sdk-python icon indicating copy to clipboard operation
sdk-python copied to clipboard

[FEATURE] Multi-Agent Primitives

Open arronbailiss opened this issue 1 year ago • 6 comments

Problem Statement

Strands builders are increasingly asking for enhanced multi-agent capabilities that go beyond our current tool-based approach. Based on community feedback and customer requests, developers want:

  • First-Class Multi-Agent Patterns: Builders want native SDK support for common coordination patterns like hierarchical delegation, autonomous collaboration, and deterministic workflows
  • Seamless Agent Composition: The community is asking for the ability to easily combine different coordination styles - mixing autonomous swarms with deterministic graphs, nesting patterns within each other
  • Simplified Multi-Agent APIs: Developers want intuitive interfaces that make complex multi-agent systems as easy to build as single-agent applications
  • Better State Management: Requests for built-in persistence and state resumption capabilities that work seamlessly across multi-agent scenarios
  • Native Agent Orchestration: Builders want direct control over agent lifecycle, tool injection, and coordination without the overhead of tool-level abstractions

Proposed Solution

In response to builder requests, we propose introducing four core multi-agent orchestration primitives as top-level SDK concepts that address the complete spectrum of coordination patterns developers are asking for.

1. Agents-as-Tools

Specialized agents provided as tools to supervisor agents, enabling the hierarchical delegation patterns.

from strands import Agent

# Create specialized agents
research_assistant = Agent(
    name="research_assistant", 
    description="Use this agent to perform deep research on any topic.",
    system_prompt="You are a specialized research assistant with access to web search and analysis tools.",
    tools=[web_search, http_request, current_time, memory]
)

product_assistant = Agent(
    name="product_assistant",
    description="Use this agent for product recommendations and comparisons.", 
    system_prompt="You are a product specialist who helps with recommendations.",
    tools=[product_search, price_compare, review_analyzer]
)

travel_assistant = Agent(
    name="travel_assistant",
    description="Use this agent for travel planning and bookings.",
    system_prompt="You are a travel planning specialist.",
    tools=[flight_search, hotel_search, weather_check]
)

# Orchestrator agent coordinates specialists
orchestrator = Agent(
    name="travel_coordinator",
    tools=[research_assistant, product_assistant, travel_assistant]
)

# Natural delegation through tool calls
result = orchestrator("I need to plan a business trip to Amsterdam on August 10. Research the city, find good hotels, and book flights.")

2. Handoffs

Structured agent-to-agent and agent-to-user communication through injected coordination tools that enable the explicit control transfer.

from strands import Agent
from strands.multiagent import handoff_to_agent, get_swarm_context, handoff_to_user

# Agents automatically receive coordination tools
sales_agent = Agent(
    name="sales",
    system_prompt="Handle initial customer inquiries and qualify leads.",
    tools=[crm_lookup, handoff_to_agent, handoff_to_user]
)

technical_agent = Agent(
    name="technical", 
    system_prompt="Provide technical support and troubleshooting.",
    tools=[knowledge_base, system_check, handoff_to_agent, handoff_to_user]
)

# Agents can hand off with context preservation
# Sales agent handling inquiry:
handoff_to_agent(
    target_agent="technical",
    message="Customer needs help with API integration error",
    context={
        "customer_id": "12345",
        "issue_type": "integration",
        "priority": "high"
    }
)

3. Swarms

Self-organizing collaborative agent teams with shared working memory.

from strands import Agent
from strands.multiagent import Swarm

# Create agents with different specializations
researcher = Agent(
    name="researcher",
    system_prompt="You research topics thoroughly using web search.",
    tools=[web_search, memory]
)

analyst = Agent(
    name="analyst", 
    system_prompt="You analyze data and create insights.",
    tools=[calculator, data_processor, memory]
)

writer = Agent(
    name="writer",
    system_prompt="You write comprehensive reports based on research and analysis.",
    tools=[file_write, document_formatter, memory]
)

# Swarm automatically injects coordination tools
market_research_team = Swarm(
    agents=[researcher, analyst, writer],
)

# Agents coordinate autonomously to complete the task
results = market_research_team.execute(
    "Analyze the current AI agent market trends and create a comprehensive report"
)

# Check coordination summary
summary = market_research_team.get_swarm_summary()
print(f"Agents used: {' → '.join(summary['swarm_history'])}")
print(f"Status: {summary['status']}")

4. Graphs

Deterministic workflow orchestration with conditional execution paths for structured control over multi-agent orchestration.

from strands import Agent
from strands.multiagent import GraphBuilder

# Create specialized agents
analyzer_agent = Agent(
    name="analyzer",
    system_prompt="Analyze customer requests and categorize them.",
    tools=[text_classifier, sentiment_analyzer]
)

ai_processor = Agent(
    name="ai_processor", 
    system_prompt="Handle routine requests automatically.",
    tools=[knowledge_base, auto_responder]
)

def get_human_input(request):
    """Function for human escalation"""
    return {"requires_human": True, "escalated_request": request}

def is_approved(analysis_result):
    """Condition function for routing"""
    return analysis_result.get("confidence", 0) > 0.8

def is_critical(analysis_result):
    """Condition function for critical cases"""
    return "urgent" in analysis_result.get("categories", [])

# Build deterministic workflow
builder = GraphBuilder()
builder.add_node(analyzer_agent, "analyze")
builder.add_node(ai_processor, "ai_processor")
builder.add_node(get_human_input, "manual_processor")

# Define conditional edges
builder.add_edge("analyze", "ai_processor", condition=is_approved)
builder.add_edge("analyze", "manual_processor", condition=is_critical)
builder.set_entry_point("analyze")

customer_support_graph = builder.build()

# Execute with deterministic routing
results = customer_support_graph.execute(
    "Please refund my order #12345, it was damaged during shipping"
)

Advanced Composability

The primitives naturally compose to handle complex scenarios builders envision:

# Swarm of graphs - each research area has its own workflow
research_workflows = [
    create_market_analysis_graph(),  # type is strands.multiagent.Graph
    create_competitor_analysis_graph(), 
    create_trend_analysis_graph()
]

analysis_swarm = Swarm(
    research_workflows,  # Graphs as swarm members
)

# Graph with swarm nodes - structured workflow with collaborative stages
content_pipeline = GraphBuilder()
content_pipeline.add_node(research_swarm, "research_phase")  # research_swarm type is strands.multiagent.Swarm
content_pipeline.add_node(writing_swarm, "writing_phase") 
content_pipeline.add_node(review_agent, "final_review")
content_pipeline.add_edge("research_phase", "writing_phase")
content_pipeline.add_edge("writing_phase", "final_review")
content_pipeline.set_entry_point("research_phase")
content_graph = content_pipeline.build()

# Agents-as-tools within swarms - specialists available to team members
code_writer = Agent(
    name="code_writer",
    system_prompt="Write code, test it, debug, iterate until it works! Work in coordination with the code_reviewer to get feedback on your code and implement the feedback until they are satisfied.",
    tools=[file_read, file_write, editor, shell, journal]
)
code_reviewer_python = Agent(
    name="code_reviewer_python",
    system_prompt="Review the code thoroughly and offer suggestions for improvements if there are any. Iterate with the code_writer until you are satisfied with the code that they have written.",
    tools=[file_read, python_repl]
)
code_reviewer = Agent(
    name="code_reviewer",
    system_prompt="Analyze and review the Python code thoroughly.",
    tools=[code_reviewer_python, memory]  # code_reviewer_python included as an Agent-as-a-Tool
)
specialist_swarm = Swarm(
    agents=[code_writer, code_reviewer],  # code_reviewer_python is not included directly in the Swarm, instead it is called by the code_reviewer agent
)

Use Case

Agents-as-Tools: Consultation Model

• Specialist Consultation: Main agent consults domain experts without giving up control • Hierarchical Decision Making: Senior agent delegates specific analysis to junior specialists • Expert Advisory: Orchestrator maintains oversight while leveraging specialized knowledge • Tool-like Interaction: Agents used as sophisticated, intelligent tools with natural language interfaces

Handoffs: Delegation Model

• Sequential Processing: Work passes from one agent to another in a chain • Context Preservation: Full state transfer between agents with conversation history • Human-in-the-Loop: Agents can escalate to humans at decision points • Responsibility Transfer: Clear handoff of ownership and accountability

Swarms: Self-Organizing Teams

• Autonomous Collaboration: Agents coordinate themselves without central control • Dynamic Task Distribution: Work allocation emerges from agent capabilities and availability • Collective Intelligence: Shared working memory enables emergent problem-solving • Adaptive Coordination: Team structure adapts to task requirements in real-time

Graphs: Deterministic Orchestration

• Conditional Branching: Different execution paths based on runtime conditions • Workflow Control: Explicit definition of agent interaction sequences • Quality Gates: Validation checkpoints that control flow progression • Parallel Processing: Multiple agents working simultaneously on independent tasks • Error Handling: Predefined fallback paths and recovery mechanisms

Composable Patterns

• Nested Coordination: Swarms within graphs, graphs as swarm members • Multi-Modal Teams: Combining autonomous and deterministic coordination • Scalable Hierarchies: Complex organizational structures with multiple coordination layers • Pattern Mixing: Different coordination styles for different phases of work

Additional Context

  • Optional name and description parameters will be added to the Agent class.
  • The existing swarm and agent_graph tools interfaces will be enhanced and use the underlying SDK multi-agent primitives. This means that your agents can autonomously create and execute their own swarms and graphs using a model-driven approach.

Please share your feedback and use cases to help shape multi-agent primitives in Strands Agents.

arronbailiss avatar Jun 13 '25 00:06 arronbailiss

For "Agents as Tools", assuming the Tools will be local to the orchestrator/supervisor, I will expect the model configuration to be shared between parent and child agent.

In its current implementation, any built-it in tool seems to ignore the model config and defaults to a model/region that I may not have access to: https://github.com/strands-agents/tools/issues/20#issuecomment-2988925602

coatsnmore avatar Jun 24 '25 14:06 coatsnmore

Hello is the Human-in-the-loop feature available? We have our agent behind a FastAPI server that would need to stop before executing the tool and go back to the user. Then receive a new request with confirmation and resume execution. Thanks!

iker592 avatar Jul 10 '25 11:07 iker592

The Graph and Swarm primitives were just released in strands-agents 1.0.0 (https://pypi.org/project/strands-agents/1.0.0/), along with an example handoff_to_user tool in strands-agents-tools 0.2.0 (https://pypi.org/project/strands-agents-tools/0.2.0/).

See the launch announcement for details: https://aws.amazon.com/blogs/opensource/introducing-strands-agents-1-0-production-ready-multi-agent-orchestration-made-simple/.

Please take them for a spin and share your feedback!

arronbailiss avatar Jul 16 '25 09:07 arronbailiss

Hello @awsarron I've been checking out Strands 1.0.0, very cool features! For human in the loop, is still a CLI use-case. Would be great to have the ability to stop before executing a tool when agents are behind an API. (ie langgraph solution)

Image

iker592 avatar Jul 17 '25 10:07 iker592

@iker592 thank you for the feedback and for raising this. Please continue following along with enhancements to human-in-the-loop and return of control in these issues:

https://github.com/strands-agents/sdk-python/issues/204 https://github.com/strands-agents/sdk-python/discussions/666

arronbailiss avatar Aug 29 '25 14:08 arronbailiss

Marking this issue as closed. Further enhancements to multi-agent primitives will continue in separate more focused GitHub issues.

arronbailiss avatar Aug 29 '25 14:08 arronbailiss