Skip to main content

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:
Returns: Dictionary of agent_id -> agent instance

get_current_agent_states()

Get the current state of all agents:
Returns: Dictionary of 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:
Use Cases:
  • Emergency shutdown
  • Cost limit exceeded
  • User cancellation
  • Timeout handling

apply_policy_to_current_agents()

Apply cross-cutting policies to all agents:
Common Policies:
  • Rate limiting
  • Timeout configuration
  • Retry policies
  • Logging configuration
  • Cost tracking

get_agents_in_node()

Get agents created within a specific node:
Use Cases:
  • 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:
Event Types:
  • agent_created: Agent instantiated
  • agent_called: Agent processing request
  • agent_completed: Request finished
  • agent_error: Error occurred
  • agent_interrupted: Agent stopped
Event Data:

Workflow Context

Auto-Initialization

Discovery works automatically without setup:

Explicit Workflow Naming

Use workflow_context for explicit workflow names:
Benefits:
  • 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

Error Handling

No Agents Discovered

Agent State Errors

Discovery API Failures

What’s Next?

Shared State

Share data across workflow nodes

Validation

Validate workflows before execution

Type Safety

Type checking for workflows

Reporting

Track workflow performance