llama-index tools AWS Bedrock AgentCore integration
Project description
AWS Bedrock AgentCore Tools
This module provides tools for interacting with AWS Bedrock AgentCore's browser and code interpreter sandbox tools.
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
Toolspecs
Browser
The Bedrock 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 selectorsextract_text: Extract all text from the current webpageextract_hyperlinks: Extract all hyperlinks from the current webpageget_elements: Get elements matching a CSS selectornavigate_back: Navigate to the previous pagecurrent_webpage: Get information about the current webpagegenerate_live_view_url: Generate a presigned URL for human oversight of a browser sessiontake_control: Take manual control of a browser session (disables automation)release_control: Release manual control (re-enables automation)
Lifecycle methods available for programmatic use (not exposed as agent tools):
list_browsers,create_browser,delete_browser,get_browser
You can optionally pass a custom identifier for VPC-enabled browser resources:
tool_spec = AgentCoreBrowserToolSpec(
region="us-west-2",
identifier="my-custom-browser-id",
)
Example usage:
import asyncio
from llama_index.llms.bedrock_converse import BedrockConverse
from llama_index.tools.aws_bedrock_agentcore import AgentCoreBrowserToolSpec
from llama_index.core.agent.workflow import FunctionAgent
import nest_asyncio
nest_asyncio.apply() # In case of existing loop (ex. in JupyterLab)
async def main():
tool_spec = AgentCoreBrowserToolSpec(region="us-west-2")
tools = tool_spec.to_tool_list()
llm = BedrockConverse(
model="us.anthropic.claude-3-7-sonnet-20250219-v1:0",
region_name="us-west-2",
)
agent = FunctionAgent(
tools=tools,
llm=llm,
)
task = "Go to https://news.ycombinator.com/ and tell me the titles of the top 5 posts."
response = await agent.run(task)
print(str(response))
await tool_spec.cleanup()
if __name__ == "__main__":
asyncio.run(main())
Code Interpreter
The Bedrock AgentCore code_interpreter toolspec provides a set of tools interacting with a secure code interpreter sandbox environment. It enables your LlamaIndex agents to execute code, run shell commands, manage files, and perform computational task.
Included tools:
execute_code: Run code in various languages (primarily Python)execute_command: Run shell commandsread_files: Read content of files in the environmentlist_files: List files in directoriesdelete_files: Remove files from the environmentwrite_files: Create or update filesstart_command: Start long-running commands asynchronouslyget_task: Check status of async tasksstop_task: Stop running tasksupload_file: Upload a file with an optional semantic descriptionupload_files: Upload multiple files at onceinstall_packages: Install Python packages via pipdownload_file: Download a file from the sandboxdownload_files: Download multiple files from the sandboxclear_context: Clear all variable state in the Python execution context
Lifecycle methods available for programmatic use (not exposed as agent tools):
list_code_interpreters,create_code_interpreter,delete_code_interpreter,get_code_interpreter
You can optionally pass a custom identifier for VPC-enabled code interpreter resources:
tool_spec = AgentCoreCodeInterpreterToolSpec(
region="us-west-2",
identifier="my-custom-interpreter-id",
)
Example usage:
import asyncio
from llama_index.llms.bedrock_converse import BedrockConverse
from llama_index.tools.aws_bedrock_agentcore import (
AgentCoreCodeInterpreterToolSpec,
)
from llama_index.core.agent.workflow import FunctionAgent
import nest_asyncio
nest_asyncio.apply() # In case of existing loop (ex. in JupyterLab)
async def main():
tool_spec = AgentCoreCodeInterpreterToolSpec(region="us-west-2")
tools = tool_spec.to_tool_list()
llm = BedrockConverse(
model="us.anthropic.claude-3-7-sonnet-20250219-v1:0",
region_name="us-west-2",
)
agent = FunctionAgent(
tools=tools,
llm=llm,
)
code_task = "Write a Python function that calculates the factorial of a number and test it."
code_response = await agent.run(code_task)
print(str(code_response))
command_task = "Use terminal CLI commands to: 1) Show the environment's Python version. 2) Show me the list of Python package currently installed in the environment."
command_response = await agent.run(command_task)
print(str(command_response))
await tool_spec.cleanup()
if __name__ == "__main__":
asyncio.run(main())
Example Notebooks
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file llama_index_tools_aws_bedrock_agentcore-0.2.0-py3-none-any.whl.
File metadata
- Download URL: llama_index_tools_aws_bedrock_agentcore-0.2.0-py3-none-any.whl
- Upload date:
- Size: 20.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.8 {"installer":{"name":"uv","version":"0.10.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d7e4818731a958926cdc0e5f5469173c48d74a7ab0364c5379fdfeac0f0158d1
|
|
| MD5 |
ec35a6e56bbdf040d166e70f0de83df9
|
|
| BLAKE2b-256 |
a298d1b583c4cf563f767906940db3058e4c32dbbbbc018881335aa91361632f
|