| Information | Details |
|---|---|
| Agent type | Synchronous |
| Agentic Framework | LlamaIndex |
| LLM model | OpenAI GPT-4o-mini |
| Components | AgentCore Runtime, Yahoo Finance Tools |
| Example complexity | Easy |
| SDK used | Amazon BedrockAgentCore Python SDK |
This example demonstrates how to integrate a LlamaIndex agent with AWS Bedrock AgentCore, enabling you to deploy a financial assistant with tool-using capabilities as a managed service.
- Python 3.10+
- uv - Fast Python package installer and resolver
- AWS account with Bedrock access
- OpenAI API key (for the model client)
# Install uv if you don't have it already
pip install uv
# Create and activate a virtual environment
uv venv
source .venv/bin/activate # On Windows: .venv\Scripts\activateuv pip install -r requirements.txtThe llama_agent_hello_world.py file contains a LlamaIndex agent with financial tools and basic math capabilities, integrated with Bedrock AgentCore:
import asyncio
from llama_index.core.agent.workflow import FunctionAgent
from llama_index.llms.openai import OpenAI
from llama_index.tools.yahoo_finance import YahooFinanceToolSpec
# Define custom function tools
def multiply(a: float, b: float) -> float:
"""Multiply two numbers and returns the product"""
return a * b
def add(a: float, b: float) -> float:
"""Add two numbers and returns the sum"""
return a + b
# Add other predefined tools
finance_tools = YahooFinanceToolSpec().to_tool_list()
finance_tools.extend([multiply, add])
# Create an agent workflow with our tools
agent = FunctionAgent(
tools=finance_tools,
llm=OpenAI(model="gpt-4o-mini"),
system_prompt="You are a helpful assistant.",
)
from bedrock_agentcore.runtime import BedrockAgentCoreApp
app = BedrockAgentCoreApp()
@app.entrypoint
async def main(payload):
# Run the agent
response = await agent.run(payload.get("prompt","What is the current stock price of AMZN?"))
print(response)
return response.response.content
# Run the agent
if __name__ == "__main__":
app.run()# Configure your agent for deployment
agentcore configure -e llama_agent_hello_world.py
# Deploy your agent with OpenAI API key
agentcore launch --env OPENAI_API_KEY=sk-...You can test your agent locally before deploying to the cloud:
# Launch locally with your OpenAI API key
agentcore launch -l --env OPENAI_API_KEY=sk-...
# Invoke the agent with a query
agentcore invoke -l '{"prompt":"Price of AMZN stock today"}'For cloud deployment, remove the -l flag:
# Deploy to cloud
agentcore launch --env OPENAI_API_KEY=sk-...
# Invoke the deployed agent
agentcore invoke '{"prompt":"Price of AMZN stock today"}'The agent will:
- Process your financial query
- Use the Yahoo Finance tools to fetch real-time stock data
- Provide a response with the requested financial information
- Perform calculations if needed using the math tools
This agent uses LlamaIndex's agent framework to create a financial assistant that can:
- Process natural language queries about stocks and financial data
- Access real-time stock information through Yahoo Finance tools
- Perform basic mathematical operations when needed
- Provide comprehensive responses based on the data
The agent is wrapped with the Bedrock AgentCore framework, which handles:
- Deployment to AWS
- Scaling and management
- Request/response handling
- Environment variable management