Supercharge your team to ship faster with the most advanced AI code reviews.
Free eBook: Sustainability for Java Developers
Towards an understanding of sustainable software development, written by and for the friends of OpenJDK
Standards Over Lock-In: Modernizing Java with Jakarta EE 11 on Azul Payara 7
Learn how to get your Java applications to cloud-native, AI-ready infrastructure without a costly rewrite or vendor lock-in. Join the engineers behind Azul Payara 7 on July 9.
Do you want your ad here?
Contact us to get your ad seen by thousands of users every day!
In Part 1 and Part 2, we explored the Spring AI SDK and Amazon Bedrock AgentCore features, including the agentcore runtime starter and integration of agentcore memory. In this article, we will explore the integration of AgentCore built-in tools, including the Browser and Code Interpreter features.
Repository containing the companion code for the tutorial. Go to GitHub.
Built-In Tool Browser
The use case I am trying to build here is for the given URL; it navigates the entire website and retrieves the content and gives key points and the summary of the page using the AgentCore Browser tool.
1. Adding Built-in Tools: AgentCore Browser
AgentCore provides specialized tools, such as the Browser and Code Interpreter, which the SDK exposes as Spring AI tool callbacks through the ToolCallbackProvider interface.
By adding the AgentCore Browser, agents can navigate websites, perform actions such as parsing content and fetching images, and provide summaries of the given URL.
To start with, add the below dependency in pom.xml
This BuiltInToolsAgent class is a Spring service that integrates the Spring AI SDK with Amazon Bedrock AgentCore built-in tools, specifically the Browser tool. It uses ChatClient to interact with the LLM and enables tool execution through ToolCallbackProvider.
This class acts as an AI agent service that processes prompts and invokes AgentCore tools.
ChatClient
Main Spring AI client used to communicate with the foundation model.
Whenever the model requires browser actions, it can automatically invoke the tool callback.
Chat Method
Accepts:
PromptRequest → user prompt
AgentCoreContext → AgentCore execution context
Returns: AI-generated response as a string
Generates a unique session ID for every interaction.
Helps AgentCore maintain conversation tracking and memory isolation.
Logs incoming user requests.
Sends the user prompt to the LLM.
Passes the session ID to AgentCore advisors.
Allows AgentCore to associate memory and execution state with the session.
Executes the prompt request.
Retrieves only the textual response content.
Logs the generated AI response.
Sends the final AI-generated output back to the caller.
The key concept here is .defaultToolCallbacks(browserTools). This line enables Amazon Bedrock AgentCore built-in Browser capabilities inside the Spring AI SDK through the ToolCallbackProvider abstraction.
+-------------------+
| User Prompt |
+-------------------+
|
v
+-------------------+
| BuiltInToolsAgent |
+-------------------+
|
v
+-------------------+
| ChatClient |
| Processes Prompt |
+-------------------+
|
v
+------------------------------+
| Browser Tool Callback |
| Registered via |
| ToolCallbackProvider |
+------------------------------+
|
v
+------------------------------+
| LLM Decides Whether to Use |
| Browser Tool Automatically |
+------------------------------+
|
v
+------------------------------+
| Browser Tool Navigates URL |
| Parses Content / Fetches |
| Images / Extracts Data |
+------------------------------+
|
v
+------------------------------+
| AgentCore Manages Session |
| and Memory Context |
+------------------------------+
|
v
+------------------------------+
| LLM Generates Summary and |
| Key Insights |
+------------------------------+
|
v
+-------------------+
| Final Response |
| Returned to User |
+-------------------+
3. Create a Controller
package com.bsmlabs.springai.agents;
import com.bsmlabs.springai.models.PromptRequest;
import org.springaicommunity.agentcore.context.AgentCoreContext;
import org.springframework.http.HttpHeaders;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
@Controller
public class SummaryController {
private final BuiltInToolsAgent builtInToolsAgent;
public SummaryController(BuiltInToolsAgent builtInToolsAgent) {
this.builtInToolsAgent = builtInToolsAgent;
}
@GetMapping("/")
public String home() {
return "summary";
}
@PostMapping("/summarize")
public String summarize(@RequestParam("url") String url, Model model) {
try {
String prompt = """
Open webpage: %s
Read the webpage content once.
Locate the primary content area.
Prioritize content inside:
- <main>
- <article>
- documentation body
- blog content
Provide:
1. Main purpose
2. Key highlights
3. Concise summary in bullet points
Ignore:
- navigation
- menus
- footer
- ads
- banners
- related links
Extract only meaningful content.
Return only final answer.
Generate concise HTML summary using:
<h3>, <p>, <ul>, <li>
Return only HTML.
""".formatted(url);
String response = builtInToolsAgent.chat(
new PromptRequest(prompt),
new AgentCoreContext(new HttpHeaders())
);
model.addAttribute("summary", response);
} catch (Exception e) {
model.addAttribute("summary",
"Error occurred: " + e.getMessage());
}
return "summary";
}
}
I am a Senior Technical Architect from India with over 18 years of experience in Java, Spring, microservices, and AWS. I am passionate about crafting scalable solutions and contributing to open-source projects such as Spring, Arconia, and OpenRewrite.
I am a Senior Technical Architect from India with over 18 years of experience in Java, Spring, microservices, and AWS. I am passionate about crafting scalable solutions and contributing to open-source projects such as Spring, Arconia, and OpenRewrite.
Towards an understanding of sustainable software development, written by and for the friends of OpenJDK
Standards Over Lock-In: Modernizing Java with Jakarta EE 11 on Azul Payara 7
Learn how to get your Java applications to cloud-native, AI-ready infrastructure without a costly rewrite or vendor lock-in. Join the engineers behind Azul Payara 7 on July 9.
Cut Code Review Time & Bugs in Half. Instantly.
Supercharge your team to ship faster with the most advanced AI code reviews.
Do you want your ad here?
Contact us to get your ad seen by thousands of users every day!
Comments (0)
No comments yet. Be the first.