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
Name for the MCP server
Description of the AOP cluster
Optional list of agents to add initially
Port for the MCP server
Transport type for the MCP server
Enable verbose logging
Enable traceback logging for errors
Host to bind the server to
Enable queue-based task execution
Maximum number of workers per agent
Maximum queue size per agent
Timeout for task processing in seconds
Delay between retries in seconds
Enable automatic restart on shutdown (with failsafe)
Maximum number of restart attempts before giving up
Delay between restart attempts in seconds
Enable network connection monitoring and retry
Maximum number of network reconnection attempts
Delay between network retry attempts in seconds
Logging level
Methods
add_agent
Add a single agent to the MCP server as a tool.The Swarms Agent instance to deploy
Name for the tool (defaults to agent.agent_name)
Description of the tool (defaults to agent.agent_description)
JSON schema for input parameters
JSON schema for output
Maximum execution time in seconds
Number of retries on failure
Enable verbose logging for this tool (defaults to deployer’s verbose setting)
Enable traceback logging for this tool
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 of Swarms Agent instances
Optional list of tool names (defaults to agent names)
Optional list of tool descriptions
Optional list of input schemas
Optional list of output schemas
Optional list of timeout values
Optional list of max retry values
Optional list of verbose settings for each agent
Optional list of traceback settings for each agent
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.Name of the tool to remove
True if agent was removed, False if not found
list_agents
Get a list of all registered agent tool names.List of tool names
get_agent_info
Get detailed information about a specific agent tool.Name of the tool
Dictionary containing agent information, or None if not found
get_queue_stats
Get queue statistics for agents.Optional specific agent name. If None, returns stats for all agents.
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