Skip to main content

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:

  1. 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.
  2. Activate — the generated model immediately becomes the agent's output type for its final answer. Companion tools list_output_schemas and deactivate_output_schema manage the lifecycle.
  3. Verify — after the run completes, user-supplied Verifier checks run against the active model. If any fail, the agent is re-run with the failure messages so it can evolve the schema, up to max_retries times.
  4. Persist — every version is stored on disk as a plain Python module (<name>.v<version>.py) indexed by a manifest.json with 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


Download files

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

Source Distribution

pydantic_ai_gedanken-0.1.0.tar.gz (189.2 kB view details)

Uploaded Source

Built Distribution

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

pydantic_ai_gedanken-0.1.0-py3-none-any.whl (19.6 kB view details)

Uploaded Python 3

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

Hashes for pydantic_ai_gedanken-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c57837eef5ac86517365b9f778c194caa9387257009a3fa2968a4f50702f919c
MD5 7d04b52eb834a1818ae679d41195e180
BLAKE2b-256 87bd16f4c586420ab6b7836a829010feef9ab1c83545c77d4aad13c53b800eee

See more details on using hashes here.

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

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

File details

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

File metadata

File hashes

Hashes for pydantic_ai_gedanken-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f8f4763ca5ba556f01057460aaaedba8faa37dbc94ec0ea509f011ee130857a2
MD5 67a0b0859ac9dc98e3824b229f10fa75
BLAKE2b-256 c8ce1a3f3e4b25c01ad30dca5ff4d3a98e157dce026287ba14f4e3184884839f

See more details on using hashes here.

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

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