> ## Documentation Index
> Fetch the complete documentation index at: https://agno-v2.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Share Memory and History Between Agents

> Two agents sharing both conversation history and user memory through a common database, user ID, and session ID.

```python share_memory_and_history_between_agents.py theme={null}
"""
Share Memory and History Between Agents
=======================================

This example shows two agents sharing both conversation history and user memory
through a common database, user ID, and session ID.
"""

from uuid import uuid4

from agno.agent import Agent
from agno.db.sqlite import SqliteDb
from agno.models.openai.chat import OpenAIChat

# ---------------------------------------------------------------------------
# Setup
# ---------------------------------------------------------------------------
db = SqliteDb(db_file="tmp/agent_sessions.db")

# ---------------------------------------------------------------------------
# Create Agents
# ---------------------------------------------------------------------------
agent_1 = Agent(
    model=OpenAIChat(id="gpt-5.6-luna"),
    instructions="You are really friendly and helpful.",
    db=db,
    add_history_to_context=True,
    update_memory_on_run=True,
)

agent_2 = Agent(
    model=OpenAIChat(id="gpt-5.6-luna"),
    instructions="You are really grumpy and mean.",
    db=db,
    add_history_to_context=True,
    update_memory_on_run=True,
)

# ---------------------------------------------------------------------------
# Run Agents
# ---------------------------------------------------------------------------
if __name__ == "__main__":
    session_id = str(uuid4())
    user_id = "john_doe@example.com"

    agent_1.print_response(
        "Hi! My name is John Doe.", session_id=session_id, user_id=user_id
    )

    agent_2.print_response("What is my name?", session_id=session_id, user_id=user_id)

    agent_2.print_response(
        "I like to hike in the mountains on weekends.",
        session_id=session_id,
        user_id=user_id,
    )

    agent_1.print_response(
        "What are my hobbies?", session_id=session_id, user_id=user_id
    )

    agent_1.print_response(
        "What have we been discussing? Give me bullet points.",
        session_id=session_id,
        user_id=user_id,
    )
```

## Run the Example

<Snippet file="create-venv-step.mdx" />

**1. Install dependencies**

```bash theme={null}
uv pip install -U agno openai sqlalchemy
```

**2. Export your OpenAI API key**

```bash Mac/Linux theme={null}
export OPENAI_API_KEY="your_openai_api_key_here"
```

```bash Windows theme={null}
$Env:OPENAI_API_KEY="your_openai_api_key_here"
```

**3. Run the example**

Save the code above as `share_memory_and_history_between_agents.py`, then run:

```bash theme={null}
python share_memory_and_history_between_agents.py
```

Full source: [cookbook/11\_memory/07\_share\_memory\_and\_history\_between\_agents.py](https://github.com/agno-agi/agno/blob/v3.0.4/cookbook/11_memory/07_share_memory_and_history_between_agents.py)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.