-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCallFlow.java
More file actions
92 lines (76 loc) · 3.24 KB
/
CallFlow.java
File metadata and controls
92 lines (76 loc) · 3.24 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
/**
* 5-phase call flow with pre/post answer verbs, recording, and post-AI actions.
*
* Demonstrates the full call lifecycle:
* Phase 1: Pre-answer verbs (e.g., play hold music before answering)
* Phase 2: Answer with recording
* Phase 3: Post-answer verbs
* Phase 4: AI agent conversation
* Phase 5: Post-AI verbs (e.g., cleanup, hangup)
*/
import com.signalwire.sdk.agent.AgentBase;
import com.signalwire.sdk.swaig.FunctionResult;
import java.util.List;
import java.util.Map;
public class CallFlow {
public static void main(String[] args) throws Exception {
var agent = AgentBase.builder()
.name("callflow-agent")
.route("/")
.port(3000)
.autoAnswer(true)
.maxDuration(1800) // 30 minutes max
.recordCall(true) // Record the call
.recordFormat("mp4")
.recordStereo(true)
.build();
// Phase 1: Pre-answer verbs
// (could play hold music or collect DTMF before answering)
// Phase 3: Post-answer verbs (after answer, before AI)
agent.addPostAnswerVerb("play", Map.of(
"url", "say:Please wait while we connect you with our AI assistant."
));
// Phase 4: AI configuration
agent.promptAddSection("Role",
"You are a customer service representative for TechCorp.");
agent.promptAddSection("Instructions", "", List.of(
"Be professional and helpful",
"Collect the customer's issue description",
"Offer solutions or escalate to a human agent"
));
// Set AI parameters
agent.setPromptLlmParams(Map.of(
"temperature", 0.3,
"top_p", 0.9
));
// Set post-prompt for conversation summary
agent.setPostPrompt(
"Summarize the call: what was the issue, what was the resolution.");
agent.setPostPromptLlmParams(Map.of(
"temperature", 0.1
));
// Add pronunciations
agent.addPronunciation("TechCorp", "TekCorp", true);
// Add speech hints
agent.addHints(List.of("TechCorp", "support", "technical", "billing"));
// Add language support
agent.addLanguage("English", "en-US", "en-US-Standard-C");
agent.addLanguage("Spanish", "es-US", "es-US-Standard-A");
// Tools
agent.defineTool("escalate", "Escalate to a human agent",
Map.of("type", "object", "properties", Map.of(
"reason", Map.of("type", "string", "description", "Reason for escalation")
), "required", List.of("reason")),
(toolArgs, raw) -> new FunctionResult(
"Transferring you to a human agent for: " + toolArgs.get("reason"))
.connect("+15551234567", true));
// Phase 5: Post-AI verbs (after AI finishes)
agent.addPostAiVerb("hangup", Map.of());
// Summary callback
agent.onSummary((summary, rawPayload) -> {
System.out.println("Call summary: " + summary);
});
System.out.println("Starting call flow agent on port 3000...");
agent.run();
}
}