DB
Store Nebius agent sessions in Postgres and carry history across a follow-up question.
"""Run `uv pip install ddgs sqlalchemy cerebras_cloud_sdk` to install dependencies."""
from agno.agent import Agent
from agno.db.postgres import PostgresDb
from agno.models.nebius import Nebius
from agno.tools.websearch import WebSearchTools
# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------
# Setup the database
db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai"
db = PostgresDb(db_url=db_url)
agent = Agent(
model=Nebius(),
db=db,
tools=[WebSearchTools()],
add_history_to_context=True,
)
agent.print_response("How many people live in Canada?")
agent.print_response("What is their national anthem called?")
# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------
if __name__ == "__main__":
passRun the Example
Set up your virtual environment
uv venv --python 3.12
source .venv/bin/activateInstall dependencies
uv pip install -U agno "psycopg[binary]" ddgs openai sqlalchemyExport your Nebius API key
export NEBIUS_API_KEY="your_nebius_api_key_here"Run PgVector
docker run -d \
-e POSTGRES_DB=ai \
-e POSTGRES_USER=ai \
-e POSTGRES_PASSWORD=ai \
-e PGDATA=/var/lib/postgresql \
-v pgvolume:/var/lib/postgresql \
-p 5532:5432 \
--name pgvector \
agnohq/pgvector:18Select an enabled Token Factory model
Copy a model ID available to your account for https://api.tokenfactory.nebius.com/v1 from the Token Factory console. For knowledge and tool examples it must support function calling; for structured output it must support JSON Schema. Confirm the endpoint and model's access before running.
export NEBIUS_MODEL_ID="your-enabled-model-id"Replace the placeholder with your copied model ID. Add from os import environ to the saved file, then set every model construction to Nebius(id=environ["NEBIUS_MODEL_ID"]). Keep any additional model options. The adapter's default ID does not establish which models your account can access. A dedicated deployment must instead use the model and endpoint supplied for that deployment, with an explicit base_url.
Run the example
Save the code above as db.py, then run:
python db.pyFull source: cookbook/90_models/nebius/db.py