Spawn Sub Agent • AI Agent SDK

spawn_sub_agent: Spawn a sub-agent for non-blocking execution (sync version).

spawn_sub_agent

Method

</div>

This is a method of the AgentTeam class in the agents module.

Spawn a sub-agent for non-blocking execution (sync version).

Implements the SpawnAnnounceProtocol for efficient parallel sub-agent workflows. Integrates with existing handoff infrastructure to avoid code duplication. Uses threading.Thread for background execution.

Note: For async contexts, use aspawn_sub_agent() which uses asyncio primitives. This method is safe to call from sync contexts only.

Diagram

Input Data

Agent: spawn_sub_agent

Output Result

Signature

python
def spawn_sub_agent(agent: Agent, task: Any, completion_callback: Optional[Callable[[SubAgentCompletionEvent], Any]], metadata: Optional[Dict[str, Any]]) -> SpawnedSubAgent

Parameters

ParamField Agent

No description available.

ParamField Any

No description available.

ParamField Optional

No description available.

ParamField Optional

No description available.

Returns

ResponseField SpawnedSubAgent

The result of the operation.

Uses

  • uuid.uuid4
  • EventBus
  • subscribe
  • SpawnedSubAgent
  • time.time
  • publish
  • agent.start
  • announce_completion
  • threading.Thread
  • spawn_thread.start

Source

View on GitHub

praisonaiagents/agents/agents.py at line 4469


Related Documentation