strands.multiagent
¶
Multiagent capabilities for Strands Agents.
This module provides support for multiagent systems, including agent-to-agent (A2A) communication protocols and coordination mechanisms.
Submodules
strands.multiagent.base
¶
Multi-Agent Base Class.
Provides minimal foundation for multi-agent patterns (Swarm, Graph).
MultiAgentBase
¶
Bases: ABC
Base class for multi-agent helpers.
This class integrates with existing Strands Agent instances and provides multi-agent orchestration capabilities.
Source code in strands/multiagent/base.py
MultiAgentResult
dataclass
¶
Result from multi-agent execution with accumulated metrics.
The status field represents the outcome of the MultiAgentBase execution: - COMPLETED: The execution was successfully accomplished - FAILED: The execution failed or produced an error
Source code in strands/multiagent/base.py
NodeResult
dataclass
¶
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
Source code in strands/multiagent/base.py
get_agent_results()
¶
Get all AgentResult objects from this node, flattened if nested.
Source code in strands/multiagent/base.py
strands.multiagent.graph
¶
Directed Acyclic Graph (DAG) Multi-Agent Pattern Implementation.
This module provides a deterministic DAG-based agent orchestration system where agents or MultiAgentBase instances (like Swarm or Graph) are nodes in a graph, executed according to edge dependencies, with output from one node passed as input to connected nodes.
Key Features: - Agents and MultiAgentBase instances (Swarm, Graph, etc.) as graph nodes - Deterministic execution order based on DAG structure - Output propagation along edges - Topological sort for execution ordering - Clear dependency management - Supports nested graphs (Graph as a node in another Graph)
Graph
¶
Bases: MultiAgentBase
Directed Acyclic Graph multi-agent orchestration.
Source code in strands/multiagent/graph.py
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 |
|
__call__(task, **kwargs)
¶
Invoke the graph synchronously.
Source code in strands/multiagent/graph.py
__init__(nodes, edges, entry_points)
¶
Initialize Graph.
Source code in strands/multiagent/graph.py
invoke_async(task, **kwargs)
async
¶
Invoke the graph asynchronously.
Source code in strands/multiagent/graph.py
GraphBuilder
¶
Builder pattern for constructing graphs.
Source code in strands/multiagent/graph.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 |
|
__init__()
¶
Initialize GraphBuilder with empty collections.
add_edge(from_node, to_node, condition=None)
¶
Add an edge between two nodes with optional condition function that receives full GraphState.
Source code in strands/multiagent/graph.py
add_node(executor, node_id=None)
¶
Add an Agent or MultiAgentBase instance as a node to the graph.
Source code in strands/multiagent/graph.py
build()
¶
Build and validate the graph.
Source code in strands/multiagent/graph.py
set_entry_point(node_id)
¶
Set a node as an entry point for graph execution.
Source code in strands/multiagent/graph.py
GraphEdge
dataclass
¶
Represents an edge in the graph with an optional condition.
Source code in strands/multiagent/graph.py
GraphNode
dataclass
¶
Represents a node in the graph.
The execution_status tracks the node's lifecycle within graph orchestration: - PENDING: Node hasn't started executing yet - EXECUTING: Node is currently running - COMPLETED/FAILED: Node finished executing (regardless of result quality)
Source code in strands/multiagent/graph.py
__eq__(other)
¶
GraphResult
dataclass
¶
Bases: MultiAgentResult
Result from graph execution - extends MultiAgentResult with graph-specific details.
Source code in strands/multiagent/graph.py
GraphState
dataclass
¶
Graph execution state.
Attributes:
Name | Type | Description |
---|---|---|
status |
Status
|
Current execution status of the graph. |
completed_nodes |
set[GraphNode]
|
Set of nodes that have completed execution. |
failed_nodes |
set[GraphNode]
|
Set of nodes that failed during execution. |
execution_order |
list[GraphNode]
|
List of nodes in the order they were executed. |
task |
str | list[ContentBlock]
|
The original input prompt/query provided to the graph execution. This represents the actual work to be performed by the graph as a whole. Entry point nodes receive this task as their input if they have no dependencies. |
Source code in strands/multiagent/graph.py
strands.multiagent.swarm
¶
Swarm Multi-Agent Pattern Implementation.
This module provides a collaborative agent orchestration system where agents work together as a team to solve complex tasks, with shared context and autonomous coordination.
Key Features: - Self-organizing agent teams with shared working memory - Tool-based coordination - Autonomous agent collaboration without central control - Dynamic task distribution based on agent capabilities - Collective intelligence through shared context
SharedContext
dataclass
¶
Shared context between swarm nodes.
Source code in strands/multiagent/swarm.py
add_context(node, key, value)
¶
Add context.
Source code in strands/multiagent/swarm.py
Swarm
¶
Bases: MultiAgentBase
Self-organizing collaborative agent teams with shared working memory.
Source code in strands/multiagent/swarm.py
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 |
|
__call__(task, **kwargs)
¶
Invoke the swarm synchronously.
Source code in strands/multiagent/swarm.py
__init__(nodes, *, max_handoffs=20, max_iterations=20, execution_timeout=900.0, node_timeout=300.0, repetitive_handoff_detection_window=0, repetitive_handoff_min_unique_agents=0)
¶
Initialize Swarm with agents and configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
nodes
|
list[Agent]
|
List of nodes (e.g. Agent) to include in the swarm |
required |
max_handoffs
|
int
|
Maximum handoffs to agents and users (default: 20) |
20
|
max_iterations
|
int
|
Maximum node executions within the swarm (default: 20) |
20
|
execution_timeout
|
float
|
Total execution timeout in seconds (default: 900.0) |
900.0
|
node_timeout
|
float
|
Individual node timeout in seconds (default: 300.0) |
300.0
|
repetitive_handoff_detection_window
|
int
|
Number of recent nodes to check for repetitive handoffs Disabled by default (default: 0) |
0
|
repetitive_handoff_min_unique_agents
|
int
|
Minimum unique agents required in recent sequence Disabled by default (default: 0) |
0
|
Source code in strands/multiagent/swarm.py
invoke_async(task, **kwargs)
async
¶
Invoke the swarm asynchronously.
Source code in strands/multiagent/swarm.py
SwarmNode
dataclass
¶
Represents a node (e.g. Agent) in the swarm.
Source code in strands/multiagent/swarm.py
SwarmResult
dataclass
¶
Bases: MultiAgentResult
Result from swarm execution - extends MultiAgentResult with swarm-specific details.
Source code in strands/multiagent/swarm.py
SwarmState
dataclass
¶
Current state of swarm execution.
Source code in strands/multiagent/swarm.py
should_continue(*, max_handoffs, max_iterations, execution_timeout, repetitive_handoff_detection_window, repetitive_handoff_min_unique_agents)
¶
Check if the swarm should continue.
Returns: (should_continue, reason)
Source code in strands/multiagent/swarm.py
strands.multiagent.a2a
¶
Agent-to-Agent (A2A) communication protocol implementation for Strands Agents.
This module provides classes and utilities for enabling Strands Agents to communicate with other agents using the Agent-to-Agent (A2A) protocol.
Docs: https://google-a2a.github.io/A2A/latest/
Classes:
Name | Description |
---|---|
A2AAgent |
A wrapper that adapts a Strands Agent to be A2A-compatible. |
strands.multiagent.a2a.executor
¶
Strands Agent executor for the A2A protocol.
This module provides the StrandsA2AExecutor class, which adapts a Strands Agent to be used as an executor in the A2A protocol. It handles the execution of agent requests and the conversion of Strands Agent streamed responses to A2A events.
The A2A AgentExecutor ensures clients recieve responses for synchronous and streamed requests to the A2AServer.
StrandsA2AExecutor
¶
Bases: AgentExecutor
Executor that adapts a Strands Agent to the A2A protocol.
This executor uses streaming mode to handle the execution of agent requests and converts Strands Agent responses to A2A protocol events.
Source code in strands/multiagent/a2a/executor.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
|
__init__(agent)
¶
Initialize a StrandsA2AExecutor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
agent
|
Agent
|
The Strands Agent instance to adapt to the A2A protocol. |
required |
cancel(context, event_queue)
async
¶
Cancel an ongoing execution.
This method is called when a request cancellation is requested. Currently, cancellation is not supported by the Strands Agent executor, so this method always raises an UnsupportedOperationError.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
context
|
RequestContext
|
The A2A request context. |
required |
event_queue
|
EventQueue
|
The A2A event queue. |
required |
Raises:
Type | Description |
---|---|
ServerError
|
Always raised with an UnsupportedOperationError, as cancellation is not currently supported. |
Source code in strands/multiagent/a2a/executor.py
execute(context, event_queue)
async
¶
Execute a request using the Strands Agent and send the response as A2A events.
This method executes the user's input using the Strands Agent in streaming mode and converts the agent's response to A2A events.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
context
|
RequestContext
|
The A2A request context, containing the user's input and task metadata. |
required |
event_queue
|
EventQueue
|
The A2A event queue used to send response events back to the client. |
required |
Raises:
Type | Description |
---|---|
ServerError
|
If an error occurs during agent execution |
Source code in strands/multiagent/a2a/executor.py
strands.multiagent.a2a.server
¶
A2A-compatible wrapper for Strands Agent.
This module provides the A2AAgent class, which adapts a Strands Agent to the A2A protocol, allowing it to be used in A2A-compatible systems.
A2AServer
¶
A2A-compatible wrapper for Strands Agent.
Source code in strands/multiagent/a2a/server.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
|
agent_skills
property
writable
¶
Get the list of skills this agent provides.
public_agent_card
property
¶
Get the public AgentCard for this agent.
The AgentCard contains metadata about the agent, including its name, description, URL, version, skills, and capabilities. This information is used by other agents and systems to discover and interact with this agent.
Returns:
Name | Type | Description |
---|---|---|
AgentCard |
AgentCard
|
The public agent card containing metadata about this agent. |
Raises:
Type | Description |
---|---|
ValueError
|
If name or description is None or empty. |
__init__(agent, *, host='0.0.0.0', port=9000, version='0.0.1', skills=None)
¶
Initialize an A2A-compatible server from a Strands agent.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
agent
|
Agent
|
The Strands Agent to wrap with A2A compatibility. |
required |
host
|
str
|
The hostname or IP address to bind the A2A server to. Defaults to "0.0.0.0". |
'0.0.0.0'
|
port
|
int
|
The port to bind the A2A server to. Defaults to 9000. |
9000
|
version
|
str
|
The version of the agent. Defaults to "0.0.1". |
'0.0.1'
|
skills
|
list[AgentSkill] | None
|
The list of capabilities or functions the agent can perform. |
None
|
Source code in strands/multiagent/a2a/server.py
serve(app_type='starlette', *, host=None, port=None, **kwargs)
¶
Start the A2A server with the specified application type.
This method starts an HTTP server that exposes the agent via the A2A protocol. The server can be implemented using either FastAPI or Starlette, depending on the specified app_type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
app_type
|
Literal['fastapi', 'starlette']
|
The type of application to serve, either "fastapi" or "starlette". Defaults to "starlette". |
'starlette'
|
host
|
str | None
|
The host address to bind the server to. Defaults to "0.0.0.0". |
None
|
port
|
int | None
|
The port number to bind the server to. Defaults to 9000. |
None
|
**kwargs
|
Any
|
Additional keyword arguments to pass to uvicorn.run. |
{}
|
Source code in strands/multiagent/a2a/server.py
to_fastapi_app()
¶
Create a FastAPI application for serving this agent via HTTP.
This method creates a FastAPI application that can be used to serve the agent via HTTP using the A2A protocol.
Returns:
Name | Type | Description |
---|---|---|
FastAPI |
FastAPI
|
A FastAPI application configured to serve this agent. |
Source code in strands/multiagent/a2a/server.py
to_starlette_app()
¶
Create a Starlette application for serving this agent via HTTP.
This method creates a Starlette application that can be used to serve the agent via HTTP using the A2A protocol.
Returns:
Name | Type | Description |
---|---|---|
Starlette |
Starlette
|
A Starlette application configured to serve this agent. |