Overview
The AOP (Agent Orchestration Platform) class enables you to deploy multiple Swarms agents as individual tools in an MCP server. It provides production-ready features including queue-based task execution, automatic restart capabilities, network monitoring, and comprehensive error handling.Constructor
Create an AOP instance to manage and deploy agents as MCP tools.Parameters
str
default:"AOP Cluster"
Name for the MCP server
str
Description of the AOP cluster
any
default:"None"
Optional list of agents to add initially
int
default:"8000"
Port for the MCP server
str
default:"streamable-http"
Transport type for the MCP server
bool
default:"False"
Enable verbose logging
bool
default:"True"
Enable traceback logging for errors
str
default:"localhost"
Host to bind the server to
bool
default:"True"
Enable queue-based task execution
int
default:"1"
Maximum number of workers per agent
int
default:"1000"
Maximum queue size per agent
int
default:"30"
Timeout for task processing in seconds
float
default:"1.0"
Delay between retries in seconds
bool
default:"False"
Enable automatic restart on shutdown (with failsafe)
int
default:"10"
Maximum number of restart attempts before giving up
float
default:"5.0"
Delay between restart attempts in seconds
bool
default:"True"
Enable network connection monitoring and retry
int
default:"5"
Maximum number of network reconnection attempts
float
default:"10.0"
Delay between network retry attempts in seconds
Literal['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL']
default:"INFO"
Logging level
Methods
add_agent
Add a single agent to the MCP server as a tool.AgentType
required
The Swarms Agent instance to deploy
str
default:"None"
Name for the tool (defaults to agent.agent_name)
str
default:"None"
Description of the tool (defaults to agent.agent_description)
Dict[str, Any]
default:"None"
JSON schema for input parameters
Dict[str, Any]
default:"None"
JSON schema for output
int
default:"30"
Maximum execution time in seconds
int
default:"3"
Number of retries on failure
bool
default:"None"
Enable verbose logging for this tool (defaults to deployer’s verbose setting)
bool
default:"None"
Enable traceback logging for this tool
str
The tool name that was registered
ValueError: If agent is None or tool_name already exists
add_agents_batch
Add multiple agents to the MCP server in batch.List[Agent]
required
List of Swarms Agent instances
List[str]
default:"None"
Optional list of tool names (defaults to agent names)
List[str]
default:"None"
Optional list of tool descriptions
List[Dict[str, Any]]
default:"None"
Optional list of input schemas
List[Dict[str, Any]]
default:"None"
Optional list of output schemas
List[int]
default:"None"
Optional list of timeout values
List[int]
default:"None"
Optional list of max retry values
List[bool]
default:"None"
Optional list of verbose settings for each agent
List[bool]
default:"None"
Optional list of traceback settings for each agent
List[str]
List of tool names that were registered
ValueError: If agents list is empty or contains None values
remove_agent
Remove an agent from the MCP server.str
required
Name of the tool to remove
bool
True if agent was removed, False if not found
list_agents
Get a list of all registered agent tool names.List[str]
List of tool names
get_agent_info
Get detailed information about a specific agent tool.str
required
Name of the tool
Optional[Dict[str, Any]]
Dictionary containing agent information, or None if not found
get_queue_stats
Get queue statistics for agents.str
default:"None"
Optional specific agent name. If None, returns stats for all agents.
Dict[str, Any]
Dictionary containing queue statistics
Queue Management
Whenqueue_enabled=True, each agent gets its own task queue with the following features:
TaskQueue Features
- Priority-based execution: Tasks can be assigned priorities
- Automatic retries: Failed tasks are automatically retried
- Worker threads: Background workers process tasks concurrently
- Statistics tracking: Comprehensive metrics on task execution
- Pause/resume: Queues can be paused and resumed
Queue States
- RUNNING: Queue is actively processing tasks
- PAUSED: Queue is paused, workers wait for resume
- STOPPED: Queue is stopped, workers are terminated
Task States
- PENDING: Task is waiting in queue
- PROCESSING: Task is currently being executed
- COMPLETED: Task completed successfully
- FAILED: Task failed after max retries
- CANCELLED: Task was cancelled
Persistence & Network Monitoring
Persistence Mode
Whenpersistence=True:
- Server automatically restarts on shutdown
- Configurable restart attempts and delays
- Failsafe protection prevents infinite restart loops
Network Monitoring
Whennetwork_monitoring=True:
- Automatic detection of network issues
- Retry logic for network failures
- Configurable retry attempts and delays
Complete Example
Best Practices
- Enable queuing: Use
queue_enabled=Truefor production reliability - Set timeouts: Configure appropriate timeouts based on task complexity
- Monitor queues: Regularly check queue statistics to identify bottlenecks
- Use persistence: Enable persistence mode for critical production deployments
- Configure workers: Adjust
max_workers_per_agentbased on load requirements - Enable logging: Use
verbose=Trueand appropriatelog_levelfor debugging - Handle failures: Set
max_retriesappropriately for your use case - Network resilience: Enable
network_monitoringfor unstable connections - Gradual scaling: Start with fewer agents and scale up based on metrics
- Health monitoring: Regular check
get_queue_stats()for system health