-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimpleAgent.java
More file actions
63 lines (55 loc) · 2.08 KB
/
SimpleAgent.java
File metadata and controls
63 lines (55 loc) · 2.08 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
/**
* Minimal agent with one tool and POM-based prompts.
*
* Run:
* java SimpleAgent
*
* Test:
* bin/swaig-test --url http://agent:PASS@localhost:3000 --list-tools
* bin/swaig-test --url http://agent:PASS@localhost:3000 --exec get_weather --param city=Austin
*/
import com.signalwire.sdk.agent.AgentBase;
import com.signalwire.sdk.swaig.FunctionResult;
import java.util.List;
import java.util.Map;
public class SimpleAgent {
public static void main(String[] args) throws Exception {
var agent = AgentBase.builder()
.name("weather-agent")
.route("/")
.port(3000)
.build();
// Add prompt sections (Prompt Object Model)
agent.promptAddSection("Role",
"You are a helpful weather assistant.");
agent.promptAddSection("Instructions", "", List.of(
"When asked about weather, use the get_weather tool",
"Provide temperature in both Fahrenheit and Celsius",
"Be friendly and conversational"
));
// Add speech recognition hints
agent.addHints(List.of("weather", "temperature", "forecast"));
// Define a tool
agent.defineTool(
"get_weather",
"Get the current weather for a city",
Map.of(
"type", "object",
"properties", Map.of(
"city", Map.of(
"type", "string",
"description", "The city to get weather for"
)
),
"required", List.of("city")
),
(toolArgs, rawData) -> {
String city = (String) toolArgs.get("city");
return new FunctionResult(
"The weather in " + city + " is 72F (22C) and sunny.");
}
);
System.out.println("Starting weather agent on port 3000...");
agent.run();
}
}