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

# Knowledge Tool

> Let an agent and team write new facts into a PgVector knowledge base with update_knowledge.

```python knowledge_tool.py theme={null}
"""
Knowledge Tool
=============================

Demonstrates knowledge tool.
"""

from agno.agent import Agent
from agno.knowledge.knowledge import Knowledge
from agno.team.team import Team
from agno.vectordb.pgvector import PgVector

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


db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai"

kb = Knowledge(
    vector_db=PgVector(
        table_name="documents",
        db_url=db_url,
    ),
)

agent = Agent(
    knowledge=kb,
    update_knowledge=True,
)

# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------
if __name__ == "__main__":
    agent.print_response(
        "Update your knowledge with the fact that cats and dogs are pets", markdown=True
    )

    team = Team(
        name="Knowledge Team",
        members=[agent],
        knowledge=kb,
        update_knowledge=True,
    )
    team.print_response(
        "Update your knowledge with the fact that cats don't like water", markdown=True
    )
```

## Run the Example

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

  <Step title="Install dependencies">
    ```bash theme={null}
    uv pip install -U agno openai pgvector psycopg-binary 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 `knowledge_tool.py`, then run:

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

Full source: [cookbook/91\_tools/knowledge\_tool.py](https://github.com/agno-agi/agno/blob/main/cookbook/91_tools/knowledge_tool.py)
