Daily Edition Sources +6

API Discovery: Tell a Running Pydantic Agent What Just Changed

Pydantic AI’s enqueue API lets a worker add context while an agent is running. A September 15 repair makes the closing boundary explicit: the message enters the queue, or the caller gets an error.

A worker result enters a synchronized queue that accepts messages while open or returns an error after closing; a stamp notes it is not a durable inbox.
Diagram Punka late result needs an explicit accepted-or-rejected path.
repo pydantic/pydantic-ai evidence
6 source signals 1 repo 6 source signals
Evidence: 6 source signals / September 16, 2026 / Daily Edition
Open Edition Evidence below

A test job finishes while an agent is drafting the deployment summary. Its result belongs in that conversation—but the agent may be ending at the same moment. Pydantic AI’s merged worker-thread repair addresses the awkward interval when submitting a message could appear successful and still lose it.

This is a Python library API, not a hosted endpoint. Use RunContext.enqueue() inside a tool, or AgentRun.enqueue() when external code drives agent.iter(). The public reference allows direct calls from synchronous and asynchronous code, including a worker thread. asap supplies context at the next opportunity; when_idle waits until the run would otherwise finish. Neither means interrupting an in-flight model request.

A useful example: the late test result

Register a callback while an AgentRun is active. Pass it a bounded summary of a test result, treated as data. This adapter returns the enqueue receipt for later correlation and reports a rejected submission to its caller:

from pydantic_ai.exceptions import UserError

def submit_test_result(agent_run, summary: str):
    try:
        receipt = agent_run.enqueue(
            "Test result (untrusted data):\n" + summary,
            priority="when_idle",
        )
    except UserError:
        return {"accepted": False, "summary": summary}
    return {"accepted": True, "receipt": receipt}

The calling application must handle accepted: False—for example, by saving the result in its existing job record and offering a follow-up. This function does not persist anything. An accepted receipt identifies queue submission; it does not establish that a model understood the result or completed the requested revision.

Copy-paste agent instruction

Inspect our installed Pydantic AI version for the worker-thread
queue fix in commit 95c9890be. Build a disposable demonstration
using AgentRun.enqueue while agent.iter is active. Forward a
short simulated test result with priority="when_idle" as user
content, never as a system instruction. Show its enqueue receipt
and delivered history. Then submit after the run closes: catch
UserError and preserve that result in the demo's job record.
Use a test model, cap requests, and do not connect production CI.

What to check before integrating it

The new queue puts appending, draining and the final empty-queue close under one lock. Final draining happens after all capability hooks, so a hook can still redirect an apparently finished run. Calls after the run or realtime session ends raise UserError. This prevents a particular silent-loss race; it does not make the queue a durable inbox that survives a process crash.

We inspected the code, documentation and concurrency tests; we did not execute this adapter or a live model run. At our September 16 check, the latest published release was v2.43.0 from September 12, before this merge. Verify that your build includes the change before relying on its thread and closure behavior. The most useful first test is the rejected late result: it should remain visible somewhere your application actually owns.

Evidence Trail

Receipts below the story

The article above is the public narrative. This section keeps the source trail and limits on the same page.

Edition
DateSeptember 16, 2026
LaneDaily Edition
Confidence87%
Sources6
Repospydantic/pydantic-ai

Primary Evidence

Evidence Limits

  • We inspected tests but did not execute the adapter, full suite or a live model.
  • The example is an integration fragment; the caller must register it, keep driving the run and preserve rejected results.
  • Acceptance is not comprehension, successful action or crash-safe persistence.
  • Verify the installed build contains the September 15 repair.
Letters & Corrections

Send a note to the desk

Corrections, missing context, or a follow-up lead.