DynamoDB

Store agent sessions and run history in DynamoDB with DynamoDb.

DynamoDb stores Agent sessions and run history in DynamoDB.

Usage

Start in a virtual environment and set the model key before running the example.

Set OpenAI Key

Set your OPENAI_API_KEY as an environment variable. You can get one from OpenAI.

export OPENAI_API_KEY=sk-***

Install the boto3 and openai packages:

uv pip install agno boto3 openai

Pass a configured DynamoDB client as db_client, or set all three environment variables:

  • AWS_REGION: The AWS region to connect to.
  • AWS_ACCESS_KEY_ID: Your AWS access key ID.
  • AWS_SECRET_ACCESS_KEY: Your AWS secret access key.

On first use, DynamoDb creates missing tables with provisioned capacity. The client or credentials must allow table creation and read/write operations.

dynamo_for_agent.py
from agno.agent import Agent
from agno.db.dynamo import DynamoDb

db = DynamoDb()

agent = Agent(db=db)

region_name, aws_access_key_id, and aws_secret_access_key accept the same values directly.

Parameters

ParameterTypeDefaultDescription
idOptional[str]-Database ID. Derived deterministically from explicit client or constructor region/key values when omitted.
db_clientOptional[Any]-The DynamoDB client to use.
region_nameOptional[str]-AWS region name.
aws_access_key_idOptional[str]-AWS access key ID.
aws_secret_access_keyOptional[str]-AWS secret access key.
session_tableOptional[str]-The name of the session table.
runs_tableOptional[str]NoneStorage name for individual runs. Defaults to agno_runs, or <session_table>_runs when a custom session name is supplied.
memory_tableOptional[str]-The name of the memory table.
metrics_tableOptional[str]-The name of the metrics table.
eval_tableOptional[str]-The name of the eval table.
knowledge_tableOptional[str]-The name of the knowledge table.
traces_tableOptional[str]-The name of the traces table.
spans_tableOptional[str]-The name of the spans table.