ProjectGedanken
Project description
pydantic-ai-gedanken
Experimental capabilities for Pydantic AI agents.
DynamicOutput
DynamicOutput is an agent capability that removes the need to fix an output type up front: the agent authors its own output type at runtime as a JSON Schema, which is converted into a real Pydantic model that evolves gradually across versions.
How it works:
- Author — the agent calls
author_output_schema(name, json_schema). The draft schema is lint-checked, converted into a Pydantic model by datamodel-code-generator, and the generated Python source is handed back to the agent so it authors against real code, not raw JSON. - Activate — the generated model immediately becomes the agent's output type for its final answer. Companion tools
list_output_schemasanddeactivate_output_schemamanage the lifecycle. - Verify — after the run completes, user-supplied
Verifierchecks run against the active model. If any fail, the agent is re-run with the failure messages so it can evolve the schema, up tomax_retriestimes. - Persist — every version is stored on disk as a plain Python module (
<name>.v<version>.py) indexed by amanifest.jsonwith statuses (draft/active/inactive), timestamps, and last errors. Modules can be read and hand-edited; edits are picked up on the next run.
Usage
from pathlib import Path
from pydantic import BaseModel
from pydantic_ai import Agent
from pydantic_ai_gedanken.capabilities.dynamic_output import (
DynamicOutput,
VerificationResult,
Verifier,
)
async def requires_name(model: type[BaseModel]) -> VerificationResult:
ok = 'name' in model.model_fields
return VerificationResult(passed=ok, message='ok' if ok else "declare a 'name' field")
dynamic_output = DynamicOutput(
directory=Path('.output_models'),
verifiers=[Verifier(name='requires_name', check_fn=requires_name)],
)
agent = Agent(
'anthropic:claude-sonnet-4-6',
capabilities=[dynamic_output],
output_type=[str, DynamicOutput.placeholder_output_type()],
)
To let the run end with the evolved output type, construct the agent with DynamicOutput.placeholder_output_type() — its output tool definition is rewritten in place with the active model's schema. To reuse the evolved model in another agent, thread dynamic_output.store.active_output_type() into it.
Development
Requires uv.
make install # install package + dev deps and set up pre-commit hooks
make format # auto-format and fix with ruff
make lint # check formatting and lint
make typecheck # run pyright
make test # run pytest
make # run all of the above
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pydantic_ai_gedanken-0.1.0.tar.gz.
File metadata
- Download URL: pydantic_ai_gedanken-0.1.0.tar.gz
- Upload date:
- Size: 189.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c57837eef5ac86517365b9f778c194caa9387257009a3fa2968a4f50702f919c
|
|
| MD5 |
7d04b52eb834a1818ae679d41195e180
|
|
| BLAKE2b-256 |
87bd16f4c586420ab6b7836a829010feef9ab1c83545c77d4aad13c53b800eee
|
Provenance
The following attestation bundles were made for pydantic_ai_gedanken-0.1.0.tar.gz:
Publisher:
release.yml on victor-camargo/pydantic-ai-gedanken
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pydantic_ai_gedanken-0.1.0.tar.gz -
Subject digest:
c57837eef5ac86517365b9f778c194caa9387257009a3fa2968a4f50702f919c - Sigstore transparency entry: 2285629451
- Sigstore integration time:
-
Permalink:
victor-camargo/pydantic-ai-gedanken@4f2739bdec7e02793cb7b1c1542c99bf21ec0250 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/victor-camargo
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@4f2739bdec7e02793cb7b1c1542c99bf21ec0250 -
Trigger Event:
push
-
Statement type:
File details
Details for the file pydantic_ai_gedanken-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pydantic_ai_gedanken-0.1.0-py3-none-any.whl
- Upload date:
- Size: 19.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f8f4763ca5ba556f01057460aaaedba8faa37dbc94ec0ea509f011ee130857a2
|
|
| MD5 |
67a0b0859ac9dc98e3824b229f10fa75
|
|
| BLAKE2b-256 |
c8ce1a3f3e4b25c01ad30dca5ff4d3a98e157dce026287ba14f4e3184884839f
|
Provenance
The following attestation bundles were made for pydantic_ai_gedanken-0.1.0-py3-none-any.whl:
Publisher:
release.yml on victor-camargo/pydantic-ai-gedanken
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pydantic_ai_gedanken-0.1.0-py3-none-any.whl -
Subject digest:
f8f4763ca5ba556f01057460aaaedba8faa37dbc94ec0ea509f011ee130857a2 - Sigstore transparency entry: 2285629473
- Sigstore integration time:
-
Permalink:
victor-camargo/pydantic-ai-gedanken@4f2739bdec7e02793cb7b1c1542c99bf21ec0250 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/victor-camargo
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@4f2739bdec7e02793cb7b1c1542c99bf21ec0250 -
Trigger Event:
push
-
Statement type: