# DynamoDB for Team (/database/providers/dynamodb/usage/dynamodb-for-team)



`DynamoDb` stores a Team's sessions and run history in DynamoDB.

## Usage [#usage]

Start in a [virtual environment](/sdk/setup) and set the model key before running the example.

## Set OpenAI Key [#set-openai-key]

Set your `OPENAI_API_KEY` as an environment variable. You can get one [from OpenAI](https://platform.openai.com/account/api-keys).

<CodeBlockTabs defaultValue="Mac">
  <CodeBlockTabsList>
    <CodeBlockTabsTrigger value="Mac">
      Mac
    </CodeBlockTabsTrigger>

    <CodeBlockTabsTrigger value="Windows PowerShell">
      Windows PowerShell
    </CodeBlockTabsTrigger>
  </CodeBlockTabsList>

  <CodeBlockTab value="Mac">
    ```bash
    export OPENAI_API_KEY=sk-***
    ```
  </CodeBlockTab>

  <CodeBlockTab value="Windows PowerShell">
    ```powershell
    $env:OPENAI_API_KEY = "your-openai-api-key"
    ```
  </CodeBlockTab>
</CodeBlockTabs>

Pass a configured DynamoDB client as `db_client`. Otherwise, set the `AWS_REGION`, `AWS_ACCESS_KEY_ID`, and `AWS_SECRET_ACCESS_KEY` environment variables or pass `region_name`, `aws_access_key_id`, and `aws_secret_access_key` directly.

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

Install dependencies:

```shell
uv pip install agno boto3 openai ddgs
```

```python title="dynamo_for_team.py"
from typing import List

from agno.agent import Agent
from agno.db.dynamo import DynamoDb
from agno.models.openai import OpenAIResponses
from agno.team import Team
from agno.tools.hackernews import HackerNewsTools
from agno.tools.websearch import WebSearchTools
from pydantic import BaseModel

db = DynamoDb()

class Article(BaseModel):
    title: str
    summary: str
    reference_links: List[str]

hn_researcher = Agent(
    name="HackerNews Researcher",
    model=OpenAIResponses(id="gpt-5.2"),
    role="Gets top stories from HackerNews.",
    tools=[HackerNewsTools()],
)

web_searcher = Agent(
    name="Web Searcher",
    model=OpenAIResponses(id="gpt-5.2"),
    role="Searches the web for information on a topic",
    tools=[WebSearchTools()],
    add_datetime_to_context=True,
)

hn_team = Team(
    name="HackerNews Team",
    model=OpenAIResponses(id="gpt-5.2"),
    members=[hn_researcher, web_searcher],
    db=db,
    instructions=[
        "First, search HackerNews for what the user is asking about.",
        "Then, ask the web searcher to search for each story to get more information.",
        "Finally, provide a thoughtful and engaging summary.",
    ],
    output_schema=Article,
    markdown=True,
    show_members_responses=True,
)

hn_team.print_response("Write an article about the top 2 stories on HackerNews")
```

## Parameters [#parameters]

| Parameter               | Type            | Default | Description                                                                                                                  |
| ----------------------- | --------------- | ------- | ---------------------------------------------------------------------------------------------------------------------------- |
| `id`                    | `Optional[str]` | -       | Database ID. Derived deterministically from explicit client or constructor region/key values when omitted.                   |
| `db_client`             | `Optional[Any]` | -       | The DynamoDB client to use.                                                                                                  |
| `region_name`           | `Optional[str]` | -       | AWS region name.                                                                                                             |
| `aws_access_key_id`     | `Optional[str]` | -       | AWS access key ID.                                                                                                           |
| `aws_secret_access_key` | `Optional[str]` | -       | AWS secret access key.                                                                                                       |
| `session_table`         | `Optional[str]` | -       | The name of the session table.                                                                                               |
| `runs_table`            | `Optional[str]` | `None`  | Storage name for individual runs. Defaults to `agno_runs`, or `<session_table>_runs` when a custom session name is supplied. |
| `memory_table`          | `Optional[str]` | -       | The name of the memory table.                                                                                                |
| `metrics_table`         | `Optional[str]` | -       | The name of the metrics table.                                                                                               |
| `eval_table`            | `Optional[str]` | -       | The name of the eval table.                                                                                                  |
| `knowledge_table`       | `Optional[str]` | -       | The name of the knowledge table.                                                                                             |
| `traces_table`          | `Optional[str]` | -       | The name of the traces table.                                                                                                |
| `spans_table`           | `Optional[str]` | -       | The name of the spans table.                                                                                                 |

## Run the Example [#run-the-example]

Save the code as `dynamo_for_team.py`, complete the prerequisites above, then run:

```bash
python dynamo_for_team.py
```
