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_searchtool 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
- Create an API key at https://app.tryglen.com/settings/api-keys.
- 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. - 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 the run lifecycle, 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 |
modes |
True |
Follow the account's Glen mode: off uses and records nothing, silent records but hides the tool and instructions, incognito keeps the tool but records nothing |
on_notice |
None |
Called once per message when Glen says something the user should see (recording paused by a plan limit, a rejected key). Always logged as a warning too |
code_search |
True |
Add the glen_code_search tool when the agent runs in a git checkout with a remote: it traces lines of code (blame, then the commits' Glen-Conversation trailers) to the conversations that wrote them |
skills |
True |
Add glen_skill_search and glen_skill_use: the team's shared skills. A skill's bundled files are written to a new temporary directory (paths that escape it are refused) and ${GLEN_SKILL_DIR} in the instructions points there |
link_commits |
True |
After a run that committed, tell Glen which commits belong to the conversation so code search and the PR reviewer can trace them. Needs a git checkout with a remote and on mode |
instructions |
True |
Tell the agent to search Glen before changing a system the team already worked on (needs search). Turn it off if your own prompt says it |
background |
True |
Upload without delaying the run. Use False with run_sync |
agent_name, agent_version |
"pydantic-ai", None |
Reported to Glen |
workspace |
"auto" |
cwd, repoName, branch, commit, remoteUrl for each recorded turn. "auto" reads them from git in the current directory (nothing outside a repository; a remote's credentials are dropped), a dict is used as given, None sends none |
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.
Compared with the Claude Code plugin
The Claude Code plugin works through hooks. This is what carries over to a Pydantic AI agent:
| Claude Code plugin | This capability |
|---|---|
| Injects the team-memory rule at session start | Yes: added to the agent's instructions (instructions=False to opt out) |
| Records each prompt and turn | Records each run, including one that fails or is cancelled (what it did so far) |
| Honors on / off / silent / incognito and plan limits | Yes: the mode is read from Glen about once a minute (modes=False to ignore it); plan limits and a rejected key reach on_notice |
| Sends repo, branch and commit with each turn | Yes: read from git in the current directory (workspace=None to opt out) |
Code search (glen code-search) |
Yes: the glen_code_search tool, offered in a git checkout with a remote |
| Links commits to the conversation | Yes: after a run that ran git commit in the checkout, each commit is linked (link_commits=False to opt out) |
Team skills (glen skill search / use) |
Yes: glen_skill_search and glen_skill_use (not the per-turn skill suggestions, see below) |
The plugin also shows a banner when Glen thinks a saved skill fits your prompt (skillsToOffer in each turn response). That only makes sense with a person reading the reply, so a library agent does not get it; it can search skills itself.
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.
- A run that fails or is cancelled is recorded too (what it did so far, ending with a note of how it ended), and its error still raises. A run that fails before its first model request records nothing.
- 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.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| pydantic_ai_glen-0.2.0.tar.gz | 28.3 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pydantic_ai_glen-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 49.9 kB
Release files / pydantic_ai_glen-0.2.0.tar.gz
| Download URL | pydantic_ai_glen-0.2.0.tar.gz |
|---|---|
| Size | 28.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8b9f03a6d77e70414bfe292b9ddbfdf6ebcf53c21b3536fec6ffd83db1e90049
|
|
BLAKE2b-256 checksum How to use checksums |
c34a65c3846a8d889863bcb497ac5cdfa60face65f89251174ec32d9dad73879
|
| 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 logRelease files / pydantic_ai_glen-0.2.0-py3-none-any.whl
| Download URL | pydantic_ai_glen-0.2.0-py3-none-any.whl |
|---|---|
| Size | 21.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
01eeab3ebafad00ea54aa285382a484ec6d139df2964da5aa7cd20843f708fc7
|
|
BLAKE2b-256 checksum How to use checksums |
1f9076dc054b3d0de016402660b73f6cca71dd212d08e43f836ca71f78915701
|
| 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 logSecurity for pydantic-ai-glen 0.2.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.
Attestation for pydantic_ai_glen-0.2.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 logA 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.