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

# 带有存储的 Agent

## 代码

```python cookbook/models/cerebras/basic_storage.py theme={null}
from agno.agent import Agent
from agno.models.cerebras import Cerebras
from agno.storage.postgres import PostgresStorage
from agno.tools.duckduckgo import DuckDuckGoTools

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

agent = Agent(
    model=Cerebras(id="llama-4-scout-17b-16e-instruct"),
    storage=PostgresStorage(table_name="agent_sessions", db_url=db_url),
    tools=[DuckDuckGoTools()],
    add_history_to_messages=True,
)

agent.print_response("How many people live in Canada?")
agent.print_response("What is their national anthem called?")
```

## 用法

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

  <Step title="设置您的 API 密钥">
    ```bash theme={null}
    export CEREBRAS_API_KEY=xxx
    ```
  </Step>

  <Step title="安装库">
    ```bash theme={null}
    pip install -U duckduckgo-search cerebras-cloud-sdk agno
    ```
  </Step>

  <Step title="启动您的 Postgres 服务器">
    确保您的 Postgres 服务器正在运行，并且可以从 `db_url` 中使用的连接字符串进行访问。
  </Step>

  <Step title="运行 Agent">
    <CodeGroup>
      ```bash Mac theme={null}
      python cookbook/models/cerebras/basic_storage.py
      ```

      ```bash Windows theme={null}
      python cookbook/models/cerebras/basic_storage.py
      ```
    </CodeGroup>
  </Step>
</Steps>
