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.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
str
|
Unique MultiAgent id for session management,etc. |
Source code in strands/multiagent/base.py
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 | |
__call__(task, invocation_state=None, **kwargs)
¶
Invoke synchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task
|
MultiAgentInput
|
The task to execute |
required |
invocation_state
|
dict[str, Any] | None
|
Additional state/context passed to underlying agents. Defaults to None to avoid mutable default argument issues. |
None
|
**kwargs
|
Any
|
Additional keyword arguments passed to underlying agents. |
{}
|
Source code in strands/multiagent/base.py
deserialize_state(payload)
¶
invoke_async(task, invocation_state=None, **kwargs)
abstractmethod
async
¶
Invoke asynchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task
|
MultiAgentInput
|
The task to execute |
required |
invocation_state
|
dict[str, Any] | None
|
Additional state/context passed to underlying agents. Defaults to None to avoid mutable default argument issues. |
None
|
**kwargs
|
Any
|
Additional keyword arguments passed to underlying agents. |
{}
|
Source code in strands/multiagent/base.py
serialize_state()
¶
stream_async(task, invocation_state=None, **kwargs)
async
¶
Stream events during multi-agent execution.
Default implementation executes invoke_async and yields the result as a single event. Subclasses can override this method to provide true streaming capabilities.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task
|
MultiAgentInput
|
The task to execute |
required |
invocation_state
|
dict[str, Any] | None
|
Additional state/context passed to underlying agents. Defaults to None to avoid mutable default argument issues. |
None
|
**kwargs
|
Any
|
Additional keyword arguments passed to underlying agents. |
{}
|
Yields:
| Type | Description |
|---|---|
AsyncIterator[dict[str, Any]]
|
Dictionary events containing multi-agent execution information including: |
AsyncIterator[dict[str, Any]]
|
|
AsyncIterator[dict[str, Any]]
|
|
AsyncIterator[dict[str, Any]]
|
|
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
from_dict(data)
classmethod
¶
Rehydrate a MultiAgentResult from persisted JSON.
Source code in strands/multiagent/base.py
to_dict()
¶
Convert MultiAgentResult to JSON-serializable dict.
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
from_dict(data)
classmethod
¶
Rehydrate a NodeResult from persisted JSON.
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
to_dict()
¶
Convert NodeResult to JSON-serializable dict, ignoring state field.
Source code in strands/multiagent/base.py
strands.multiagent.graph
¶
Directed Graph Multi-Agent Pattern Implementation.
This module provides a deterministic graph-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 based on dependency resolution - Output propagation along edges - Support for cyclic graphs (feedback loops) - Clear dependency management - Supports nested graphs (Graph as a node in another Graph)
Graph
¶
Bases: MultiAgentBase
Directed Graph multi-agent orchestration with configurable revisit behavior.
Source code in strands/multiagent/graph.py
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 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 | |
__call__(task, invocation_state=None, **kwargs)
¶
Invoke the graph synchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task
|
MultiAgentInput
|
The task to execute |
required |
invocation_state
|
dict[str, Any] | None
|
Additional state/context passed to underlying agents. Defaults to None to avoid mutable default argument issues. |
None
|
**kwargs
|
Any
|
Keyword arguments allowing backward compatible future changes. |
{}
|
Source code in strands/multiagent/graph.py
__init__(nodes, edges, entry_points, max_node_executions=None, execution_timeout=None, node_timeout=None, reset_on_revisit=False, session_manager=None, hooks=None, id=_DEFAULT_GRAPH_ID)
¶
Initialize Graph with execution limits and reset behavior.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nodes
|
dict[str, GraphNode]
|
Dictionary of node_id to GraphNode |
required |
edges
|
set[GraphEdge]
|
Set of GraphEdge objects |
required |
entry_points
|
set[GraphNode]
|
Set of GraphNode objects that are entry points |
required |
max_node_executions
|
Optional[int]
|
Maximum total node executions (default: None - no limit) |
None
|
execution_timeout
|
Optional[float]
|
Total execution timeout in seconds (default: None - no limit) |
None
|
node_timeout
|
Optional[float]
|
Individual node timeout in seconds (default: None - no limit) |
None
|
reset_on_revisit
|
bool
|
Whether to reset node state when revisited (default: False) |
False
|
session_manager
|
Optional[SessionManager]
|
Session manager for persisting graph state and execution history (default: None) |
None
|
hooks
|
Optional[list[HookProvider]]
|
List of hook providers for monitoring and extending graph execution behavior (default: None) |
None
|
id
|
str
|
Unique graph id (default: None) |
_DEFAULT_GRAPH_ID
|
Source code in strands/multiagent/graph.py
deserialize_state(payload)
¶
Restore graph state from a session dict and prepare for execution.
This method handles two scenarios: 1. If the graph execution ended (no next_nodes_to_execute, eg: Completed, or Failed with dead end nodes), resets all nodes and graph state to allow re-execution from the beginning. 2. If the graph execution was interrupted mid-execution (has next_nodes_to_execute), restores the persisted state and prepares to resume execution from the next ready nodes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
payload
|
dict[str, Any]
|
Dictionary containing persisted state data including status, completed nodes, results, and next nodes to execute. |
required |
Source code in strands/multiagent/graph.py
invoke_async(task, invocation_state=None, **kwargs)
async
¶
Invoke the graph asynchronously.
This method uses stream_async internally and consumes all events until completion, following the same pattern as the Agent class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task
|
MultiAgentInput
|
The task to execute |
required |
invocation_state
|
dict[str, Any] | None
|
Additional state/context passed to underlying agents. Defaults to None to avoid mutable default argument issues. |
None
|
**kwargs
|
Any
|
Keyword arguments allowing backward compatible future changes. |
{}
|
Source code in strands/multiagent/graph.py
serialize_state()
¶
Serialize the current graph state to a dictionary.
Source code in strands/multiagent/graph.py
stream_async(task, invocation_state=None, **kwargs)
async
¶
Stream events during graph execution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task
|
MultiAgentInput
|
The task to execute |
required |
invocation_state
|
dict[str, Any] | None
|
Additional state/context passed to underlying agents. Defaults to None to avoid mutable default argument issues. |
None
|
**kwargs
|
Any
|
Keyword arguments allowing backward compatible future changes. |
{}
|
Yields:
| Type | Description |
|---|---|
AsyncIterator[dict[str, Any]]
|
Dictionary events during graph execution, such as: |
AsyncIterator[dict[str, Any]]
|
|
AsyncIterator[dict[str, Any]]
|
|
AsyncIterator[dict[str, Any]]
|
|
AsyncIterator[dict[str, Any]]
|
|
Source code in strands/multiagent/graph.py
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 | |
GraphBuilder
¶
Builder pattern for constructing graphs.
Source code in strands/multiagent/graph.py
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 | |
__init__()
¶
Initialize GraphBuilder with empty collections.
Source code in strands/multiagent/graph.py
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 with configured settings.
Source code in strands/multiagent/graph.py
reset_on_revisit(enabled=True)
¶
Control whether nodes reset their state when revisited.
When enabled, nodes will reset their messages and state to initial values each time they are revisited (re-executed). This is useful for stateless behavior where nodes should start fresh on each revisit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
enabled
|
bool
|
Whether to reset node state when revisited (default: True) |
True
|
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
set_execution_timeout(timeout)
¶
Set total execution timeout.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timeout
|
float
|
Total execution timeout in seconds (None for no limit) |
required |
set_graph_id(graph_id)
¶
Set graph id.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph_id
|
str
|
Unique graph id |
required |
set_hook_providers(hooks)
¶
Set hook providers for the graph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hooks
|
list[HookProvider]
|
Customer hooks user passes in |
required |
set_max_node_executions(max_executions)
¶
Set maximum number of node executions allowed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_executions
|
int
|
Maximum total node executions (None for no limit) |
required |
Source code in strands/multiagent/graph.py
set_node_timeout(timeout)
¶
Set individual node execution timeout.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timeout
|
float
|
Individual node timeout in seconds (None for no limit) |
required |
set_session_manager(session_manager)
¶
Set session manager for the graph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_manager
|
SessionManager
|
SessionManager instance |
required |
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)
¶
__hash__()
¶
__post_init__()
¶
Capture initial executor state after initialization.
Source code in strands/multiagent/graph.py
reset_executor_state()
¶
Reset GraphNode executor state to initial state when graph was created.
This is useful when nodes are executed multiple times and need to start fresh on each execution, providing stateless behavior.
Source code in strands/multiagent/graph.py
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 |
MultiAgentInput
|
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
should_continue(max_node_executions, execution_timeout)
¶
Check if the graph should continue execution.
Returns: (should_continue, reason)
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
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 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 | |
__call__(task, invocation_state=None, **kwargs)
¶
Invoke the swarm synchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task
|
MultiAgentInput
|
The task to execute |
required |
invocation_state
|
dict[str, Any] | None
|
Additional state/context passed to underlying agents. Defaults to None to avoid mutable default argument issues. |
None
|
**kwargs
|
Any
|
Keyword arguments allowing backward compatible future changes. |
{}
|
Source code in strands/multiagent/swarm.py
__init__(nodes, *, entry_point=None, 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, session_manager=None, hooks=None, id=_DEFAULT_SWARM_ID)
¶
Initialize Swarm with agents and configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
Unique swarm id (default: None) |
required | |
nodes
|
list[Agent]
|
List of nodes (e.g. Agent) to include in the swarm |
required |
entry_point
|
Agent | None
|
Agent to start with. If None, uses the first agent (default: None) |
None
|
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
|
session_manager
|
Optional[SessionManager]
|
Session manager for persisting graph state and execution history (default: None) |
None
|
hooks
|
Optional[list[HookProvider]]
|
List of hook providers for monitoring and extending graph execution behavior (default: None) |
None
|
Source code in strands/multiagent/swarm.py
deserialize_state(payload)
¶
Restore swarm state from a session dict and prepare for execution.
This method handles two scenarios: 1. If the persisted status is COMPLETED, FAILED resets all nodes and graph state to allow re-execution from the beginning. 2. Otherwise, restores the persisted state and prepares to resume execution from the next ready nodes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
payload
|
dict[str, Any]
|
Dictionary containing persisted state data including status, completed nodes, results, and next nodes to execute. |
required |
Source code in strands/multiagent/swarm.py
invoke_async(task, invocation_state=None, **kwargs)
async
¶
Invoke the swarm asynchronously.
This method uses stream_async internally and consumes all events until completion, following the same pattern as the Agent class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task
|
MultiAgentInput
|
The task to execute |
required |
invocation_state
|
dict[str, Any] | None
|
Additional state/context passed to underlying agents. Defaults to None to avoid mutable default argument issues. |
None
|
**kwargs
|
Any
|
Keyword arguments allowing backward compatible future changes. |
{}
|
Source code in strands/multiagent/swarm.py
serialize_state()
¶
Serialize the current swarm state to a dictionary.
Source code in strands/multiagent/swarm.py
stream_async(task, invocation_state=None, **kwargs)
async
¶
Stream events during swarm execution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task
|
MultiAgentInput
|
The task to execute |
required |
invocation_state
|
dict[str, Any] | None
|
Additional state/context passed to underlying agents. Defaults to None to avoid mutable default argument issues. |
None
|
**kwargs
|
Any
|
Keyword arguments allowing backward compatible future changes. |
{}
|
Yields:
| Type | Description |
|---|---|
AsyncIterator[dict[str, Any]]
|
Dictionary events during swarm execution, such as: |
AsyncIterator[dict[str, Any]]
|
|
AsyncIterator[dict[str, Any]]
|
|
AsyncIterator[dict[str, Any]]
|
|
AsyncIterator[dict[str, Any]]
|
|
AsyncIterator[dict[str, Any]]
|
|
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 receive 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
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 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 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 | |
__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
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 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 | |
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='127.0.0.1', port=9000, http_url=None, serve_at_root=False, version='0.0.1', skills=None, task_store=None, queue_manager=None, push_config_store=None, push_sender=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 "127.0.0.1". |
'127.0.0.1'
|
port
|
int
|
The port to bind the A2A server to. Defaults to 9000. |
9000
|
http_url
|
str | None
|
The public HTTP URL where this agent will be accessible. If provided, this overrides the generated URL from host/port and enables automatic path-based mounting for load balancer scenarios. Example: "http://my-alb.amazonaws.com/agent1" |
None
|
serve_at_root
|
bool
|
If True, forces the server to serve at root path regardless of http_url path component. Use this when your load balancer strips path prefixes. Defaults to False. |
False
|
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
|
task_store
|
TaskStore | None
|
Custom task store implementation for managing agent tasks. If None, uses InMemoryTaskStore. |
None
|
queue_manager
|
QueueManager | None
|
Custom queue manager for handling message queues. If None, no queue management is used. |
None
|
push_config_store
|
PushNotificationConfigStore | None
|
Custom store for push notification configurations. If None, no push notification configuration is used. |
None
|
push_sender
|
PushNotificationSender | None
|
Custom push notification sender implementation. If None, no push notifications are sent. |
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.
Automatically handles path-based mounting if a mount path was derived from the http_url parameter.
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.
Automatically handles path-based mounting if a mount path was derived from the http_url parameter.
Returns:
| Name | Type | Description |
|---|---|---|
Starlette |
Starlette
|
A Starlette application configured to serve this agent. |