Repository navigation
Expand file tree
/
Copy pathCustomPathAgent.java
More file actions
61 lines (49 loc) · 2.33 KB
/
Copy pathCustomPathAgent.java
File metadata and controls
61 lines (49 loc) · 2.33 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
/**
* Custom Path Agent -- agent served at a non-root path.
*
* Demonstrates how to create an agent at a custom route (/chat) with
* dynamic per-request personalization from query parameters.
*
* Try: ?user_name=Alice&topic=AI&mood=professional
*/
import com.signalwire.sdk.agent.AgentBase;
import java.util.List;
import java.util.Map;
public class CustomPathAgent {
public static void main(String[] args) throws Exception {
var agent = AgentBase.builder()
.name("chat-assistant")
.route("/chat")
.port(3000)
.recordCall(true)
.build();
agent.promptAddSection("Role",
"You are a friendly chat assistant ready to help with any questions.");
agent.setDynamicConfigCallback((queryParams, bodyParams, headers, configAgent) -> {
String userName = queryParams.getOrDefault("user_name", "friend");
String topic = queryParams.getOrDefault("topic", "general conversation");
String mood = queryParams.getOrDefault("mood", "friendly").toLowerCase();
configAgent.promptAddSection("Personalization",
"The user's name is " + userName + ". They're interested in " + topic + ".");
configAgent.addLanguage("English", "en-US", "en-US-Standard-C");
switch (mood) {
case "professional" -> configAgent.promptAddSection("Communication Style",
"Maintain a professional, business-appropriate tone.");
case "casual" -> configAgent.promptAddSection("Communication Style",
"Use a casual, relaxed conversational style.");
default -> configAgent.promptAddSection("Communication Style",
"Be warm, friendly, and approachable in your responses.");
}
configAgent.setGlobalData(Map.of(
"user_name", userName,
"topic", topic,
"mood", mood,
"session_type", "chat"
));
configAgent.addHints(List.of("chat", "assistant", "help", "conversation"));
});
System.out.println("Starting chat agent at /chat on port 3000...");
System.out.println("Try: ?user_name=Alice&topic=AI&mood=professional");
agent.run();
}
}