-
Notifications
You must be signed in to change notification settings - Fork 425
feat(multiagent): Add stream_async #961
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
base: main
Are you sure you want to change the base?
Changes from all commits
6c00bbe
b09b539
08141a0
d4f5571
fc0a272
ca59221
60f16b9
a307f37
24502fc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -351,3 +351,74 @@ def __init__(self, reason: str | Exception) -> None: | |
class AgentResultEvent(TypedEvent): | ||
def __init__(self, result: "AgentResult"): | ||
super().__init__({"result": result}) | ||
|
||
|
||
class MultiAgentResultEvent(TypedEvent): | ||
"""Event emitted when multi-agent execution completes with final result.""" | ||
|
||
def __init__(self, result: Any) -> None: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this |
||
"""Initialize with multi-agent result. | ||
|
||
Args: | ||
result: The final result from multi-agent execution (SwarmResult, GraphResult, etc.) | ||
""" | ||
super().__init__({"result": result}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How does the caller differentiate between an AgentResult (using the key |
||
|
||
|
||
class MultiAgentNodeStartEvent(TypedEvent): | ||
"""Event emitted when a node begins execution in multi-agent context.""" | ||
|
||
def __init__(self, node_id: str, node_type: str) -> None: | ||
"""Initialize with node information. | ||
|
||
Args: | ||
node_id: Unique identifier for the node | ||
node_type: Type of node ("agent", "swarm", "graph") | ||
""" | ||
super().__init__({"multi_agent_node_start": True, "node_id": node_id, "node_type": node_type}) | ||
|
||
|
||
class MultiAgentNodeCompleteEvent(TypedEvent): | ||
"""Event emitted when a node completes execution.""" | ||
|
||
def __init__(self, node_id: str, execution_time: int) -> None: | ||
"""Initialize with completion information. | ||
|
||
Args: | ||
node_id: Unique identifier for the node | ||
execution_time: Execution time in milliseconds | ||
""" | ||
super().__init__({"multi_agent_node_complete": True, "node_id": node_id, "execution_time": execution_time}) | ||
|
||
|
||
class MultiAgentHandoffEvent(TypedEvent): | ||
"""Event emitted during agent handoffs in Swarm.""" | ||
|
||
def __init__(self, from_node: str, to_node: str, message: str) -> None: | ||
"""Initialize with handoff information. | ||
|
||
Args: | ||
from_node: Node ID handing off control | ||
to_node: Node ID receiving control | ||
message: Handoff message explaining the transfer | ||
""" | ||
super().__init__({"multi_agent_handoff": True, "from_node": from_node, "to_node": to_node, "message": message}) | ||
|
||
|
||
class MultiAgentNodeStreamEvent(TypedEvent): | ||
"""Event emitted during node execution - forwards agent events with node context.""" | ||
|
||
def __init__(self, node_id: str, agent_event: dict[str, Any]) -> None: | ||
"""Initialize with node context and agent event. | ||
|
||
Args: | ||
node_id: Unique identifier for the node generating the event | ||
agent_event: The original agent event data | ||
""" | ||
super().__init__( | ||
{ | ||
"multi_agent_node_stream": True, | ||
"node_id": node_id, | ||
**agent_event, # Forward all original agent event data | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's nest this instead of combining. Specifically |
||
} | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there ever a case where this is not an dict?