# JSON for Team (/database/providers/json/usage/json-for-team)



`JsonDb` stores a Team's sessions and run history in local JSON files.

## 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>

Install the `openai` and `ddgs` packages:

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

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

from agno.agent import Agent
from agno.db.json import JsonDb
from agno.models.openai import OpenAIChat
from agno.team import Team
from agno.tools.hackernews import HackerNewsTools
from agno.tools.websearch import WebSearchTools
from pydantic import BaseModel

db = JsonDb(db_path="tmp/json_db")


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


hn_researcher = Agent(
    name="HackerNews Researcher",
    model=OpenAIChat("gpt-4o"),
    role="Gets top stories from HackerNews.",
    tools=[HackerNewsTools()],
)

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

hn_team = Team(
    name="HackerNews Team",
    model=OpenAIChat("gpt-4o"),
    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, summarize each story and include its reference links.",
    ],
    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 database path when omitted.                                                      |
| `db_path`         | `Optional[str]` | -       | Path to the directory where JSON files will be stored.                                                                       |
| `session_table`   | `Optional[str]` | -       | Name of the JSON file to store sessions (without .json extension).                                                           |
| `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]` | -       | Name of the JSON file to store memories.                                                                                     |
| `metrics_table`   | `Optional[str]` | -       | Name of the JSON file to store metrics.                                                                                      |
| `eval_table`      | `Optional[str]` | -       | Name of the JSON file to store evaluation runs.                                                                              |
| `knowledge_table` | `Optional[str]` | -       | Name of the JSON file to store knowledge content.                                                                            |
| `traces_table`    | `Optional[str]` | -       | Name of the JSON file to store traces.                                                                                       |
| `spans_table`     | `Optional[str]` | -       | Name of the JSON file to store spans.                                                                                        |

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

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

```bash
python json_for_team.py
```
