-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmulti-agent.ts
More file actions
73 lines (65 loc) · 2.17 KB
/
multi-agent.ts
File metadata and controls
73 lines (65 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/**
* Multi-Agent Server Example
*
* Host multiple agents under a single HTTP server, each at its own route.
* Run: npx tsx examples/multi-agent.ts
* Test:
* curl http://user:pass@localhost:3000/support
* curl http://user:pass@localhost:3000/sales
* curl http://localhost:3000/ (agent listing)
* curl http://localhost:3000/health
*/
import { AgentBase, AgentServer, FunctionResult } from '../src/index.js';
// --- Support Agent ---
export const support = new AgentBase({
name: 'support',
route: '/support',
basicAuth: [
process.env['SWML_BASIC_AUTH_USER'] ?? 'user',
process.env['SWML_BASIC_AUTH_PASSWORD'] ?? 'pass',
],
});
support.setPromptText('You are a customer support agent. Help resolve issues quickly and politely.');
support.addLanguage({ name: 'English', code: 'en-US', voice: 'rachel' });
support.defineTool({
name: 'lookup_ticket',
description: 'Look up a support ticket by ID',
parameters: {
ticket_id: { type: 'string', description: 'The ticket ID' },
},
handler: (args) => {
return new FunctionResult(`Ticket ${args.ticket_id}: Status is "In Progress", assigned to Team B.`);
},
});
// --- Sales Agent ---
export const sales = new AgentBase({
name: 'sales',
route: '/sales',
basicAuth: [
process.env['SWML_BASIC_AUTH_USER'] ?? 'user',
process.env['SWML_BASIC_AUTH_PASSWORD'] ?? 'pass',
],
});
sales.setPromptText('You are a sales agent. Help potential customers understand our products and pricing.');
sales.addLanguage({ name: 'English', code: 'en-US', voice: 'dave' });
sales.defineTool({
name: 'get_pricing',
description: 'Get pricing information for a product',
parameters: {
product: { type: 'string', description: 'Product name' },
},
handler: (args) => {
const prices: Record<string, string> = {
basic: '$29/mo',
pro: '$99/mo',
enterprise: 'Custom pricing - schedule a call',
};
const price = prices[args.product?.toLowerCase()] ?? 'Product not found';
return new FunctionResult(`Pricing for ${args.product}: ${price}`);
},
});
// --- Server ---
const server = new AgentServer({ port: 3000 });
server.register(support);
server.register(sales);
server.run();