-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathGameMasterWithBuiltInTools.java
More file actions
77 lines (62 loc) · 3.12 KB
/
Copy pathGameMasterWithBuiltInTools.java
File metadata and controls
77 lines (62 loc) · 3.12 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
///usr/bin/env jbang "$0" "$@" ; exit $?
//JAVA 25+
//REPOS mavencentral,spring-milestones=https://repo.spring.io/milestone
//DEPS io.netty:netty-bom:4.2.9.Final@pom
//DEPS tools.jackson:jackson-bom:3.1.4@pom
//DEPS com.fasterxml.jackson.core:jackson-annotations:2.21
//DEPS org.springframework.ai:spring-ai-bedrock-converse:2.0.0
//DEPS org.springframework.ai:spring-ai-client-chat:2.0.0
//DEPS software.amazon.awssdk:bedrockruntime:2.49.1
//DEPS software.amazon.awssdk:auth:2.49.1
// Provided for you: the Spring AI Community agent-utils dependency that gives you SmartWebFetchTool.
//DEPS org.springaicommunity:spring-ai-agent-utils:0.10.0
//DEPS org.slf4j:slf4j-api:2.0.17
//DEPS org.slf4j:slf4j-simple:2.0.17
//RUNTIME_OPTIONS -Daws.region=us-west-2 --enable-native-access=ALL-UNNAMED
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ai.bedrock.converse.BedrockProxyChatModel;
import org.springframework.ai.bedrock.converse.BedrockChatOptions;
import org.springframework.ai.chat.client.ChatClient;
import software.amazon.awssdk.auth.credentials.AnonymousCredentialsProvider;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.bedrockruntime.BedrockRuntimeClient;
// Provided for you: the SmartWebFetchTool import from the community library.
import org.springaicommunity.agent.tools.SmartWebFetchTool;
private static final Logger log = LoggerFactory.getLogger("GameMasterWithBuiltInTools");
void main() {
log.info("=== Starting Game Master AI Agent with Built-in Tools ===");
var bearerToken = System.getenv("AWS_BEARER_TOKEN_BEDROCK");
if (bearerToken == null || bearerToken.isBlank()) {
log.error("Set AWS_BEARER_TOKEN_BEDROCK first — get your key from the Amazon Bedrock Console → API keys → Short-term API keys");
return;
}
var bedrockClient = BedrockRuntimeClient.builder()
.region(Region.US_WEST_2)
.credentialsProvider(AnonymousCredentialsProvider.create())
.overrideConfiguration(c -> c.putHeader("Authorization", "Bearer " + bearerToken))
.build();
var modelId = "us.anthropic.claude-haiku-4-5-20251001-v1:0";
var options = BedrockChatOptions.builder()
.model(modelId)
.build();
var chatModel = BedrockProxyChatModel.builder()
.bedrockRuntimeClient(bedrockClient)
.options(options)
.build();
var agent = ChatClient.builder(chatModel).build();
// TODO 1: Create a SmartWebFetchTool from the agent. It uses a builder:
try {
var response = agent.prompt()
.user("Using the website https://en.wikipedia.org/wiki/Dungeons_%26_Dragons tell me the name of the designers of Dungeons and Dragons.")
// TODO 2: Pass your web-fetch tool to the agent
.call()
.content();
log.info("Agent Response:");
log.info(response);
} catch (Exception e) {
log.error("Error invoking AI agent: {}", e.getMessage());
} finally {
log.info("\n=== Ending Game Master AI Agent with Built-in Tools ===");
}
}