-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLambdaAgent.java
More file actions
58 lines (49 loc) · 2.16 KB
/
LambdaAgent.java
File metadata and controls
58 lines (49 loc) · 2.16 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
/**
* AWS Lambda Deployment Example.
*
* Demonstrates an agent designed for serverless deployment. In a real
* Lambda setup you would use a Java Lambda handler framework to translate
* API Gateway events to HTTP requests.
*
* For local testing, this runs as a normal HTTP server.
*/
import com.signalwire.sdk.agent.AgentBase;
import com.signalwire.sdk.swaig.FunctionResult;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Map;
public class LambdaAgent {
public static void main(String[] args) throws Exception {
var agent = AgentBase.builder()
.name("lambda-agent")
.route("/")
.port(3000)
.build();
agent.addLanguage("English", "en-US", "en-US-Standard-C");
agent.promptAddSection("Role",
"You are a helpful AI assistant running in AWS Lambda.");
agent.promptAddSection("Instructions", "", List.of(
"Greet users warmly and offer help",
"Use the greet_user function when asked to greet someone",
"Use the get_time function when asked about the current time"
));
agent.defineTool("greet_user", "Greet a user by name",
Map.of("type", "object",
"properties", Map.of(
"name", Map.of("type", "string",
"description", "User name")
)),
(toolArgs, raw) -> {
String name = (String) toolArgs.getOrDefault("name", "friend");
return new FunctionResult("Hello " + name + "! I'm running in AWS Lambda!");
});
agent.defineTool("get_time", "Get the current time",
Map.of("type", "object", "properties", Map.of()),
(toolArgs, raw) -> new FunctionResult(
"Current time: " + LocalDateTime.now()
.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME)));
System.out.println("Starting Lambda agent (local testing) on port 3000...");
agent.run();
}
}