Copy
import { Agent, openai } from '@runflow-ai/sdk';
// Specialized agents
const salesAgent = new Agent({
name: 'Sales Specialist',
instructions: 'You are a sales expert. Help with pricing, demos, and purchasing.',
model: openai('gpt-4o'),
tools: { /* sales tools */ },
});
const supportAgent = new Agent({
name: 'Technical Support',
instructions: 'You are a technical support expert. Help with technical issues.',
model: openai('gpt-4o'),
rag: { vectorStore: 'tech-docs', k: 5 },
});
const billingAgent = new Agent({
name: 'Billing Specialist',
instructions: 'You handle billing, invoices, and payment issues.',
model: openai('gpt-4o'),
tools: { /* billing tools */ },
});
// Supervisor agent
const supervisorAgent = new Agent({
name: 'Supervisor',
instructions: `You route customer requests to the right specialist:
- Sales: pricing, demos, purchasing
- Support: technical issues, bugs
- Billing: invoices, payments, subscriptions
Analyze the request and respond with: ROUTE_TO: [sales|support|billing]`,
model: openai('gpt-4o-mini'),
});
// Routing function
async function handleCustomerRequest(message: string, context: any) {
// 1. Supervisor analyzes intent
const routing = await supervisorAgent.process({
message: `Analyze this request: "${message}"`,
...context,
});
// 2. Extract route
const route = routing.message.match(/ROUTE_TO: (\w+)/)?.[1] || 'support';
// 3. Route to specialist
const agents = {
sales: salesAgent,
support: supportAgent,
billing: billingAgent,
};
const specialistAgent = agents[route];
// 4. Specialist handles request
const result = await specialistAgent.process({
message,
...context,
});
return {
route,
response: result.message,
};
}
// Example usage
const result = await handleCustomerRequest(
'I want to upgrade to the enterprise plan',
{
sessionId: 'session_456',
userId: 'user_789',
}
);
console.log(`Routed to: ${result.route}`);
console.log(`Response: ${result.response}`);
Features
- ✅ Specialized Agents: Each agent handles specific domain
- ✅ Intelligent Routing: Supervisor analyzes and routes requests
- ✅ Scalable: Easy to add new agents
- ✅ Efficient: Uses cheaper model for routing