This content originally appeared on DEV Community and was authored by Atsushi Suzuki
This summer, I barely had any time or energy to explore new technologies due to internal troubles at work and a family member being hospitalized. But by mid-September, I finally got some breathing room—so I decided to dive into Amazon Bedrock AgentCore, which had been generating buzz since July.
AgentCore is a suite of services designed for production-grade AI agent operations. Its core execution platform, AgentCore Runtime, quickly caught attention for being extremely easy to deploy.
Introducing Amazon Bedrock AgentCore: Securely deploy and operate AI agents at any scale (preview)
Since I had the chance, I also tried combining the AgentCore Browser, a managed browser for agents, to experiment with browser automation.
Amazon Bedrock AgentCore Browser Tool
What I Built
I created an agent with Strands Agents, deployed it on AgentCore Runtime, and connected it to the AgentCore Browser through Browser Use.
The goal: when asked something like
“How can I create a lifecycle policy for an S3 bucket?”,
the agent should navigate through official Amazon S3 documentation pages, extract key information, and generate an answer.
Prerequisites
- Python 3.11+
- AWS account with configured credentials
- Region:
us-west-2
- Unfortunately, AgentCore is not yet available in
ap-northeast-1
- Unfortunately, AgentCore is not yet available in
- Access to the Claude Sonnet 4 base model
- I used
us.anthropic.claude-sonnet-4-20250514-v1:0
- I used
Code Overview
Here are the main points of the implementation.
The full source code is available on GitHub:
Project Structure
Since there’s only one browser tool, I kept it simple:
src/
├── agents/
│ └── main_agent.py # Main agent
├── runtime/
│ └── agentcore_app.py # Integration with AgentCore Runtime
└── tools/
└── browser_tool.py # Browser automation logic
Implementing the Main Agent
The agent is built using Strands Agents.
It uses Claude Sonnet 4 as the model and the browse_url_tool
for browser interaction.
def create_agent():
"""Create AWS Docs search agent"""
model = BedrockModel(
model_id='us.anthropic.claude-sonnet-4-20250514-v1:0',
params={
"max_tokens": 2048,
"temperature": 0.3,
"top_p": 0.8
},
region='us-west-2',
read_timeout=600,
)
agent = Agent(
name="aws_docs_agent",
model=model,
tools=[browse_url_tool],
system_prompt=SYSTEM_PROMPT
)
return agent
Connecting to AgentCore Runtime
Integrating with AgentCore Runtime is surprisingly simple.
Just use the @app.entrypoint
decorator to expose an endpoint that accepts requests.
app = BedrockAgentCoreApp()
@app.entrypoint
async def invoke(payload: Dict[str, Any], context) -> Dict[str, Any]:
try:
prompt = payload.get("prompt", "")
agent = create_agent()
result = agent(prompt)
return {
"result": str(result),
"status": "success"
}
except Exception as e:
return {
"error": f"Error: {str(e)}",
"status": "error"
}
Browser Automation Logic
This is the key part.
It launches AgentCore Browser and controls it from Browser Use via Chrome DevTools Protocol (CDP).
- Start an AgentCore Browser session
- Get the CDP WebSocket URL
- Pass it to Browser Use
- Provide proper authentication headers
async def execute_browser_task(instruction: str, starting_url: str = "https://docs.aws.amazon.com") -> str:
client = BrowserClient(region=region)
try:
client.start()
ws_url, headers = client.generate_ws_headers()
browser_profile = BrowserProfile(
headers=headers,
timeout=180000,
)
browser_session = BrowserSession(
cdp_url=ws_url,
browser_profile=browser_profile,
keep_alive=True
)
await browser_session.start()
browser_use_agent = BrowserUseAgent(
task=instruction,
llm=bedrock_chat,
browser_session=browser_session,
)
result = await browser_use_agent.run()
return result
finally:
if browser_session:
await browser_session.close()
client.stop()
Important
Without pinning the version ofbrowser-use
, I ran into WebSocket 403 errors.
Be sure to specify it in yourrequirements.txt
:browser-use<0.3.3
Deploying to AgentCore Runtime
Create a virtual environment:
python -m venv venv
source venv/bin/activate
Run the initial setup (this creates IAM roles, an Amazon Elastic Container Registry repo, etc.):
agentcore configure --entrypoint src/runtime/agentcore_app.py --region us-west-2
You’ll need to manually attach this policy to the AmazonBedrockAgentCoreSDKRuntime-us-west-2-~
IAM role created by agentcore configure
so it can use AgentCore Browser:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "BrowserAccess",
"Effect": "Allow",
"Action": [
"bedrock-agentcore:StartBrowserSession",
"bedrock-agentcore:StopBrowserSession",
"bedrock-agentcore:ConnectBrowserAutomationStream",
"bedrock-agentcore:ConnectBrowserLiveViewStream",
"bedrock-agentcore:ListBrowserSessions",
"bedrock-agentcore:GetBrowserSession",
"bedrock-agentcore:ListBrowsers",
"bedrock-agentcore:GetBrowser"
],
"Resource": "*"
}
]
}
Then deploy:
agentcore launch
For redeployments:
agentcore launch --auto-update-on-conflict
Execution Result
After deployment, I tested it locally:
agentcore invoke '{"prompt": "How can I create a lifecycle policy for an S3 bucket?"}'
It took about 10 minutes (long), but the response was a fully detailed explanation of how to set up Amazon S3 lifecycle policies—complete with CLI, Console, SDK, and XML/JSON examples.
I could also see the Live View of browser operations in the AgentCore Browser console:
References
- amazon-bedrock-agentcore-samples
- Strands Agents
- 5分で AI エージェントをデプロイ・ホスティングする – Amazon Bedrock AgentCore Runtime
- [Amazon Bedrock AgentCore] AgentCore Browser をAIエージェントで操作してみた
This content originally appeared on DEV Community and was authored by Atsushi Suzuki