TECHNOLOGY

Pydantic AI deferred calls need correlated external results

In this article
THE QUICK TAKE

Store both the external job receipt and the originating tool-call identity, then resume with the actual correlated result rather than a scheduling acknowledgement.

Hand off the slow extraction without inventing its answer

A document extraction takes longer than the application wants to keep an agent process active. Pydantic AI’s deferred-tool guide treats this as external tool execution. A tool can schedule background work and raise CallDeferred. The handoff indicates that the result will arrive elsewhere; it does not mean the document was extracted or that its contents are already available to the model.

Preserve the identities on both sides

The guide recommends passing the originating tool_call_id when scheduling external work. A job system may also return its own receipt or task identifier. Keep the mapping between these identities. A job identifier locates the external operation; the tool-call identifier locates the pending conversation request. Matching only by source URL or tool name becomes ambiguous when the same document is processed under different extraction options or several runs overlap.

Distinguish pending calls from approvals

The tool API separates deferred external calls from approval requests and defines per-call metadata. An external call needs a result from its executor; an approval authorizes the framework to execute a tool. Supplying an approval Boolean is not a substitute for extraction output. Preserve the request kind so a review interface or queue consumer cannot accidentally treat a permission decision as the completed document observation.

Return the actual external outcome

When work finishes, DeferredToolResults.calls associates results with original call identifiers. The guide also describes reporting a failure that asks the model to try again or a terminal tool failure. Choose according to the real external outcome. A successful queue submission receipt should remain a receipt, not be promoted into an apparently successful extraction result. Task contracts identify what data the eventual tool result must contain to satisfy its consumer.

Resume the original frontier deliberately

The history guide explains how deferred results resolve the pending tool calls in the original conversation. Continue with that history or conversation instead of asking for a new unrelated extraction. Tool observations should link scheduling, external completion and result delivery. This preserves the distinction between work running elsewhere, work already finished externally and a result actually supplied to the model for its next decision.

Earn rental income from GPUs

Have idle GPUs or looking to fund AI infrastructure? Retrivium finds a rental platform, sets up the server and helps you assess income and costs with a pilot.

Explore GPU hosting
← All articles