Skip to main content

Sayou workspace toolset for Pydantic AI agents — persistent memory, file storage, and search

Project description

sayou-pydantic-ai

Persistent memory and workspace storage for Pydantic AI agents. Write files, search content, and persist conversation history — all through a single toolset.

Built on sayou, the file-system inspired context store for AI agents.

Install

pip install sayou-pydantic-ai

Quick Start

from pydantic_ai import Agent
from sayou_pydantic_ai import SayouToolset

agent = Agent("openai:gpt-4o", toolsets=[SayouToolset()])
result = await agent.run("Save a note about our meeting decisions")

Zero config. The agent gets 7 workspace tools and a local SQLite store at ~/.sayou/. Files persist across sessions.

Tools

Tool Description
workspace_write Create or update files (supports YAML frontmatter)
workspace_read Read files with token budget control
workspace_list List files and subfolders
workspace_search Full-text and metadata search
workspace_grep Content search with line context
workspace_glob Pattern matching (**/*.md, docs/**)
workspace_kv Key-value store for config/state

Optional tools (opt-in)

Tool Description
workspace_delete Soft-delete files
workspace_history Version history
workspace_links File-to-file links
workspace_chunks Chunk-based file reading

Enable them with the tools parameter:

from sayou_pydantic_ai.toolset import ALL_TOOLS

SayouToolset(tools=ALL_TOOLS)                          # Everything
SayouToolset(tools={"read", "write", "search", "delete"})  # Pick what you need

Persist Conversation History

from sayou.workspace import Workspace
from sayou_pydantic_ai import SayouToolset, SayouMessageHistory

async with Workspace() as ws:
    history = SayouMessageHistory(ws, conversation_id="project-alpha")
    agent = Agent("openai:gpt-4o", toolsets=[SayouToolset(workspace=ws)])

    # Load previous messages
    messages = await history.load()

    # Run with history
    result = await agent.run("Continue our discussion", message_history=messages)

    # Save for next session
    await history.save(result.all_messages())

Options:

  • max_messages=50 — keep only the last N messages
  • ttl_seconds=86400 — auto-expire after 24 hours

Choose Your Tools

# Default: 7 core tools
SayouToolset()

# Minimal: just read and write
SayouToolset(tools={"read", "write"})

# Full: all 11 tools including delete
SayouToolset(tools=ALL_TOOLS)

# Custom prefix
SayouToolset(tool_prefix="ws")      # ws_read, ws_write, ...
SayouToolset(tool_prefix="")        # read, write, ... (no prefix)

Dependency Injection

Use from_deps when the workspace comes from your agent's dependency system:

from dataclasses import dataclass
from sayou.workspace import Workspace
from sayou_pydantic_ai import SayouToolset

@dataclass
class MyDeps:
    workspace: Workspace

agent = Agent(
    "openai:gpt-4o",
    deps_type=MyDeps,
    toolsets=[SayouToolset.from_deps(lambda d: d.workspace)],
)

Configuration

Database

By default, sayou uses SQLite at ~/.sayou/sayou.db. For production, point to MySQL or any SQLAlchemy-compatible database:

SayouToolset(database_url="mysql+aiomysql://user:pass@host/db")

Or set the environment variable:

export SAYOU_DATABASE_URL="mysql+aiomysql://user:pass@host/db"

Workspace identity

SayouToolset(
    workspace=Workspace(
        slug="my-project",
        org_id="my-org",
        user_id="agent-1",
    )
)

How It Works

SayouToolset implements Pydantic AI's AbstractToolset interface. When the agent runs:

  1. get_tools() returns tool definitions with JSON schemas
  2. The LLM sees tools like workspace_write(path, content) and calls them
  3. call_tool() dispatches to the corresponding Workspace method
  4. Results are returned to the LLM as strings

Files are stored with version history. Every write creates a new version — nothing is lost.

SayouMessageHistory uses sayou's built-in KV store to serialize/deserialize Pydantic AI's ModelMessage objects via TypeAdapter.

Links

License

Apache 2.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sayou_pydantic_ai-0.1.0.tar.gz (16.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sayou_pydantic_ai-0.1.0-py3-none-any.whl (13.6 kB view details)

Uploaded Python 3

File details

Details for the file sayou_pydantic_ai-0.1.0.tar.gz.

File metadata

  • Download URL: sayou_pydantic_ai-0.1.0.tar.gz
  • Upload date:
  • Size: 16.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.0

File hashes

Hashes for sayou_pydantic_ai-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c5be3dcc649abee70b0f9f5a4f8e93a6321fb11bfd2a90689c116b5e9df049fe
MD5 516450838d51571181c4d63bbd7ea695
BLAKE2b-256 0d4b99f26449aada38c5b38d13125a86924abde1807e30f444635e9a7e3ed016

See more details on using hashes here.

File details

Details for the file sayou_pydantic_ai-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for sayou_pydantic_ai-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7364d877304177c6d7db05f805741c489726654f40cc020718442fb926e65a58
MD5 0267668a1bbcdd95a8cb324f07d57d56
BLAKE2b-256 b4f25b279fba478f84fd1e2155b8a7eac98d128e6640d167fbf1a4acfe5301a2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page