decision_log_always.py
"""
Decision Logs: ALWAYS Mode (Automatic Logging)
===============================================
This example demonstrates automatic decision logging where
tool calls are automatically recorded as decisions.
In ALWAYS mode, DecisionLogStore extracts decisions from:
- Tool calls (which tool was used)
- Other significant choices the agent makes
Run:
.venvs/demo/bin/python cookbook/08_learning/09_decision_logs/02_decision_log_always.py
"""
from agno.agent import Agent
from agno.db.postgres import PostgresDb
from agno.learn import DecisionLogConfig, LearningMachine, LearningMode
from agno.models.openai import OpenAIResponses
from agno.tools.duckduckgo import DuckDuckGoTools
# ---------------------------------------------------------------------------
# Setup
# ---------------------------------------------------------------------------
# Database connection
db = PostgresDb(db_url="postgresql+psycopg://ai:ai@localhost:5532/ai")
# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------
# Create an agent with automatic decision logging
# ALWAYS mode: Tool calls are automatically logged as decisions
agent = Agent(
id="auto-decision-logger",
name="Auto Decision Logger",
model=OpenAIResponses(id="gpt-5.5"),
db=db,
learning=LearningMachine(
decision_log=DecisionLogConfig(
mode=LearningMode.ALWAYS,
),
),
tools=[DuckDuckGoTools()],
instructions=[
"You are a helpful research assistant.",
"Use web search to find current information when needed.",
],
markdown=True,
)
# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------
if __name__ == "__main__":
# Test: Agent uses a tool (will be logged automatically)
print("=== Test: Agent uses web search ===\n")
agent.print_response(
"What are the latest developments in AI agents?",
session_id="session-002",
)
# View auto-logged decisions
print("\n=== Auto-Logged Decisions ===\n")
decision_store = agent.learning_machine.decision_log_store
if decision_store:
decision_store.print(agent_id="auto-decision-logger", limit=10)
Run the Example
1
Set up your virtual environment
uv venv --python 3.12
source .venv/bin/activate
uv venv --python 3.12
.venv\Scripts\activate
2
Install dependencies
uv pip install -U agno "psycopg[binary]" ddgs openai sqlalchemy
3
Export your OpenAI API key
export OPENAI_API_KEY="your_openai_api_key_here"
$Env:OPENAI_API_KEY="your_openai_api_key_here"
4
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:18
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:18
5
Run the example
Save the code above as
decision_log_always.py, then run:python decision_log_always.py