Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add swarm output schemas and agent fixes #742

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Occupying-Mars
Copy link
Collaborator

@Occupying-Mars Occupying-Mars commented Jan 10, 2025

Unified Swarm Output Schema

for harshals ui

Changes Made

  1. Created a new unified schema system in swarms/schemas/swarm_output_schemas.py that standardizes output across all swarm types:

    • Base SwarmOutput schema for common fields
    • Specialized schemas for each swarm type (MixtureOfAgents, SpreadsheetSwarm, AgentRearrange, etc.)
    • Each schema includes type-safe Pydantic models with proper field validation
  2. Added specialized output classes for different swarm types:

    • AgentRearrangeOutput: For agent rearrangement workflows
    • ConcurrentWorkflowOutput: For parallel execution stats
    • SequentialWorkflowOutput: For workflow chain tracking
    • AutoSwarmOutput: For auto-selected strategy details
    • MixtureOfAgentsOutput: For aggregated agent summaries
    • SpreadsheetSwarmOutput: For CSV data handling
  3. Enhanced the Agent class with a unified create_swarm_output method that:

    • Creates standardized output for all swarm types
    • Handles metadata appropriately for each type
    • Provides consistent formatting

Benefits

  • Consistent output structure across all swarm types
  • Type safety through Pydantic models
  • Simplified UI parsing with built-in formatting methods
  • Easier maintenance and extensibility
  • Reduced code duplication
  • Better error handling and validation

Breaking Changes

None. This is a new feature that enhances existing functionality without breaking existing implementations.


📚 Documentation preview 📚: https://swarms--742.org.readthedocs.build/en/742/

@@ -0,0 +1,79 @@
from typing import List, Dict, Any, Optional
from pydantic import BaseModel, Field

Check failure

Code scanning / Pyre

Undefined import Error

Undefined import [21]: Could not find a module corresponding to import pydantic.
from pydantic import BaseModel, Field
from datetime import datetime

class AgentStep(BaseModel):

Check failure

Code scanning / Pyre

Undefined or invalid type Error

Undefined or invalid type [11]: Annotation BaseModel is not defined as a type.
Comment on lines +2621 to +2625
input_config = SwarmInput(
swarm_id=swarm_id,
name=swarm_type,
flow=flow or "->".join([out["agent_name"] for out in agent_outputs]),
)

Check failure

Code scanning / Pyre

Unexpected keyword Error

Unexpected keyword [28]: Unexpected keyword argument swarm\_id to call object.\_\_init\_\_.
formatted_outputs = []
for agent_out in agent_outputs:
steps = [
AgentStep(role=step["role"], content=step["content"])

Check failure

Code scanning / Pyre

Unexpected keyword Error

Unexpected keyword [28]: Unexpected keyword argument role to call object.\_\_init\_\_.
Comment on lines +2635 to +2639
AgentOutput(
agent_name=agent_out["agent_name"],
steps=steps,
metadata=agent_out.get("metadata")
)

Check failure

Code scanning / Pyre

Unexpected keyword Error

Unexpected keyword [28]: Unexpected keyword argument agent\_name to call object.\_\_init\_\_.
Comment on lines +2644 to +2651
return MixtureOfAgentsOutput(
input=input_config,
outputs=formatted_outputs,
time=time.time(),
execution_time=execution_time,
metadata=metadata,
aggregator_summary=metadata.get("aggregator_summary") if metadata else None
)

Check failure

Code scanning / Pyre

Unexpected keyword Error

Unexpected keyword [28]: Unexpected keyword argument input to call object.\_\_init\_\_.
Comment on lines +2653 to +2660
return SpreadsheetSwarmOutput(
input=input_config,
outputs=formatted_outputs,
time=time.time(),
execution_time=execution_time,
metadata=metadata,
csv_data=metadata.get("csv_data", []) if metadata else []
)

Check failure

Code scanning / Pyre

Unexpected keyword Error

Unexpected keyword [28]: Unexpected keyword argument input to call object.\_\_init\_\_.
Comment on lines +2662 to +2668
return SwarmOutput(
input=input_config,
outputs=formatted_outputs,
time=time.time(),
execution_time=execution_time,
metadata=metadata
)

Check failure

Code scanning / Pyre

Unexpected keyword Error

Unexpected keyword [28]: Unexpected keyword argument input to call object.\_\_init\_\_.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant