Deploy LlamaIndex Agents to Bedrock AgentCore
Deploy LlamaIndex agents to Amazon Bedrock AgentCore Runtime with managed compute and memory.
Why it matters
Deploy and manage LlamaIndex agents on Amazon Bedrock AgentCore Runtime. This asset provides a managed compute platform for your AI agents, enabling them to interact with sandboxed browser environments and execute code.
Outcomes
What it gets done
Deploy LlamaIndex agents to AWS Bedrock AgentCore Runtime.
Enable agents to perform sandboxed browser automation.
Integrate agents with code execution capabilities.
Manage agent memory and session context.
Install
Add it to your toolbox
Run in your project directory:
curl -fsSL https://spark.entire.vc/get/li-tool-tools-aws-bedrock-agentcore | bash Overview
Amazon Bedrock AgentCore Runtime and Tools
A LlamaIndex runtime adapter that deploys agents to Amazon Bedrock AgentCore's managed compute, with streaming responses, persistent memory, and sandboxed browser tools. Use when deploying a working LlamaIndex agent to AWS's managed AgentCore platform instead of self-hosted infrastructure.
What it does
This module provides a runtime adapter and tools for deploying and extending LlamaIndex agents with Amazon Bedrock AgentCore, including managed compute via AgentCore Runtime, sandboxed browser automation, and code execution. The AgentCoreRuntime adapter wraps BedrockAgentCoreApp from the bedrock-agentcore SDK, exposing the required POST /invocations and GET /ping endpoints so any LlamaIndex agent can run on AgentCore's managed compute platform.
A single call, AgentCoreRuntime.serve(agent), starts a uvicorn server on port 8080 with sensible defaults. AgentCoreRuntime can also be instantiated directly with options: stream (SSE streaming, enabled by default), a required port for AgentCore deployment, and debug. Requests accept prompt, message, or input as the payload key, and can be sent non-streaming or as a streaming SSE connection. When streaming, the SSE stream emits typed events: agent_stream (token-by-token output with delta, response, and an optional thinking_delta), tool_call (before tool execution, with tool_name and tool_kwargs), tool_result (after tool execution, with tool_name and tool_output), done (the final response), and error (with a message).
The runtime also integrates with AgentCore Memory: an AgentCoreMemory instance configured with an AgentCoreMemoryContext (memory ID and actor ID) can be passed to AgentCoreRuntime.serve, and the session ID from the X-Amzn-Bedrock-AgentCore-Runtime-Session-Id header is automatically wired to it.
When to use - and when NOT to
Use it when you have a working LlamaIndex agent and want to deploy it to AWS's managed AgentCore compute platform rather than hosting your own server infrastructure, especially if you also want AgentCore's sandboxed browser automation or persistent memory across sessions. For testing without a full deployment, the adapter exposes runtime.app, a Starlette-based ASGI app usable directly with httpx.AsyncClient. Do not use it without valid AWS credentials and IAM permissions for bedrock-agentcore:* actions - the runtime is entirely dependent on AWS's AgentCore service being reachable and authorized.
Capabilities
AgentCoreRuntime.serve and the AgentCoreRuntime class deploy a LlamaIndex agent as an AgentCore-compatible service with streaming or non-streaming responses. AgentCoreMemory wires persistent, session-scoped memory into the runtime automatically from the request header. A Browser toolspec provides sandboxed browser automation tools, including navigate_browser to go to a URL and click_element to click an element by CSS selector.
How to install
pip install llama-index-tools-aws-bedrock-agentcore
Requires AWS credentials (via environment variables, an AWS CLI profile, or an IAM role), IAM permissions for bedrock-agentcore:* actions, and Python 3.9 or newer.
Who it's for
Developers who have built a LlamaIndex agent and want to deploy it to Amazon Bedrock AgentCore's managed runtime, with optional persistent memory and sandboxed browser automation, rather than operating their own agent-hosting infrastructure.
Source README
Amazon Bedrock AgentCore Runtime and Tools
This module provides a runtime adapter and tools for deploying and extending LlamaIndex agents with Amazon Bedrock AgentCore -- including managed compute via AgentCore Runtime, sandboxed browser automation, and code execution.
Prerequisites
- AWS credentials configured via environment variables, AWS CLI profile, or IAM role
- IAM permissions for
bedrock-agentcore:*actions (see the AgentCore documentation for details) - Python 3.9+
Installation
(Optional) To run the examples below, first install:
pip install llama-index llama-index-llms-bedrock-converse
Install the main tools package:
pip install llama-index-tools-aws-bedrock-agentcore
Runtime
The AgentCoreRuntime adapter deploys any LlamaIndex agent to Amazon Bedrock AgentCore Runtime -- a managed compute platform for AI agents. It wraps BedrockAgentCoreApp from the bedrock-agentcore SDK, providing the required POST /invocations and GET /ping endpoints.
Quick Start
from llama_index.llms.bedrock_converse import BedrockConverse
from llama_index.core.agent.workflow import FunctionAgent
from llama_index.tools.aws_bedrock_agentcore import AgentCoreRuntime
llm = BedrockConverse(
model="us.anthropic.claude-sonnet-4-6-v1",
region_name="us-west-2",
)
agent = FunctionAgent(llm=llm, tools=[])
### One-liner -- starts uvicorn on port 8080
AgentCoreRuntime.serve(agent)
With Options
runtime = AgentCoreRuntime(
agent=agent,
stream=True, # SSE streaming (default)
port=8080, # Required port for AgentCore deployment
debug=False,
)
runtime.run()
With AgentCore Memory
from llama_index.memory.bedrock_agentcore import (
AgentCoreMemory,
AgentCoreMemoryContext,
)
memory = AgentCoreMemory(
context=AgentCoreMemoryContext(
memory_id="your-memory-id",
actor_id="user-123",
),
region_name="us-west-2",
)
### Session ID from the X-Amzn-Bedrock-AgentCore-Runtime-Session-Id header
### is automatically wired to memory
AgentCoreRuntime.serve(agent, memory=memory)
Sending Requests
### Non-streaming
curl -X POST http://localhost:8080/invocations \
-H "Content-Type: application/json" \
-d '{"prompt": "Hello, what can you do?"}'
### Streaming (SSE)
curl -N -X POST http://localhost:8080/invocations \
-H "Content-Type: application/json" \
-d '{"prompt": "Hello, what can you do?"}'
The adapter accepts prompt, message, or input as the payload key.
Streaming Event Types
When stream=True (default), the SSE stream emits these event types:
| Event | Fields | Description |
|---|---|---|
agent_stream |
delta, response, thinking_delta? |
Token-by-token LLM output |
tool_call |
tool_name, tool_kwargs |
Before tool execution |
tool_result |
tool_name, tool_output |
After tool execution |
done |
response |
Final agent response |
error |
message |
Error during streaming |
Testing with ASGI
runtime = AgentCoreRuntime(agent=agent)
app = runtime.app # BedrockAgentCoreApp (Starlette-based)
### Use with httpx.AsyncClient for testing
Toolspecs
Browser
The AgentCore Browser toolspec provides a set of tools for interacting with web browsers in a secure sandbox environment. It enables your LlamaIndex agents to navigate websites, extract content, click elements, and more.
Included tools:
navigate_browser: Navigate to a URLclick_element: Click on an element using CSS sele
FAQ
Common questions
Discussion
Questions & comments · 0
Sign In Sign in to leave a comment.