Add the agents field to create a supervisor that automatically routes requests to specialized child agents using LLM-based intent classification:
const supervisor = new Agent({ name: 'Customer Service', instructions: `Route requests to the right specialist: - Sales: pricing, plans, purchases - Support: technical issues, bugs, how-to`, model: openai('gpt-4o-mini'), // Cheap model for routing agents: { support: { name: 'Support Agent', instructions: 'Solve technical problems step by step.', model: openai('gpt-4o'), tools: { searchOrders: orderTool }, rag: { vectorStore: 'support-docs', k: 5 }, }, sales: { name: 'Sales Agent', instructions: 'Handle sales inquiries. Be consultative.', model: openai('gpt-4o'), }, }, memory: { maxTurns: 30 },});// Supervisor analyzes intent and routes automaticallyawait supervisor.process({ message: 'I want to buy your product', sessionId: 'session_123',});
Each child agent can have its own model, tools, RAG, and memory. The supervisor uses a cheap model for routing while specialists use powerful models for quality responses.
See the dedicated Supervisor guide for routing logic, cost optimization, fallback behavior, and configuration reference.