Skip to content

Agency

The Agency module is the core orchestration layer of the Bedrock Swarm framework. It manages communication between agents, coordinates task execution, and handles resource allocation.

Overview

The Agency system consists of several key components:

graph TD
    A[Agency] --> B[Thread Manager]
    A --> C[Event System]
    A --> D[Agent Registry]
    B --> E[Thread]
    B --> F[Run]
    C --> G[Event Tracking]
    C --> H[Event Filtering]
    D --> I[Agent Creation]
    D --> J[Agent Management]

Core Components

  1. Agency
  2. Central coordination point
  3. Manages agent communication
  4. Handles resource allocation
  5. Coordinates task execution

  6. Thread Manager

  7. Manages conversation threads
  8. Handles parallel execution
  9. Coordinates agent interactions
  10. Tracks conversation state

  11. Event System

  12. Records agent activities
  13. Tracks system operations
  14. Enables event filtering
  15. Supports debugging

  16. Agent Registry

  17. Manages agent lifecycle
  18. Handles agent creation
  19. Tracks agent state
  20. Coordinates resources

Key Features

  1. Agent Communication
  2. Direct messaging
  3. Broadcast capabilities
  4. Event notifications
  5. State synchronization

  6. Resource Management

  7. Memory allocation
  8. Model token tracking
  9. Concurrent operations
  10. Load balancing

  11. Task Coordination

  12. Sequential execution
  13. Parallel processing
  14. Priority handling
  15. Error recovery

Usage Examples

from bedrock_swarm.agency import Agency
from bedrock_swarm.agents import BedrockAgent

# Create agency instance
agency = Agency()

# Add agents
calculator = BedrockAgent(
    name="calculator",
    model_id="us.anthropic.claude-3-5-sonnet-20241022-v2:0",
    tools=[CalculatorTool()]
)
agency.add_agent(calculator)

# Process request
response = agency.process_request(
    "Calculate 2 + 2",
    agent_name="calculator"
)

Best Practices

  1. Agent Organization
  2. Group related agents
  3. Define clear responsibilities
  4. Implement proper error handling
  5. Monitor resource usage

  6. Communication Patterns

  7. Use direct messaging
  8. Implement retry logic
  9. Handle timeouts
  10. Track message flow

  11. Resource Management

  12. Monitor token usage
  13. Implement rate limiting
  14. Handle concurrent requests
  15. Manage memory usage

See Also