Skip to main content

Pydantic AI tool adapters for Copass — drop-in discover/interpret/search tools for Pydantic AI agents

Project description

copass-pydantic-ai

Copass retrieval as Pydantic AI tools. The LLM decides whether to discover, interpret, or search — you don't write the tool-calling loop.

Prerequisites

Install the Copass CLI and bootstrap your account:

npm install -g @copass/cli
copass login                             # email OTP
copass setup                             # creates a sandbox, writes .olane/refs.json
copass apikey create --name my-app       # prints an olk_... key — shown once, save it
Output Use as
olk_... key printed by copass apikey create api_key on CopassRetrievalClient (typically via COPASS_API_KEY env)
sandbox_id in ./.olane/refs.json sandbox_id on copass_tools (typically via COPASS_SANDBOX_ID env)

Ingest some content so retrieval has something to return:

copass ingest path/to/file.md

Install

pip install copass-pydantic-ai pydantic-ai

Requires Python 3.10+.

Quickstart

import os
from pydantic_ai import Agent
from copass_pydantic_ai import CopassRetrievalClient, copass_tools

# COPASS_API_KEY is the olk_... token from `copass apikey create`.
# COPASS_SANDBOX_ID is from .olane/refs.json (written by `copass setup`).
client = CopassRetrievalClient(
    api_url=os.environ.get("COPASS_API_URL", "https://ai.copass.id"),
    api_key=os.environ["COPASS_API_KEY"],
)
discover, interpret, search = copass_tools(
    client=client,
    sandbox_id=os.environ["COPASS_SANDBOX_ID"],
)

agent = Agent(
    "anthropic:claude-opus-4-7",
    tools=[discover, interpret, search],
)
result = await agent.run("what do we know about checkout retry behavior?")
print(result.output)

If it worked, the answer cites concepts from whatever you ingested. Run twice with a shared window (see below) — the second call won't re-surface items the agent already used.

Why this, not the raw API

  • LLM chooses the retrieval shape. Three tools; the model picks the right one per turn.
  • Pydantic AI-native. Type hints become the schema; docstrings become descriptions. No decorator dance.
  • Trimmed responses. Tools return only what the model needs — no sandbox/query echoes.

Tools

Tool When the LLM calls it
discover "What's relevant?" — ranked menu of pointers
interpret "Tell me about these specific items." — brief pinned to canonical_ids
search "Answer this directly." — full synthesized answer

Window-aware retrieval

Pass any object with a get_turns() method:

class MyWindow:
    def __init__(self):
        self.turns: list[dict[str, str]] = []
    def get_turns(self) -> list[dict[str, str]]:
        return self.turns

window = MyWindow()
discover, interpret, search = copass_tools(
    client=client,
    sandbox_id=project_refs["sandbox_id"],
    window=window,
)

Every retrieval call forwards window.get_turns() as history so the server excludes already-seen content.

Low-level client

If you don't want the Pydantic AI wrapping, CopassRetrievalClient is a minimal async httpx client you can use directly:

menu = await client.discover("sb_...", query="...")
brief = await client.interpret("sb_...", query="...", items=[["cid1", "cid2"]])
answer = await client.search("sb_...", query="...")

Related

License

MIT

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

copass_pydantic_ai-1.0.6.tar.gz (8.1 kB view details)

Uploaded Source

Built Distribution

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

copass_pydantic_ai-1.0.6-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

Details for the file copass_pydantic_ai-1.0.6.tar.gz.

File metadata

  • Download URL: copass_pydantic_ai-1.0.6.tar.gz
  • Upload date:
  • Size: 8.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for copass_pydantic_ai-1.0.6.tar.gz
Algorithm Hash digest
SHA256 3a6e01f1a0d32007e3bd6212047c82f4090e059bbb6cfd0e15189855c4031663
MD5 57bddb5c7f82a35531b2a260eea106c1
BLAKE2b-256 ab2cba4b42e9e47f12a3bac144dc84b344f84288dd4c9971d071bc78fd8135f0

See more details on using hashes here.

Provenance

The following attestation bundles were made for copass_pydantic_ai-1.0.6.tar.gz:

Publisher: release-python.yml on olane-labs/copass

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file copass_pydantic_ai-1.0.6-py3-none-any.whl.

File metadata

File hashes

Hashes for copass_pydantic_ai-1.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 c8d7c8ce3416fe537f06a2f4f4639d80ba12e26d417a46dbca0ca2c4dc5c8f92
MD5 13a9c4b5e7f36e1a17853ac2ae6701af
BLAKE2b-256 52b5a34440c39cd11dbb5e88b9a1d964148f3e4457a36c611b1c75005ad8de51

See more details on using hashes here.

Provenance

The following attestation bundles were made for copass_pydantic_ai-1.0.6-py3-none-any.whl:

Publisher: release-python.yml on olane-labs/copass

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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