Quick Start
How It Works
The spawn-announce pattern uses an event-driven architecture to coordinate between parent and sub-agents.| Component | Role |
|---|---|
| Parent Agent | Spawns sub-agents, continues work non-blocking |
| Sub-Agent | Executes task, announces completion when done |
| AgentTeam | Orchestrates spawning and event coordination |
| EventBus | Delivers completion events to callbacks |
Choosing Your Pattern
Different use cases require different coordination patterns.Common Patterns
Fire-and-Forget with Callback
Best for immediate processing of sub-agent results.Parallel Fan-out with Join
Scale work across multiple sub-agents, then combine results.Event-Driven Coordination
React to sub-agent events without callbacks.Configuration
spawn_sub_agent Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
agent | Agent | required | The agent that will execute the task. |
task | Task or str | required | Task to run. If it has .description, that string is sent to agent.start(). |
completion_callback | Callable[[SubAgentCompletionEvent], Any] | None | Called once the sub-agent finishes. |
metadata | Dict[str, Any] | None | Free-form metadata stored on the SpawnedSubAgent. |
announce_completion Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
agent_id | str | required | ID returned by spawn_sub_agent. |
task_id | str | required | Task ID from SpawnedSubAgent.task_id. |
result | Any | required | The sub-agent’s output. |
success | bool | True | Whether the task succeeded. |
error | Optional[str] | None | Error message if success=False. |
metadata | Dict[str, Any] | None | Free-form metadata on the completion event. |
wait_for_completions Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
timeout | Optional[float] | None | Max seconds to wait. None = wait forever (not recommended). |
agent_ids | Optional[List[str]] | None | Specific IDs to wait for. None = wait for all currently spawned. |
Async Usage
For async code, use the async variants with proper event-driven waiting.Best Practices
Always Set Timeouts
Always Set Timeouts
Prevent indefinite waiting by setting reasonable timeout values.
Use Async Variants for Async Code
Use Async Variants for Async Code
Inside
async def functions, use aspawn_sub_agent and await_for_completions.Keep Callbacks Fast
Keep Callbacks Fast
Completion callbacks should be lightweight to avoid blocking the event loop.
Use Metadata for Correlation
Use Metadata for Correlation
Attach metadata to track spawned sub-agents back to your domain context.
Related
AgentTeam
Core multi-agent coordination
Event Bus
Event-driven architecture

