Learning resourcesReviewed · Pydantic

Pydantic AI Harness: Runtime Capability Creation

This guide teaches Python agent developers to let Pydantic AI agents create persistent extensions, but the generated Python executes with the agent process's permissions. CapabilityCreation validates source during the current run; application code must explicitly load it into a later run before its tools, hooks or instructions become available.

Researched 15 Nov 2026

In short.

This guide explains persistent agent extensions for Python developers using Pydantic AI, with the central catch that validation executes generated code on the host. It documents authoring, loading, disabling, persistence and approval controls. New capabilities become available only through explicit loading into a later run, and the documented activation pattern has restrictions under durable execution. Runtime behavior was not tested, and costs are unknown.

Researched and written by an AI model and checked by a second AI model. How it works

Coverage is the complete selected page at [https://pydantic.dev/docs/ai/harness/capability-creation/index.md], including its API reference, diagram description, trust and approval guidance, persistence behavior, durable-execution restrictions, telemetry notes and 0.x compatibility notice. Linked documentation, repository files, the documentation index and the diagram image itself are excluded. The page's documentation-fetching notices do not establish feature behavior. No code was executed; runtime correctness, security-control effectiveness, performance, costs and linked licensing terms remain unassessed.

The overview

Identity

Runtime Capability Creation is a Pydantic AI Harness feature documented through a usage guide and API reference. Its main interfaces are CapabilityCreation, which exposes agent tools, and CapabilityStore, which manages authored Python files and their manifest.

The original page is [https://pydantic.dev/docs/ai/harness/capability-creation/index.md]. It concerns capabilities authored by the model as Python source, including tools, instructions, model settings and lifecycle hooks.

Assessment

The feature is a plausible fit when a local coding agent needs to create reusable behavior during a task and carry it into subsequent runs. The guide is specific about the application loop, storage behavior and failure cases, making it useful for implementation planning.

Its decisive tradeoff is execution authority: authoring imports and runs generated Python before validation completes. Validation can reject structurally invalid capabilities, but it does not establish that their code is safe or their behavior is correct.

Users

The main audience is Python developers building Pydantic AI agents whose behavior should evolve across runs. Useful cases described by the page include adding a guardrail, an instruction, a tool or a request hook.

Beginners need familiarity with Python classes, asynchronous agent calls and filesystem permissions. Experienced developers will need to assess orchestration, code approval, directory ownership and durable-workflow compatibility before adopting the pattern.

Capabilities

CapabilityCreation exposes author_capability(name, code), list_authored_capabilities() and disable_authored_capability(name). These author and validate source, report stored status and errors, and exclude disabled entries from subsequent active loads.

An authored capability can contribute tools, instructions, native tools, model settings or lifecycle methods. A hook is a method on a capability; overriding one lifecycle method is sufficient to define a capability.

Authored source persists across process restarts. Constructing a new CapabilityCreation over the same directory and calling its store.load_active() makes valid active entries available for injection into another run.

Using it

Requirements

The documented integration uses Pydantic AI, pydantic_ai_harness, a configured model and a writable LocalWorkspace. The authored directory must have operator authority and contain only operator-written or capability-authored code. A cloned repository or a user's upload is unsuitable as the storage directory.

A directory outside the workspace requires an explicit operator-authority mapping through path_authority. The checks also account for lower-authority subdirectories and symlinks. With deferred capability loading, the checks occur before authoring tool execution instead of at run startup.

Minimum Python and package versions, hardware requirements and a complete supported-model list are not established by this page.

Mechanism

Authoring imports the submitted module and requires exactly one AbstractCapability subclass that constructs without arguments. Validation calls get_instructions, get_toolset, get_native_tools, get_model_settings and get_serialization_name, checking that their returns are usable. It does not execute asynchronous lifecycle hooks because they need a live RunContext.

The effective capability set is fixed at the start of a run. Application code must call creation.store.load_active() and pass its returned instances as capabilities= to a subsequent agent.run(...). Successful authoring neither schedules nor injects the capability automatically.

Each capability has a Python file and a manifest entry recording its class, status and last validation error. Active loads import, construct and validate source again, skipping failures and updating their recorded errors. Previously loaded versions remain imported for the process lifetime.

Setup

Create CapabilityCreation with a directory such as Path('.authored'), then add it and LocalWorkspace to the Agent's capabilities. In the application loop, load active authored capabilities before each run and pass them through capabilities=. Preserve message history if the task spans multiple runs.

If a person must inspect generated source before it executes, configure a ToolGuardrail requiring approval for author_capability and handle DeferredToolRequests. Approval must precede authoring because import, construction and getter execution already happen during validation.

File or shell tools able to write the authored directory can bypass the authoring tool by changing source and manifest files directly. The guide recommends keeping that directory outside their workspace when every authored file must pass through validation, while explicitly granting the required operator authority.

Example

The API example asks the agent to build a logging capability and supplies capabilities=creation.store.load_active() to agent.run(...). That run receives capabilities already present in the store; a new logging capability authored during it becomes available only after another load and run.

The page does not provide the implementation of that logging capability or an execution transcript showing its behavior. The example illustrates integration rather than a demonstrated working logging extension.

Assessment & evidence

Limitations

If authored code blocks during validation, cancelling the run stops waiting for it, but its worker thread runs until the code returns and then finishes the write, so code that passes validation is still saved and loaded by the next load_active() unless it is disabled. load_active() executes generated code in its calling thread, so blocking code can block that call and other loads of the same source.

Stores sharing a directory coordinate manifest updates within one process. Separate processes do not coordinate, so the guide requires one process per directory at a time. Manifest writes are atomic, but an unreadable manifest prevents authoring and disabling until it is repaired or removed. Rejected replacement code is retained separately when a working version exists.

Durable execution records store operations for recovery, but the documented per-run activation pattern is refused inside Temporal and DBOS workflows. Prefect accepts authored hooks, instructions and model settings, while refusing authored function, MCP or dynamic toolsets. The authoring tools themselves work under all three.

A direct store.load_active() call before a run has no workspace context and cannot perform the run's authority checks. Authored capabilities contain live code and cannot be serialized as agent specifications.

Reasoning

The documented design separates creating an extension from activating its agent behavior. That can support reusable adaptations without restarting the process, provided the application supplies the next-run loading loop.

A practical implication is that structural validation cannot substitute for code review: the code has already executed during validation, and hooks remain unchecked until used with a live context. Directory authority identifies who controls the source location; the page explicitly warns that it does not prevent lower-trust material read by the model from influencing generated code.

Alternatives

For capabilities written or selected by application code, the page points to Building Custom Capabilities at [https://pydantic.dev/docs/ai/capabilities/custom/]. That route is relevant when developers want application-controlled extensions rather than model-authored source.

The linked guide was not supplied, so its detailed setup and tradeoffs are not assessed. The evidence supports no comparison with competing frameworks or separate extension systems.

Evidence

The evidence is the complete Runtime Capability Creation documentation page, including its usage examples, API reference, persistence rules, trust boundary, telemetry notes and durable-execution restrictions. It supports specific descriptions of the documented interfaces and intended behavior.

The page supplies no benchmarks, independent security evaluation or production results. Nothing was executed, so installation, runtime correctness, approval enforcement, failure recovery and performance remain untested.

Access & freshness

Costs

Costs are unknown. The page gives no feature price, model rates, token usage, execution measurements or hosting estimates. Model calls, host execution, storage and any durable-execution infrastructure would need separate cost assessment; the examples do not establish a free operating cost.

Rights

The page does not state a licence for the documentation or library code. It links to a source repository, but the linked repository's licence is outside the supplied evidence. Reproduction and redistribution rights are therefore unknown here.

The page also does not establish ownership or licensing terms for capabilities generated by a model. Those rights require separate assessment before distributing authored source.

Freshness

The documentation snapshot was captured on 15 November 2026. It does not identify an exact package release or state a publication or last-updated date.

The page warns that Pydantic AI Harness APIs may change between minor releases while on 0.x versions, with deprecation warnings and release-note migration guidance. Compatibility with a particular installed version therefore remains unknown.

Actions

Before adoption, confirm that the application can permit generated Python to execute in its own process and can defer new behavior until a subsequent run. Check the installed package API and any Temporal, Prefect or DBOS restrictions against the intended capability.

Choose an operator-controlled storage directory, restrict direct write access and require pre-execution approval when human review is needed. Account for load_active() executing source before run-level checks.

For an initial evaluation, use a small capability with observable behavior and verify authoring, later-run activation, rejection handling, disabling and restart persistence. Assess lifecycle hooks separately because author-time validation does not run them. These are suggested checks; none were performed.

Evidence for this report

selected-page.txtselected · checked 2026-11-15