Amazon Bedrock AgentCore Browser Tools
This notebook demonstrates how to use the Amazon Bedrock AgentCore Browser tools with LlamaIndex. The toolkit provides a managed Chrome browser for web automation, content extraction, and human-in-the-loop oversight via live view URLs.
Prerequisites
Section titled “Prerequisites”- An AWS account with Amazon Bedrock AgentCore access
- Configured AWS credentials (via
~/.aws/credentials, environment variables, or IAM role) - Required IAM permissions:
bedrock-agentcore:InvokeBrowser - Playwright is installed automatically as a dependency of the toolkit
Install Dependencies
Section titled “Install Dependencies”%pip install -q llama-index llama-index-tools-aws-bedrock-agentcore llama-index-llms-bedrock-converseCreate an AgentCoreBrowserToolSpec instance. A browser session is started lazily on first navigation.
from llama_index.tools.aws_bedrock_agentcore import AgentCoreBrowserToolSpec
tool_spec = AgentCoreBrowserToolSpec(region="us-west-2")tools = tool_spec.to_tool_list()
print(f"Available tools: {[t.metadata.name for t in tools]}")Direct Tool Usage
Section titled “Direct Tool Usage”You can call the tool spec methods directly without an agent. Since Jupyter runs inside an asyncio event loop, use the async methods (prefixed with a).
Navigate and Extract Content
Section titled “Navigate and Extract Content”# Navigate to a page (use async methods inside Jupyter's event loop)result = await tool_spec.anavigate_browser("https://example.com")print(result)
# Get current page inforesult = await tool_spec.acurrent_webpage()print(result)# Extract text from a specific elementresult = await tool_spec.aextract_text(selector="h1")print(f"Page heading: {result}")Links and Elements
Section titled “Links and Elements”# Extract all hyperlinksresult = await tool_spec.aextract_hyperlinks()print("Hyperlinks:")print(result)
# Get elements matching a CSS selectorresult = await tool_spec.aget_elements("p")print("\nParagraph elements:")print(result)Live View URL
Section titled “Live View URL”Generate a presigned URL that lets a human observe the browser session in real time. This is useful for oversight and debugging.
live_url = await tool_spec.agenerate_live_view_url()print(f"Live view URL (expires in 5 minutes):\n{live_url}")Human-in-the-Loop Control
Section titled “Human-in-the-Loop Control”Use take_control() to pause automation and let a human interact with the browser via the live view URL. Call release_control() to hand control back to the agent.
# Pause automation for human interactionresult = await tool_spec.atake_control()print(result)
# ... human interacts via the live view URL ...
# Resume automationresult = await tool_spec.arelease_control()print(result)Agent Integration
Section titled “Agent Integration”Combine the browser tools with a FunctionAgent and BedrockConverse LLM to let the agent autonomously browse the web.
from llama_index.llms.bedrock_converse import BedrockConversefrom llama_index.core.agent.workflow import FunctionAgent
llm = BedrockConverse(model="us.anthropic.claude-sonnet-4-20250514-v1:0")
agent = FunctionAgent( tools=tools, llm=llm,)Web Scraping Task
Section titled “Web Scraping Task”Ask the agent to visit Hacker News and summarize the top posts.
response = await agent.run( "Go to https://news.ycombinator.com/ and tell me the titles of the top 5 posts.")print(str(response))Content Extraction Task
Section titled “Content Extraction Task”Ask the agent to visit a page and extract specific information.
response = await agent.run( "Go to https://example.com and extract the page heading and all hyperlinks on the page.")print(str(response))Cleanup
Section titled “Cleanup”Always clean up browser sessions when done to release resources.
await tool_spec.cleanup()print("Browser sessions cleaned up.")