-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathWebSearchAgent.java
More file actions
62 lines (52 loc) · 2.08 KB
/
Copy pathWebSearchAgent.java
File metadata and controls
62 lines (52 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
/**
* Web Search Agent.
*
* Uses the web_search skill to give the agent internet search capabilities.
*
* Requires env vars:
* GOOGLE_SEARCH_API_KEY
* GOOGLE_SEARCH_ENGINE_ID
*
* Get credentials at: https://developers.google.com/custom-search/v1/introduction
*/
import com.signalwire.sdk.agent.AgentBase;
import java.util.List;
import java.util.Map;
public class WebSearchAgent {
public static void main(String[] args) throws Exception {
String apiKey = System.getenv("GOOGLE_SEARCH_API_KEY");
String engineId = System.getenv("GOOGLE_SEARCH_ENGINE_ID");
if (apiKey == null || engineId == null
|| apiKey.isEmpty() || engineId.isEmpty()) {
System.err.println("Missing required env vars:");
System.err.println(" GOOGLE_SEARCH_API_KEY");
System.err.println(" GOOGLE_SEARCH_ENGINE_ID");
System.exit(1);
}
var agent = AgentBase.builder()
.name("web-search-assistant")
.route("/search")
.port(3000)
.build();
agent.addLanguage("English", "en-US", "en-US-Standard-C");
agent.promptAddSection("Personality",
"You are Franklin, a friendly and knowledgeable search bot.");
agent.promptAddSection("Goal",
"Help users find accurate, up-to-date information from the web.");
agent.promptAddSection("Instructions", "", List.of(
"Always introduce yourself as Franklin",
"Use the web search tool to find current information",
"Present results in a clear, organized manner",
"Be enthusiastic about searching and learning"
));
agent.addSkill("web_search", Map.of(
"api_key", apiKey,
"search_engine_id", engineId,
"num_results", 1,
"max_content_length", 3000
));
System.out.println("Loaded skills: " + agent.listSkills());
System.out.println("Starting Web Search Agent on port 3000...");
agent.run();
}
}