-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathComprehensiveDynamic.java
More file actions
127 lines (113 loc) · 5.55 KB
/
ComprehensiveDynamic.java
File metadata and controls
127 lines (113 loc) · 5.55 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/**
* Comprehensive Dynamic Agent Configuration.
*
* Demonstrates per-request customization based on query parameters:
* - Tier-based features (standard / premium / enterprise)
* - Industry-specific prompts (healthcare / finance / retail)
* - Language and voice selection
* - A/B testing configuration
* - Debug mode
*
* Try: ?tier=premium&industry=healthcare&lang=es&test_group=B
*/
import com.signalwire.sdk.agent.AgentBase;
import java.util.List;
import java.util.Map;
public class ComprehensiveDynamic {
public static void main(String[] args) throws Exception {
var agent = AgentBase.builder()
.name("comprehensive-dynamic")
.route("/dynamic")
.port(3000)
.recordCall(true)
.build();
agent.setDynamicConfigCallback((queryParams, bodyParams, headers, configAgent) -> {
String tier = queryParams.getOrDefault("tier", "standard").toLowerCase();
String industry = queryParams.getOrDefault("industry", "general").toLowerCase();
String lang = queryParams.getOrDefault("lang", "en").toLowerCase();
String testGroup = queryParams.getOrDefault("test_group", "A").toUpperCase();
boolean debug = "true".equals(queryParams.get("debug"));
String customerId = queryParams.getOrDefault("customer_id", "");
// --- Voice / Language ---
if ("es".equals(lang)) {
configAgent.addLanguage("Spanish", "es-ES", "es-ES-Standard-A");
} else {
configAgent.addLanguage("English US", "en-US", "en-US-Standard-C");
}
// --- Tier parameters ---
switch (tier) {
case "enterprise" -> configAgent.setParams(Map.of(
"end_of_speech_timeout", 800,
"attention_timeout", 25000));
case "premium" -> configAgent.setParams(Map.of(
"end_of_speech_timeout", 600,
"attention_timeout", 20000));
default -> configAgent.setParams(Map.of(
"end_of_speech_timeout", 400,
"attention_timeout", 15000));
}
// --- Industry prompts ---
configAgent.promptAddSection("Role",
"You are a professional AI assistant specialized in " + industry + " services.");
if ("healthcare".equals(industry)) {
configAgent.promptAddSection("Healthcare Guidelines",
"Follow HIPAA compliance. Never provide medical diagnoses.", List.of(
"Protect patient privacy",
"Direct medical questions to providers",
"Use appropriate medical terminology"
));
} else if ("finance".equals(industry)) {
configAgent.promptAddSection("Financial Guidelines",
"Adhere to financial regulations.", List.of(
"Never provide investment advice",
"Protect sensitive financial data",
"Use precise financial terminology"
));
} else if ("retail".equals(industry)) {
configAgent.promptAddSection("Customer Service",
"Focus on satisfaction and sales support.", List.of(
"Be friendly and helpful",
"Handle complaints with empathy",
"Look for upsell opportunities"
));
}
// --- Enhanced tier capabilities ---
if ("premium".equals(tier) || "enterprise".equals(tier)) {
configAgent.promptAddSection("Enhanced Capabilities",
"As a " + tier + " service you have advanced features:", List.of(
"Extended conversation memory",
"Priority processing",
"Specialized knowledge bases"
));
}
// --- A/B testing ---
if ("B".equals(testGroup)) {
configAgent.addHints(List.of("enhanced", "personalized", "proactive"));
configAgent.promptAddSection("Enhanced Interaction Style",
"Use an enhanced conversation style:", List.of(
"Ask clarifying questions frequently",
"Provide detailed explanations",
"Offer proactive suggestions"
));
}
// --- Debug mode ---
if (debug) {
configAgent.promptAddSection("Debug Mode",
"Debug mode is active. Show reasoning in responses.");
configAgent.addHints(List.of("debug", "verbose", "reasoning"));
}
// --- Global data ---
configAgent.updateGlobalData(Map.of(
"service_tier", tier,
"industry", industry,
"test_group", testGroup
));
if (!customerId.isEmpty()) {
configAgent.updateGlobalData(Map.of("customer_id", customerId));
}
});
System.out.println("Starting comprehensive dynamic agent on port 3000...");
System.out.println("Try: ?tier=premium&industry=healthcare&lang=es&test_group=B");
agent.run();
}
}