-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMultiAgentServer.java
More file actions
71 lines (64 loc) · 2.81 KB
/
MultiAgentServer.java
File metadata and controls
71 lines (64 loc) · 2.81 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
/**
* Host multiple agents on different routes using AgentServer.
*
* Routes:
* /sales -> Sales agent
* /support -> Support agent
* /health -> Health check
*/
import com.signalwire.sdk.agent.AgentBase;
import com.signalwire.sdk.server.AgentServer;
import com.signalwire.sdk.swaig.FunctionResult;
import java.util.List;
import java.util.Map;
public class MultiAgentServer {
public static void main(String[] args) throws Exception {
// Create Sales agent
var salesAgent = AgentBase.builder()
.name("sales-agent")
.route("/sales")
.build();
salesAgent.promptAddSection("Role",
"You are a sales representative for Acme Corp.");
salesAgent.promptAddSection("Instructions", "", List.of(
"Help customers learn about our products",
"Answer pricing questions",
"Collect contact information for follow-up"
));
salesAgent.defineTool("get_pricing", "Get product pricing",
Map.of("type", "object", "properties", Map.of(
"product", Map.of("type", "string", "description", "Product name")
)),
(toolArgs, raw) -> {
String product = (String) toolArgs.getOrDefault("product", "unknown");
return new FunctionResult("The price for " + product + " is $99/month.");
});
// Create Support agent
var supportAgent = AgentBase.builder()
.name("support-agent")
.route("/support")
.build();
supportAgent.promptAddSection("Role",
"You are a technical support specialist.");
supportAgent.promptAddSection("Instructions", "", List.of(
"Help users troubleshoot technical issues",
"Escalate complex issues to a human agent",
"Be patient and thorough"
));
supportAgent.defineTool("create_ticket", "Create a support ticket",
Map.of("type", "object", "properties", Map.of(
"subject", Map.of("type", "string", "description", "Ticket subject"),
"description", Map.of("type", "string", "description", "Issue description")
)),
(toolArgs, raw) -> new FunctionResult(
"Ticket created: " + toolArgs.get("subject")));
// Create and start the server
var server = new AgentServer(3000);
server.register(salesAgent);
server.register(supportAgent);
System.out.println("Starting multi-agent server on port 3000...");
System.out.println(" Sales: http://localhost:3000/sales");
System.out.println(" Support: http://localhost:3000/support");
server.run();
}
}