Skip to main content

pydantic-ai-glen

A Pydantic AI capability that connects an agent to Glen, a shared team memory. It does two things:

  • Search: adds a glen_search tool so the agent can ask Glen a question.
  • Recording: after every run, sends that run's conversation to Glen so it becomes searchable memory. Glen extracts memory in the background on its side.

Install

pip install pydantic-ai-glen

Requires Python 3.10+ and pydantic-ai-slim>=2.9.

Setup

  1. Create an API key at https://app.tryglen.com/settings/api-keys.
  2. In Glen, switch to the organization the agent should use, click Connect an agent, then MCP server, and copy the value next to x-glen-org-id.
  3. Set both where the app runs (never commit them):
GLEN_API_KEY=<your key>
GLEN_ORG_ID=<your organization id>

GLEN_URL is optional and defaults to https://app.tryglen.com.

Usage

from pydantic_ai import Agent
from pydantic_ai_glen import Glen

glen = Glen()  # reads GLEN_API_KEY / GLEN_ORG_ID
agent = Agent("openai:gpt-5", capabilities=[glen])

result = await agent.run("why does the billing worker batch at 500?")
await glen.flush()  # before a short-lived process exits

Recording hooks into after_run, so run, run_stream, iter and run_sync are all covered with no wrapper code.

Option Default
api_key, org_id, url env vars Constructor values win over the environment
search True Expose the glen_search tool
record True Send finished runs to Glen
background True Upload without delaying the run. Use False with run_sync
agent_name, agent_version "pydantic-ai", None Reported to Glen
workspace None cwd, repoName, branch, commit, remoteUrl

Conversations are grouped by Pydantic AI's conversation_id. Pass your own thread id to agent.run(..., conversation_id=...) to keep one Glen conversation across runs.

Behavior

  • A Glen failure never fails a run. Search returns a short message to the model; recording retries transient errors (429/5xx) three times with the same idempotency key, then logs.
  • Only this run's new messages are sent, with tool calls, tool results and thinking as ordered segments. System prompts and non-text prompt content (images, audio) are not sent.
  • Everything recorded becomes real team memory. Don't point test runs at your real org.

Known issue

Conversations recorded this way currently show up in Glen labelled as Claude Code sessions (claude-code:<conversationId>). Only the label is affected; recording, search and memory work normally.

Try it

examples/demo.py is an interactive chat that searches Glen and records the conversation:

export GLEN_API_KEY=... GLEN_ORG_ID=...
uv run --with "pydantic-ai-slim[anthropic]" python examples/demo.py --model anthropic:claude-sonnet-5-5
uv run --with "pydantic-ai-slim[anthropic]" python examples/demo.py --model anthropic:claude-sonnet-5-5 --search-only

It asks before recording, since whatever you type becomes team memory. Use any model string Pydantic AI supports (--model or DEMO_MODEL).

Development

uv sync --extra dev
uv run ruff check . && uv run ruff format --check .
uv run pytest

Tests fake Glen's HTTP API with httpx.MockTransport; the agent, capability and message conversion run for real.

See CONTRIBUTING.md and SECURITY.md.

This is an independent integration; Pydantic AI and Glen are their respective owners' projects.

License

MIT, see LICENSE.

Metadata

Release files for pydantic-ai-glen 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pydantic-ai-glen 0.1.0
File Size Uploaded Provenance
pydantic_ai_glen-0.1.0.tar.gz 11.1 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for pydantic-ai-glen 0.1.0
File Interpreter ABI Platform
pydantic_ai_glen-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 20.3 kB

Release files / pydantic_ai_glen-0.1.0.tar.gz

Download URL pydantic_ai_glen-0.1.0.tar.gz
Size 11.1 kB
Tags Source
SHA-256 checksum
How to use checksums
280f0e05fcb2b47f0e78df634c35dc56ff7118e5af6d87e4043787d3a02b9f4f
BLAKE2b-256 checksum
How to use checksums
7d077c72369e753f088f4492b996e2ad02939424600b0f7288801497aecf2f02
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 26, 2026.

Transparency log

Release files / pydantic_ai_glen-0.1.0-py3-none-any.whl

Download URL pydantic_ai_glen-0.1.0-py3-none-any.whl
Size 9.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ab7f9af769888c1240c0206818d5f633e153c09ca889748adf186fe225490803
BLAKE2b-256 checksum
How to use checksums
04251b9476cde7dd0837104d44a6ba1d6d2ddb99cfbd292be102b27a00339a48
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 26, 2026.

Transparency log

Security for pydantic-ai-glen 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pydantic_ai_glen-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 26, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page