Skip to content

pydantic-ai adapter ​

Status: shipped, release phase. It passes the contract suite in chat mode, on a fake bridge that plays the Acme example agent. Its bridge ran end to end on the real pydantic-ai 2.55.0 with a FunctionModel, two blocks with the history replayed. It has not run against a live model yet.

The pydantic-ai adapter runs a Pydantic AI agent in a Python process, one process per block, through a bridge script that ships with the adapter. Python and pydantic-ai are yours to install; driftbench depends on neither.

Options ​

ts
import { pydanticAiAdapter } from '@agent-nexus/driftbench-adapters';

const adapter = pydanticAiAdapter({
  agent: 'acme.agents:sales', // an Agent, or a function that returns one
  python: '.venv/bin/python',
  cwd: '/srv/acme', // where the agent's module is importable; also set as PYTHONPATH
  toolLabels: { coverage_check: 'coverage.check' },
  sideEffects: ['order.create'],
});
OptionMeaning
agentthe agent, as <module>:<name>
pythonthe interpreter. Default python3.
cwd, envwhere the process runs, and extra variables. Keys come from the environment, never from an option.
timeoutMsthe most milliseconds one block may take. Default 600000.
execruns the process. Default spawnExec; tests pass one that plays the bridge.
toolLabels, sideEffects, deterministic, versionas on the openai-agents adapter

The bridge &ZeroWidthSpace;

The adapter writes the bridge (packages/adapters/src/pydantic-ai/bridge.py) to a file under the temporary folder, named by its hash, and runs python bridge.py <agent>. On stdin it gets { "user_prompt": ..., "message_history": [...] }: the block's user text, and the earlier turns in Pydantic AI's own format (what ModelMessagesTypeAdapter reads). It runs the agent once (run_sync) and prints one line, driftbench-result <the run's new messages>. Everything else the agent prints goes to stderr, and the adapter skips any other line on stdout, such as a banner.

History messagePydantic AI
a user message, or a tool notea request with a user-prompt part
a system messagea request with a system-prompt part
a recorded tool calla response with a tool-call part, then a request with its tool-return, or a retry-prompt carrying the error
the reply texta response with a text part

What the adapter reads &ZeroWidthSpace;

The new messages, in order: a response's text parts are text, its tool-call parts tool calls (arguments parsed when they are JSON text), its usage (input_tokens, output_tokens) on its first segment; a request's tool-return is the call's result (an error when its outcome is not success), and a retry-prompt that names a tool is that call's error (the tool asked the model to try again). The agent runs its own tools, so world.tools cannot reach them.

Capabilities &ZeroWidthSpace;

seedPrefix yes; toolStubs no; endState with sideEffects; the rest no; deterministic as declared.

Errors &ZeroWidthSpace;

What happensError
the bridge prints driftbench-error with a 408, a 429 or a 5xx (ModelHTTPError.status_code), or a connection or timeout error typeAdapterTransportError: the runner retries under the shared policy
the interpreter cannot startAdapterTransportError, marked exhausted: not retried
the process gives no answer within timeoutMsAdapterTransportError
any other driftbench-error, or an exit without a result lineAgentFailure, with the error or the end of stderr

Target &ZeroWidthSpace;

The adapter reads no field of the target except retry. Its id is pydantic-ai.

MIT. driftbench is made by Nexus.