-
Notifications
You must be signed in to change notification settings - Fork 211
feat(multi-agent): introduce Graph multi-agent orchestrator #336
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
82db983
feat(multi-agent): introduce Graph orchestrator
awsarron 7edc6f2
graph - organize Status + always return NodeResult + align statuses
awsarron 04890fe
add graph.execute and graph.execute_async functions
awsarron 14ea5ac
graph - remove unnecessary __str__ magic functions
awsarron 339e170
graph - fix types
awsarron 70fab1c
feat(multiagent): PR feedback for graph.py
awsarron 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 hidden or 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 |
---|---|---|
|
@@ -8,4 +8,5 @@ __pycache__* | |
.ruff_cache | ||
*.bak | ||
.vscode | ||
dist | ||
dist | ||
repl_state |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,87 @@ | ||
"""Multi-Agent Base Class. | ||
|
||
Provides minimal foundation for multi-agent patterns (Swarm, Graph). | ||
""" | ||
|
||
from abc import ABC, abstractmethod | ||
from dataclasses import dataclass, field | ||
from enum import Enum | ||
from typing import Union | ||
|
||
from ..agent import AgentResult | ||
from ..types.event_loop import Metrics, Usage | ||
|
||
|
||
class Status(Enum): | ||
"""Execution status for both graphs and nodes.""" | ||
|
||
PENDING = "pending" | ||
awsarron marked this conversation as resolved.
Show resolved
Hide resolved
|
||
EXECUTING = "executing" | ||
COMPLETED = "completed" | ||
FAILED = "failed" | ||
|
||
|
||
@dataclass | ||
class NodeResult: | ||
"""Unified result from node execution - handles both Agent and nested MultiAgentBase results. | ||
|
||
The status field represents the semantic outcome of the node's work: | ||
- COMPLETED: The node's task was successfully accomplished | ||
- FAILED: The node's task failed or produced an error | ||
""" | ||
|
||
# Core result data - single AgentResult, nested MultiAgentResult, or Exception | ||
result: Union[AgentResult, "MultiAgentResult", Exception] | ||
|
||
# Execution metadata | ||
execution_time: int = 0 | ||
status: Status = Status.PENDING | ||
|
||
# Accumulated metrics from this node and all children | ||
accumulated_usage: Usage = field(default_factory=lambda: Usage(inputTokens=0, outputTokens=0, totalTokens=0)) | ||
accumulated_metrics: Metrics = field(default_factory=lambda: Metrics(latencyMs=0)) | ||
execution_count: int = 0 | ||
|
||
def get_agent_results(self) -> list[AgentResult]: | ||
"""Get all AgentResult objects from this node, flattened if nested.""" | ||
if isinstance(self.result, Exception): | ||
return [] # No agent results for exceptions | ||
elif isinstance(self.result, AgentResult): | ||
return [self.result] | ||
else: | ||
# Flatten nested results from MultiAgentResult | ||
flattened = [] | ||
for nested_node_result in self.result.results.values(): | ||
flattened.extend(nested_node_result.get_agent_results()) | ||
return flattened | ||
|
||
|
||
@dataclass | ||
class MultiAgentResult: | ||
"""Result from multi-agent execution with accumulated metrics.""" | ||
|
||
results: dict[str, NodeResult] | ||
accumulated_usage: Usage = field(default_factory=lambda: Usage(inputTokens=0, outputTokens=0, totalTokens=0)) | ||
accumulated_metrics: Metrics = field(default_factory=lambda: Metrics(latencyMs=0)) | ||
execution_count: int = 0 | ||
execution_time: int = 0 | ||
|
||
|
||
class MultiAgentBase(ABC): | ||
"""Base class for multi-agent helpers. | ||
|
||
This class integrates with existing Strands Agent instances and provides | ||
multi-agent orchestration capabilities. | ||
""" | ||
|
||
@abstractmethod | ||
# TODO: for task - multi-modal input (Message), list of messages | ||
awsarron marked this conversation as resolved.
Show resolved
Hide resolved
|
||
async def execute_async(self, task: str) -> MultiAgentResult: | ||
"""Execute task asynchronously.""" | ||
raise NotImplementedError("execute_async not implemented") | ||
|
||
@abstractmethod | ||
# TODO: for task - multi-modal input (Message), list of messages | ||
def execute(self, task: str) -> MultiAgentResult: | ||
"""Execute task synchronously.""" | ||
raise NotImplementedError("execute not implemented") |
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.
Uh oh!
There was an error while loading. Please reload this page.