Repository navigation
Expand file tree
/
Copy pathDataMapDemo.cs
More file actions
73 lines (62 loc) · 2.4 KB
/
Copy pathDataMapDemo.cs
File metadata and controls
73 lines (62 loc) · 2.4 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
// DataMap Demo - Shows how to use the DataMap class for server-side tools
//
// This demo creates an agent with data_map tools:
// 1. Simple API call (weather)
// 2. Expression-based pattern matching
// These tools execute on SignalWire's servers, no webhook needed.
using SignalWire.Agent;
using SignalWire.DataMap;
using SignalWire.SWAIG;
var agent = new AgentBase(new AgentOptions
{
Name = "datamap-demo",
Route = "/datamap-demo",
});
agent.PromptAddSection(
"Role",
"You are a helpful assistant with access to weather data and file playback control."
);
// 1. Simple weather API via DataMap
var weather = new DataMap("get_weather")
.Description("Get weather for a location")
.Parameter("location", "string", "City name or location", required: true)
.Webhook("GET", "https://api.weather.com/v1/current?key=API_KEY&q=${args.location}")
.Output(new FunctionResult(
"Current weather in ${args.location}: ${response.current.condition.text}, ${response.current.temp_f}F"
));
agent.RegisterSwaigFunction(weather.ToSwaigFunction());
// 2. Expression-based file control (no API calls)
var fileControl = new DataMap("file_control")
.Description("Control audio/video playback")
.Parameter("command", "string", "Playback command", required: true,
enumValues: new List<string> { "play", "pause", "stop", "next", "previous" })
.Expression(
"${args.command}",
"play|resume",
new FunctionResult("Playback started"),
nomatchOutput: new FunctionResult("Playback stopped")
);
agent.RegisterSwaigFunction(fileControl.ToSwaigFunction());
// 3. Regular SWAIG function for comparison
agent.DefineTool(
name: "echo_test",
description: "A simple echo function for testing",
parameters: new Dictionary<string, object>
{
["message"] = new Dictionary<string, object>
{
["type"] = "string",
["description"] = "Message to echo back",
},
},
handler: (args, raw) =>
{
var msg = args.GetValueOrDefault("message")?.ToString() ?? "nothing";
return new FunctionResult($"Echo: {msg}");
}
);
agent.AddLanguage("English", "en-US", "inworld.Mark");
agent.SetParams(new Dictionary<string, object> { ["ai_model"] = "gpt-4.1-nano" });
Console.WriteLine("Starting DataMap Demo Agent");
Console.WriteLine("Available at: http://localhost:3000/datamap-demo");
agent.Run();