Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 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.

---
65 changes: 65 additions & 0 deletions cookbook/05_agent_os/dbs/valkey_db.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
"""Example showing how to use AgentOS with Valkey as the database"""
Comment thread
harshsinha03 marked this conversation as resolved.
Outdated

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)
34 changes: 34 additions & 0 deletions cookbook/06_storage/valkey/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Valkey Integration

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

## Setup

These configurations and examples will use Valkey GLIDE.

```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.

---

### 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.

---

### 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.

---
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")
75 changes: 75 additions & 0 deletions cookbook/06_storage/valkey/valkey_for_workflow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
"""
Valkey Storage for Workflow
===========================
Demonstrates using ValkeyDb as the session storage backend for a workflow.
"""

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 agno.workflow.step import Step
from agno.workflow.workflow import Workflow

# ---------------------------------------------------------------------------
# Create Workflow
# ---------------------------------------------------------------------------
hackernews_agent = Agent(
name="Hackernews Agent",
model=OpenAIResponses(id="gpt-5.5"),
tools=[HackerNewsTools()],
role="Extract key insights and content from Hackernews posts",
)
web_agent = Agent(
name="Web Agent",
model=OpenAIResponses(id="gpt-5.5"),
tools=[WebSearchTools()],
role="Search the web for the latest news and trends",
)

# Define research team for complex analysis
research_team = Team(
name="Research Team",
members=[hackernews_agent, web_agent],
instructions="Research tech topics from Hackernews and the web",
)

content_planner = Agent(
name="Content Planner",
model=OpenAIResponses(id="gpt-5.5"),
instructions=[
"Plan a content schedule over 4 weeks for the provided topic and research content",
"Ensure that I have posts for 3 posts per week",
],
)

# Define steps
research_step = Step(
name="Research Step",
team=research_team,
)

content_planning_step = Step(
name="Content Planning Step",
agent=content_planner,
)

# ---------------------------------------------------------------------------
# Run Workflow
# ---------------------------------------------------------------------------
if __name__ == "__main__":
content_creation_workflow = Workflow(
name="Content Creation Workflow",
description="Automated content creation from blog posts to social media",
db=ValkeyDb(
session_table="workflow_session",
),
steps=[research_step, content_planning_step],
)
content_creation_workflow.print_response(
input="AI trends in 2024",
markdown=True,
)
2 changes: 2 additions & 0 deletions cookbook/07_knowledge/05_integrations/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ Specific reader, cloud storage, and vector database integrations.
| [vector_dbs/01_qdrant.py](./vector_dbs/01_qdrant.py) | Qdrant (recommended for production) |
| [vector_dbs/02_local.py](./vector_dbs/02_local.py) | ChromaDB + LanceDB (local development) |
| [vector_dbs/03_managed.py](./vector_dbs/03_managed.py) | Pinecone + PgVector (managed/production) |
| [vector_dbs/04_pgvector.py](./vector_dbs/04_pgvector.py) | PgVector (PostgreSQL) |
| [vector_dbs/05_valkey.py](./vector_dbs/05_valkey.py) | Valkey (ValkeySearch via GLIDE) |

## Running

Expand Down
Loading