dynamo_for_agent.py
"""Use DynamoDb as the database for an agent.
Set the following environment variables to connect to your DynamoDb instance:
- AWS_ACCESS_KEY_ID
- AWS_SECRET_ACCESS_KEY
- AWS_REGION
Run `uv pip install boto3` to install dependencies."""
from agno.agent import Agent
from agno.db import DynamoDb
# ---------------------------------------------------------------------------
# Setup
# ---------------------------------------------------------------------------
db = DynamoDb()
# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------
agent = Agent(
db=db,
name="DynamoDB Agent",
description="An agent that uses DynamoDB as a database",
add_history_to_context=True,
)
# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------
if __name__ == "__main__":
# The Agent sessions and runs will now be stored in DynamoDB
agent.print_response("How many people live in Canada?")
agent.print_response("What is their national anthem called?")
Run the Example
1
Set up your virtual environment
uv venv --python 3.12
source .venv/bin/activate
uv venv --python 3.12
.venv\Scripts\activate
2
Install dependencies
uv pip install -U agno boto3 openai
3
Export environment variables
export AWS_ACCESS_KEY_ID="your_aws_access_key_id_here"
export AWS_REGION="your_aws_region_here"
export AWS_SECRET_ACCESS_KEY="your_aws_secret_access_key_here"
export OPENAI_API_KEY="your_openai_api_key_here"
$Env:AWS_ACCESS_KEY_ID="your_aws_access_key_id_here"
$Env:AWS_REGION="your_aws_region_here"
$Env:AWS_SECRET_ACCESS_KEY="your_aws_secret_access_key_here"
$Env:OPENAI_API_KEY="your_openai_api_key_here"
4
Run the example
Save the code above as
dynamo_for_agent.py, then run:python dynamo_for_agent.py