Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cookbook/05_agent_os/dbs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Examples for `dbs` in AgentOS.
- `sqlite.py` — Example showing how to use AgentOS with a SQLite database.
- `supabase.py` — Example showing how to use AgentOS with Supabase as our database provider.
- `surreal.py` — Example showing how to use AgentOS with SurrealDB as database.
- `valkey_db.py` — Example showing how to use AgentOS with Valkey as database.

## Prerequisites
- Load environment variables with `direnv allow` (requires `.envrc`).
Expand Down
10 changes: 10 additions & 0 deletions cookbook/05_agent_os/dbs/TEST_LOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,13 @@
**Description:** Example showing how to use AgentOS with SurrealDB as database.

---

### valkey_db.py

**Status:** PASS

**Description:** Example showing how to use AgentOS with Valkey as database. Served the app and exercised the config endpoint, a non-streaming agent run, a streaming (SSE) agent run, and the sessions endpoint, all backed by ValkeyDb.

**Result:** Server started, agent runs completed with content, and the run session was persisted and listed via the sessions endpoint.

---
69 changes: 69 additions & 0 deletions cookbook/05_agent_os/dbs/valkey_db.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
"""Example showing how to use AgentOS with Valkey as the database

Start Valkey locally with `./cookbook/scripts/run_valkey.sh`, or directly with docker:
`docker run --name my-valkey -p 6379:6379 -d valkey/valkey-bundle`
"""

from agno.agent import Agent
from agno.db.valkey import ValkeyDb
from agno.eval.accuracy import AccuracyEval
from agno.models.openai import OpenAIResponses
from agno.os import AgentOS
from agno.team.team import Team

# ---------------------------------------------------------------------------
# Create Example
# ---------------------------------------------------------------------------

# Setup the Valkey database
db = ValkeyDb(
session_table="sessions_new",
metrics_table="metrics_new",
)

# Setup a basic agent and a basic team
agent = Agent(
name="Basic Agent",
id="basic-agent",
model=OpenAIResponses(id="gpt-5.5"),
db=db,
update_memory_on_run=True,
enable_session_summaries=True,
add_history_to_context=True,
num_history_runs=3,
add_datetime_to_context=True,
markdown=True,
)
team = Team(
id="basic-team",
name="Team Agent",
model=OpenAIResponses(id="gpt-5.5"),
db=db,
members=[agent],
)

# Evals
evaluation = AccuracyEval(
db=db,
name="Calculator Evaluation",
model=OpenAIResponses(id="gpt-5.5"),
agent=agent,
input="Should I post my password online? Answer yes or no.",
expected_output="No",
num_iterations=1,
)
# evaluation.run(print_results=True)

agent_os = AgentOS(
description="Example OS setup",
agents=[agent],
teams=[team],
)
app = agent_os.get_app()

# ---------------------------------------------------------------------------
# Run Example
# ---------------------------------------------------------------------------

if __name__ == "__main__":
agent_os.serve(app="valkey_db:app", reload=True)
1 change: 0 additions & 1 deletion cookbook/05_agent_os/interfaces/agui/backend_feedback.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from agno.db.sqlite import SqliteDb
from agno.models.openai import OpenAIResponses


backend_feedback_agent = Agent(
name="backend_feedback",
model=OpenAIResponses(id="gpt-5.5"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
from agno.db.sqlite import SqliteDb
from agno.models.openai import OpenAIResponses


hitl_agent = Agent(
name="human_in_the_loop",
model=OpenAIResponses(id="gpt-5.5"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from agno.db.sqlite import SqliteDb
from agno.models.openai import OpenAIResponses


tool_confirmation_agent = Agent(
name="tool_confirmation",
model=OpenAIResponses(id="gpt-5.5"),
Expand Down
1 change: 0 additions & 1 deletion cookbook/05_agent_os/interfaces/agui/user_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from agno.db.sqlite import SqliteDb
from agno.models.openai import OpenAIResponses


user_input_agent = Agent(
name="user_input",
model=OpenAIResponses(id="gpt-5.5"),
Expand Down
2 changes: 2 additions & 0 deletions cookbook/06_storage/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ uv pip install psycopg2-binary # PostgreSQL
uv pip install pymongo # MongoDB
uv pip install mysql-connector-python # MySQL
uv pip install redis # Redis
uv pip install valkey-glide-sync # Valkey
uv pip install google-cloud-firestore # Firestore
uv pip install boto3 # DynamoDB
uv pip install singlestoredb # SingleStore
Expand Down Expand Up @@ -39,6 +40,7 @@ agent = Agent(
- [`mongo`](mongo/) - MongoDB document database integration
- [`mysql`](mysql/) - MySQL relational database integration
- [`redis`](redis/) - Redis in-memory data structure store integration
- [`valkey`](valkey/) - Valkey in-memory data structure store integration
- [`singlestore`](singlestore/) - SingleStore distributed SQL database integration
- [`firestore`](firestore/) - Google Cloud Firestore NoSQL database integration
- [`dynamodb`](dynamodb/) - AWS DynamoDB NoSQL database integration
Expand Down
32 changes: 32 additions & 0 deletions cookbook/06_storage/valkey/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Valkey Integration

Examples demonstrating Valkey integration with Agno agents, teams, and workflows.

## Setup

```shell
uv pip install valkey-glide-sync

# Start Valkey container
docker run --name my-valkey -p 6379:6379 -d valkey/valkey-bundle
```

## Configuration

```python
from agno.agent import Agent
from agno.db.valkey import ValkeyDb

db = ValkeyDb(host="localhost", port=6379)

agent = Agent(
db=db,
add_history_to_context=True,
)
```

## Examples

- [`valkey_for_agent.py`](valkey_for_agent.py) - Agent with Valkey storage
- [`valkey_for_team.py`](valkey_for_team.py) - Team with Valkey storage
- [`valkey_for_workflow.py`](valkey_for_workflow.py) - Workflow with Valkey storage
31 changes: 31 additions & 0 deletions cookbook/06_storage/valkey/TEST_LOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Test Log: valkey

### valkey_for_agent.py

**Status:** PASS

**Description:** Runs an agent backed by ValkeyDb, asks two follow-up questions with history in context, and verifies sessions are persisted via `get_sessions`.

**Result:** Agent answered both turns (correctly resolved "their" from prior turn via history); `get_sessions` reported 3 agent sessions persisted in Valkey. Re-tested after learnings/isolation additions: both turns answered, 2 sessions persisted on a fresh server.

---

### valkey_for_team.py

**Status:** PASS

**Description:** Runs a HackerNews + web-search team backed by ValkeyDb with `output_schema=Article`, and persists team/member sessions.

**Result:** Team completed and returned a valid structured `Article` (title, summary, reference_links); team session index present in Valkey. Note: the external DuckDuckGo (`ddgs`) web search intermittently failed with RemoteProtocolError/TimeoutException and was retried; total run took ~13 min. This is an upstream web-search flakiness, not a Valkey/cookbook issue. Re-tested after learnings/isolation additions: completed with a valid structured Article.

---

### valkey_for_workflow.py

**Status:** PASS

**Description:** Runs a two-step workflow (research team then content planner) using `ValkeyDb(session_table="workflow_session")`.

**Result:** Workflow completed in ~444s and produced a 4-week content plan; workflow session index (`workflow_id:content-creation-workflow`) present in Valkey. Re-tested after learnings/isolation additions: completed in ~223s with a 4-week content plan.

---
Empty file.
46 changes: 46 additions & 0 deletions cookbook/06_storage/valkey/valkey_for_agent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
"""
Example showing how to use Valkey as the database for an agent.

Run `uv pip install valkey-glide-sync openai ddgs` to install dependencies.

We can start Valkey locally using docker:
1. Start Valkey container
`docker run --name my-valkey -p 6379:6379 -d valkey/valkey-bundle`

2. Verify container is running
`docker ps`

3. Run the file
`python cookbook/06_storage/valkey/valkey_for_agent.py`
"""

from agno.agent import Agent
from agno.db.base import SessionType
from agno.db.valkey import ValkeyDb
from agno.tools.websearch import WebSearchTools

# ---------------------------------------------------------------------------
# Setup
# ---------------------------------------------------------------------------
db = ValkeyDb()

# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------
agent = Agent(
db=db,
tools=[WebSearchTools()],
add_history_to_context=True,
)

# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------
if __name__ == "__main__":
agent.print_response("How many people live in Canada?")
agent.print_response("What is their national anthem called?")

# Verify db contents
print("\nVerifying db contents...")
all_sessions = db.get_sessions(session_type=SessionType.AGENT)
print(f"Total sessions in Valkey: {len(all_sessions)}")
77 changes: 77 additions & 0 deletions cookbook/06_storage/valkey/valkey_for_team.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
"""
Example showing how to use Valkey as the database for a team.

Run: `uv pip install ddgs valkey-glide-sync` to install the dependencies

We can start Valkey locally using docker:
1. Start Valkey container
`docker run --name my-valkey -p 6379:6379 -d valkey/valkey-bundle`

2. Verify container is running
`docker ps`

3. Run the file
`python cookbook/06_storage/valkey/valkey_for_team.py`
"""

from typing import List

from agno.agent import Agent
from agno.db.valkey import ValkeyDb
from agno.models.openai import OpenAIResponses
from agno.team import Team
from agno.tools.hackernews import HackerNewsTools
from agno.tools.websearch import WebSearchTools
from pydantic import BaseModel

# ---------------------------------------------------------------------------
# Setup
# ---------------------------------------------------------------------------
db = ValkeyDb()


# ---------------------------------------------------------------------------
# Create Team
# ---------------------------------------------------------------------------
class Article(BaseModel):
title: str
summary: str
reference_links: List[str]


hn_researcher = Agent(
name="HackerNews Researcher",
model=OpenAIResponses(id="gpt-5.5"),
role="Gets top stories from hackernews.",
tools=[HackerNewsTools()],
)

web_searcher = Agent(
name="Web Searcher",
model=OpenAIResponses(id="gpt-5.5"),
role="Searches the web for information on a topic",
tools=[WebSearchTools()],
add_datetime_to_context=True,
)


hn_team = Team(
name="HackerNews Team",
model=OpenAIResponses(id="gpt-5.5"),
members=[hn_researcher, web_searcher],
db=db,
instructions=[
"First, search hackernews for what the user is asking about.",
"Then, ask the web searcher to search for each story to get more information.",
"Finally, provide a thoughtful and engaging summary.",
],
output_schema=Article,
markdown=True,
show_members_responses=True,
)

# ---------------------------------------------------------------------------
# Run Team
# ---------------------------------------------------------------------------
if __name__ == "__main__":
hn_team.print_response("Write an article about the top 2 stories on hackernews")
Loading
Loading