The ASP Orchestrator is a component designed to manage services and tasks within the Agent Swarm Protocol ecosystem. It provides a centralized way to track agents, the services they provide, and the tasks they can perform.
- Agent Management: Register and track agent properties, capabilities, and status
- Service Registry: Catalog of services offered by agents with their input/output schemas
- Task Management: Create, assign, and track task status across the system
- Agent-Task Matching: Find suitable agents for tasks based on capabilities
- Service Recommendations: Suggest services based on task requirements
- System Statistics: Monitor usage and performance metrics
- MCP Support: Integrate with Model Context Protocol servers for expanded tool capabilities
The main controller that integrates all aspects of the system:
- Maintains agent information and status
- Manages the service registry
- Handles task creation and assignment
- Provides system-wide statistics
- Manages MCP server connections
Catalogs all services that agents can provide:
- Service definitions with input/output schemas
- Service categorization
- Provider tracking
Tracks all tasks in the system:
- Task status monitoring
- Assignment tracking
- Result storage
Manages Model Context Protocol servers:
- MCP server registration and connection
- Tool discovery and execution
- Protocol-compliant communication
const { Orchestrator } = require('./orchestrator');
const orchestrator = new Orchestrator();
const agent = orchestrator.registerAgent({
id: 'agent-1',
name: 'Example Agent',
type: 'assistant',
capabilities: ['text-generation', 'question-answering']
});
const service = orchestrator.registerService({
name: 'text-generation',
providerId: agent.id,
category: 'content',
schema: {
input: {
prompt: 'string',
maxTokens: 'number'
},
output: {
text: 'string'
}
}
});
// Create a task
const task = orchestrator.createTask({
type: 'content',
name: 'Generate product description',
description: 'Create a compelling product description for our new item',
input: {
product: 'Smart Lamp',
targetAudience: 'tech enthusiasts'
},
requesterId: 'requester-agent-id'
});
// Find suitable agents
const suitableAgents = orchestrator.findAgentsForTask(
task,
['text-generation', 'marketing']
);
// Assign the task
orchestrator.assignTask(task.id, suitableAgents[0].id);
// Update task status
orchestrator.updateTaskStatus(task.id, 'in_progress', {
note: 'Working on the description'
});
// Complete task
orchestrator.updateTaskStatus(task.id, 'completed', {
note: 'Description completed',
result: {
description: 'An innovative smart lamp that transforms your living space...'
}
});
MCP (Model Context Protocol) servers provide additional tool capabilities to agents through a standardized protocol. Agents can use these tools through the orchestrator's MCP service.
// Agent requests to register a new MCP server
const mcpServer = await agent.sendServiceRequest('mcp-service', {
action: 'register-server',
name: 'weather-server',
path: '/path/to/weather-server.js',
type: 'node'
});
// Get the server ID for future reference
const serverId = mcpServer.serverId;
// Connect to the registered server
const connection = await agent.sendServiceRequest('mcp-service', {
action: 'connect-server',
serverId: serverId // Or use server name with: mcpServerName: 'weather-server'
});
// The server tools are available in the response
const tools = connection.tools;
// Get tools provided by a specific MCP server
const toolList = await agent.sendServiceRequest('mcp-service', {
action: 'list-tools',
serverId: serverId
});
// Tools include name, description and input schema
console.log(toolList.tools);
// Execute a tool from the MCP server
const taskExecution = await agent.sendServiceRequest('mcp-service', {
action: 'execute-tool',
serverId: serverId,
toolName: 'get-weather',
toolArgs: {
location: 'San Francisco',
units: 'metric'
}
});
// Get the task ID to track progress
const taskId = taskExecution.taskId;
// Check task status later
const taskStatus = await agent.getTaskStatus(taskId);
// Process the result when task is completed
if (taskStatus.status === 'completed') {
const result = taskStatus.result;
console.log(`Weather in San Francisco: ${result.data.temperature}°C`);
}
const recommendedServices = orchestrator.getRecommendedServices(
task,
'content'
);
const stats = orchestrator.getStatistics();
console.log(stats);
See example-usage.js for a complete example of how to use the Orchestrator.
For MCP integration examples, see mcp/example-usage.js.
The Orchestrator is designed to work within the Agent Swarm Protocol ecosystem, providing service and task management capabilities to enhance coordination among multiple agents. It can be used by controller agents to:
- Discover available services
- Assign tasks to specialized agents
- Monitor task progress
- Collect and distribute results
- Optimize resource allocation based on agent capabilities and availability
- Access external tools through MCP servers