Repository navigation
Expand file tree
/
Copy pathSimpleAgent.cs
More file actions
135 lines (111 loc) · 3.89 KB
/
Copy pathSimpleAgent.cs
File metadata and controls
135 lines (111 loc) · 3.89 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
128
129
130
131
132
133
134
135
// Simple example of using the SignalWire AI Agent SDK (.NET)
//
// This example demonstrates creating an agent using explicit methods
// to manipulate the POM (Prompt Object Model) structure directly.
using SignalWire.Agent;
using SignalWire.SWAIG;
// Create an agent
var agent = new AgentBase(new AgentOptions
{
Name = "simple",
Route = "/simple",
Host = "0.0.0.0",
Port = 3000,
});
// --- Prompt Configuration ---
agent.PromptAddSection("Personality", "You are a friendly and helpful assistant.");
agent.PromptAddSection("Goal", "Help users with basic tasks and answer questions.");
agent.PromptAddSection("Instructions", "", new List<string>
{
"Be concise and direct in your responses.",
"If you don't know something, say so clearly.",
"Use the get_time function when asked about the current time.",
"Use the get_weather function when asked about the weather.",
});
// LLM parameters
agent.SetPromptLlmParams(new Dictionary<string, object>
{
["temperature"] = 0.3,
["top_p"] = 0.9,
["barge_confidence"] = 0.7,
["presence_penalty"] = 0.1,
["frequency_penalty"] = 0.2,
});
// Post-prompt for summary generation
agent.SetPostPrompt(@"Return a JSON summary of the conversation:
{
""topic"": ""MAIN_TOPIC"",
""satisfied"": true/false,
""follow_up_needed"": true/false
}");
// --- Pronunciation and Hints ---
agent.AddHints(new List<string> { "SignalWire", "SWML", "SWAIG" });
agent.AddPronunciation("API", "A P I");
agent.AddPronunciation("SIP", "sip", ignoreCase: true);
// --- Languages ---
agent.AddLanguage("English", "en-US", "inworld.Mark");
agent.AddLanguage("Spanish", "es", "inworld.Sarah");
agent.AddLanguage("French", "fr-FR", "inworld.Hanna");
// --- AI Behavior ---
agent.SetParams(new Dictionary<string, object>
{
["ai_model"] = "gpt-4.1-nano",
["wait_for_user"] = false,
["end_of_speech_timeout"] = 1000,
["ai_volume"] = 5,
["languages_enabled"] = true,
["local_tz"] = "America/Los_Angeles",
});
agent.SetGlobalData(new Dictionary<string, object>
{
["company_name"] = "SignalWire",
["product"] = "AI Agent SDK",
["supported_features"] = new List<string> { "Voice AI", "Telephone integration", "SWAIG functions" },
});
// --- Native Functions ---
agent.SetNativeFunctions(new List<string> { "check_time", "wait_seconds" });
// --- Tool Definitions ---
agent.DefineTool(
name: "get_time",
description: "Get the current time",
parameters: new Dictionary<string, object>(),
handler: (args, rawData) =>
{
var time = DateTime.Now.ToString("HH:mm:ss");
return new FunctionResult($"The current time is {time}");
}
);
agent.DefineTool(
name: "get_weather",
description: "Get the current weather for a location",
parameters: new Dictionary<string, object>
{
["location"] = new Dictionary<string, object>
{
["type"] = "string",
["description"] = "The city or location to get weather for",
},
},
handler: (args, rawData) =>
{
var location = args.GetValueOrDefault("location")?.ToString() ?? "Unknown location";
var result = new FunctionResult($"It's sunny and 72F in {location}.");
result.UpdateGlobalData(new Dictionary<string, object> { ["weather_location"] = location });
return result;
}
);
// --- Summary Callback ---
agent.OnSummary((summary, rawData, headers) =>
{
if (!string.IsNullOrEmpty(summary))
{
Console.WriteLine($"SUMMARY: {summary}");
}
});
// --- Start the Agent ---
var (user, pass) = agent.GetBasicAuthCredentials();
Console.WriteLine("Starting the agent. Press Ctrl+C to stop.");
Console.WriteLine("Agent 'simple' is available at:");
Console.WriteLine("URL: http://localhost:3000/simple");
Console.WriteLine($"Basic Auth: {user}:{pass}");
agent.Run();