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

# Entity Memory: The Four Tools

> Entity memory is the agent's knowledge about the WORLD - the people, projects, companies and systems around the user - as opposed to user memory, which is about the user themselves.

```python entity_memory.py theme={null}
"""
Entity Memory: The Four Tools
=============================
Entity memory is the agent's knowledge about the WORLD - the people,
projects, companies and systems around the user - as opposed to user
memory, which is about the user themselves.

It is AGENTIC-only: the agent records through four tools (remember_about,
link_entities, search_entities, forget), and the store does the librarian
work - ids are slugified from names, "Sarah Chen" and "sarah chen" resolve
to one person, and a correcting fact retires the stale one (supersession).

Deep dives: cookbook/08_learning/04_entity_memory/

Run:
    .venvs/demo/bin/python cookbook/08_learning/01_basics/5_entity_memory.py
"""

from uuid import uuid4

from agno.agent import Agent
from agno.db.postgres import PostgresDb
from agno.learn import EntityMemoryConfig, LearningMachine
from agno.models.openai import OpenAIResponses

# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------

db = PostgresDb(db_url="postgresql+psycopg://ai:ai@localhost:5532/ai")

# Fresh per-run namespace so the demo starts clean on every execution.
NAMESPACE = f"basics_{uuid4().hex[:6]}"

agent = Agent(
    model=OpenAIResponses(id="gpt-5.5"),
    db=db,
    instructions="You are a sales assistant. Acknowledge notes briefly.",
    learning=LearningMachine(
        entity_memory=EntityMemoryConfig(namespace=NAMESPACE),
    ),
    markdown=True,
)

# ---------------------------------------------------------------------------
# Run Demo
# ---------------------------------------------------------------------------

if __name__ == "__main__":
    agent.print_response(
        "Note on Acme Corp: fintech startup in SF, about 50 people. "
        "Jane Smith is their CTO.",
        session_id="s1",
        stream=True,
    )

    # A fresh session: the entity directory plus relevance recall carry the
    # context - no tool call needed to answer.
    agent.print_response(
        "What do we know about Acme?",
        session_id="s2",
        stream=True,
    )
```

## Run the Example

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

  <Step title="Install dependencies">
    ```bash theme={null}
    uv pip install -U agno "psycopg[binary]" openai sqlalchemy
    ```
  </Step>

  <Step title="Export your OpenAI API key">
    <CodeGroup>
      ```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"
      ```
    </CodeGroup>
  </Step>

  <Snippet file="run-pgvector-step.mdx" />

  <Step title="Run the example">
    Save the code above as `entity_memory.py`, then run:

    ```bash theme={null}
    python entity_memory.py
    ```
  </Step>
</Steps>

Full source: [cookbook/08\_learning/01\_basics/5\_entity\_memory.py](https://github.com/agno-agi/agno/blob/v3.0.4/cookbook/08_learning/01_basics/5_entity_memory.py)
