-
-
Notifications
You must be signed in to change notification settings - Fork 504
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
Occupying-Mars
wants to merge
1
commit into
kyegomez:master
Choose a base branch
from
Occupying-Mars:harshal_fixes
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
from typing import List, Dict, Any, Optional | ||
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.
|
||
"""Schema for individual agent execution steps""" | ||
role: str = Field(description="Role of the agent in this step") | ||
content: str = Field(description="Content/response from the agent") | ||
|
||
class AgentOutput(BaseModel): | ||
"""Schema for individual agent outputs""" | ||
agent_name: str = Field(description="Name of the agent") | ||
steps: List[AgentStep] = Field(description="List of execution steps by this agent") | ||
metadata: Optional[Dict[str, Any]] = Field(default=None, description="Additional metadata about the agent's execution") | ||
|
||
class SwarmInput(BaseModel): | ||
"""Schema for swarm input configuration""" | ||
swarm_id: str = Field(description="Unique identifier for the swarm execution") | ||
name: str = Field(description="Name of the swarm type") | ||
flow: str = Field(description="Agent execution flow configuration") | ||
description: Optional[str] = Field(default=None, description="Description of the swarm execution") | ||
|
||
class SwarmOutput(BaseModel): | ||
"""Unified schema for all swarm type outputs""" | ||
input: SwarmInput = Field(description="Input configuration for the swarm") | ||
outputs: List[AgentOutput] = Field(description="List of outputs from all agents") | ||
time: float = Field(description="Timestamp of execution") | ||
execution_time: Optional[float] = Field(default=None, description="Total execution time in seconds") | ||
metadata: Optional[Dict[str, Any]] = Field(default=None, description="Additional swarm execution metadata") | ||
|
||
def format_output(self) -> str: | ||
"""Format the swarm output into a readable string""" | ||
output = f"Workflow Execution Details\n\n" | ||
output += f"Swarm ID: `{self.input.swarm_id}`\n" | ||
output += f"Swarm Name: `{self.input.name}`\n" | ||
output += f"Agent Flow: `{self.input.flow}`\n\n---\n" | ||
output += f"Agent Task Execution\n\n" | ||
|
||
for i, agent_output in enumerate(self.outputs, start=1): | ||
output += f"Run {i} (Agent: `{agent_output.agent_name}`)\n\n" | ||
|
||
for j, step in enumerate(agent_output.steps, start=1): | ||
if step.role.strip() != "System:": | ||
output += f"Step {j}:\n" | ||
output += f"Response: {step.content}\n\n" | ||
|
||
if self.execution_time: | ||
output += f"Overall Execution Time: `{self.execution_time:.2f}s`" | ||
|
||
return output | ||
|
||
class MixtureOfAgentsOutput(SwarmOutput): | ||
"""Schema specific to MixtureOfAgents output""" | ||
aggregator_summary: Optional[str] = Field(default=None, description="Aggregated summary from all agents") | ||
|
||
def format_output(self) -> str: | ||
"""Format MixtureOfAgents output""" | ||
output = super().format_output() | ||
if self.aggregator_summary: | ||
output += f"\nAggregated Summary:\n{self.aggregator_summary}\n{'=' * 50}\n" | ||
return output | ||
|
||
class SpreadsheetSwarmOutput(SwarmOutput): | ||
"""Schema specific to SpreadsheetSwarm output""" | ||
csv_data: List[List[str]] = Field(description="CSV data in list format") | ||
|
||
def format_output(self) -> str: | ||
"""Format SpreadsheetSwarm output""" | ||
output = "### Spreadsheet Swarm Output ###\n\n" | ||
if self.csv_data: | ||
# Create markdown table | ||
header = self.csv_data[0] | ||
output += "| " + " | ".join(header) + " |\n" | ||
output += "| " + " | ".join(["---"] * len(header)) + " |\n" | ||
|
||
for row in self.csv_data[1:]: | ||
output += "| " + " | ".join(row) + " |\n" | ||
|
||
return output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check failure
Code scanning / Pyre
Undefined import Error