Agent Discovery
Native agent discovery provides automatic agent tracking and management within workflows. Discovery is always enabled - no setup required.Core Concept
Workflows automatically track all agents created during execution, providing immediate access to agent instances, states, and control capabilities.Discovery API
get_current_agents()
Access all agents in the current workflow:agent_id -> agent instance
get_current_agent_states()
Get the current state of all agents:agent_id -> state string
Possible States:
"idle": Agent available for work"busy": Agent processing request"waiting": Agent waiting for response"error": Agent encountered error
interrupt_current_agents()
Stop all agents in the current workflow:- Emergency shutdown
- Cost limit exceeded
- User cancellation
- Timeout handling
apply_policy_to_current_agents()
Apply cross-cutting policies to all agents:- Rate limiting
- Timeout configuration
- Retry policies
- Logging configuration
- Cost tracking
get_agents_in_node()
Get agents created within a specific node:- Track which nodes created which agents
- Clean up agents per node
- Debug agent creation flow
- Isolate agent groups
monitor_current_workflow()
Add monitoring callbacks for agent lifecycle events:agent_created: Agent instantiatedagent_called: Agent processing requestagent_completed: Request finishedagent_error: Error occurredagent_interrupted: Agent stopped
Workflow Context
Auto-Initialization
Discovery works automatically without setup:Explicit Workflow Naming
Useworkflow_context for explicit workflow names:
- Clear workflow identification
- Multiple concurrent workflows
- Better logging and debugging
- Workflow isolation
Nested Workflows
Workflows maintain their own agent contexts:Common Patterns
Multi-Agent Coordination
Agent Load Balancing
Conditional Agent Selection
Agent Health Monitoring
Progressive Agent Policies
Global Workflow Management
Access Global Manager
Cross-Workflow Operations
Performance Considerations
Discovery Overhead
- Agent registration: Less than 1ms per agent
- get_current_agents(): Less than 1ms (dictionary lookup)
- State queries: Less than 1ms
- Policy application: ~5ms per agent
Memory Impact
- Per agent: ~100 bytes of tracking data
- Per workflow: ~500 bytes of metadata
- Total: Negligible for typical workflows (less than 1MB for 1000 agents)
Thread Safety
All discovery operations are thread-safe:Best Practices
Use workflow_context for named workflows
Use workflow_context for named workflows
Check agent states before work distribution
Check agent states before work distribution
Apply policies early in workflow
Apply policies early in workflow
Use monitoring for production workflows
Use monitoring for production workflows
Clean up with interrupt on failures
Clean up with interrupt on failures

