代码

cookbook/models/cerebras/basic_storage.py
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?")

用法

1

创建虚拟环境

打开 Terminal 并创建一个 python 虚拟环境。

python3 -m venv .venv
source .venv/bin/activate
2

设置您的 API 密钥

export CEREBRAS_API_KEY=xxx
3

安装库

pip install -U duckduckgo-search cerebras-cloud-sdk agno
4

启动您的 Postgres 服务器

确保您的 Postgres 服务器正在运行,并且可以从 db_url 中使用的连接字符串进行访问。

5

运行 Agent

python cookbook/models/cerebras/basic_storage.py