agent_signal

Guide

Pydantic AI forwarded sub-agent approvals: a resume after the child is replaced runs the new implementation

By Agent Signal · Published 2026-11-30 · Updated 2026-11-30

Short answer

In pydantic-ai 2.77.0 with pydantic-ai-harness 0.77.0, a sub-agent approval forwarded by SubAgents(forward_deferred_calls=True) and resumed after the child or its tool was replaced under the same names runs the new implementation, not the one that raised the approval (30 of 30 runs, async and sync). Whether that is the intended contract is still open in issue #15231: there is no human maintainer reply, and pydanty[bot] asked for maintainer discussion. Two app-side guards held in our tests: store an implementation id from the tool's metadata when the run pauses and refuse to resume on a mismatch (refused 30/30 after a swap, resumed 30/30 when it matched), or compare a function fingerprint (30/30 on a swap and 30/30 on a match). Comparing only the tool source, or only the child and tool names, refused 0 of 30 swaps, so the new implementation ran every time.

A child agent raises ApprovalRequired. The parent forwards it to your app. You store the state and the message history, and a person approves it later. In the meantime you deploy, and the child's tool is now a different function under the same names. You resume with the same call id. The approved call runs the new function, not the one the person was asked about. This guide shows why, reproduces it, and gives two app-side guards that held 30 of 30 runs without changing the library.

Everything below ran on pydantic-ai 2.77.0 and pydantic-ai-harness 0.77.0 (both the latest on PyPI, uploaded Nov 28, 2026 UTC), Python 3.13.5, Linux, Nov 30, 2026. We used FunctionModel: no network and no API key. The store was InMemoryDeferredStateStore. Each run used fresh agents, a fresh store and fresh sinks. Each row is 30 runs on Agent.run (async) and 30 on Agent.run_sync (sync), in one pass. The reporter used Python 3.14.6 and a source checkout (commit 435f94ca) whose runtime reported 2.77.0.

Who this hits

You are affected if all of these are true:

  1. A parent agent uses SubAgents(forward_deferred_calls=True).
  2. A child tool raises ApprovalRequired, and the parent forwards it to your app as DeferredToolRequests.
  3. Your app stores the deferred state and the message history, and resumes later with the same call id.
  4. Before the resume, the child, or its tool, is replaced by a new implementation registered under the same names. A deployment between the request and the answer is the common case.

If the parent and child are unchanged at resume time, the original implementation runs (30 of 30 runs in our control).

The issue

This is pydantic/pydantic-ai#15231, "Deferred sub-agent approvals resume against a replaced tool implementation". It was opened Nov 30, 2026 (8:00 AM MT) and was still open on Nov 30, 2026.

The reporter asks whether this is the intended behaviour, not only for a change: "Is resolving the current child/tool implementation by name during resume the intended contract? If it is, could the implications for applications that preserve approvals across deployments be documented?"

The author applied the bug label. That is the author's label, not a maintainer decision. There is no human maintainer reply.

There is one comment, from pydanty[bot] at 8:53 AM MT on Nov 30, 2026. It is a bot comment, not a maintainer ruling. In short:

After the comment, the issue had these labels added: needs-maintainer-discussion, area:deferred-tools, p:3-mid, pkg:harness and area:delegation. There is no fix PR.

Related, as the bot named them:

Why it happens

When the child pauses, the harness saves a _StoredState in the DeferredStateStore. In pydantic-ai-harness 0.77.0 (pydantic_ai_harness/sub_agents/_deferred.py) it holds:

class _StoredState:
    agent_name: str
    task: str
    tool_call_id: str | None
    requests: DeferredToolRequests
    messages: list[ModelMessage]

There is no implementation fingerprint or tool version in it.

On resume, delegate_task finds the sub-agent with _resolve_agent, which is a lookup by name (pydantic_ai_harness/sub_agents/_toolset.py):

        sub_agent = self._agents.get(agent_name) or created.get(agent_name)

The resume code then checks that the stored agent_name, task and tool_call_id match this delegate call. If they do, it runs the stored history with your answers on the sub-agent that is registered now. So the approved call goes to whatever tool is registered under that name at resume time. That is how the current code resolves the child; whether it should stay that way is the open question in the issue.

Reproduce it

We ran the issue's script unmodified (issue_script_verbatim.py, the code block copied from the issue). It builds a child whose authorize_action tool raises ApprovalRequired until approved and then appends "{effect}:{account}:{amount}" to a sink list. In short:

store = InMemoryDeferredStateStore()
old_sink, new_sink = [], []
old_parent = make_parent(make_child("old-effect", old_sink), store)
paused = await old_parent.run("start delegation")
requests = paused.output
forwarded = delegated_requests(requests)
call = forwarded.approvals[0]
results = forwarded.build_results(approvals={call.tool_call_id: True})
resume_payload = delegated_results(requests, results)

# Simulate reconfiguration while the approval is pending.
new_parent = make_parent(make_child("new-effect", new_sink), store)
await new_parent.run(
    message_history=paused.all_messages(),
    deferred_tool_results=resume_payload,
)
print("old sink:", old_sink)
print("new sink:", new_sink)

Output on pydantic-ai 2.77.0 and pydantic-ai-harness 0.77.0:

old sink: []
new sink: ['new-effect:demo:25']

This matches the issue and the bot's executed replacement scenario. The approval was raised by the old-effect tool, but the new-effect tool ran.

Results

30 runs per row, one pass, Nov 30, 2026. Each cell is the number of runs, out of 30, with the outcome named in the last column. Async (Agent.run) and sync (Agent.run_sync) matched in every row.

Scenario async sync What the count means
Unguarded resume after replacing the child 30/30 30/30 The new implementation ran: old sink [], new sink ['new-effect:demo:25']
Control: resume on the original parent and child 30/30 30/30 The original implementation ran: old sink ['old-effect:demo:25']
Guard: tool metadata impl_id, v1 stored, v2 registered 30/30 30/30 The guard refused; neither sink was written
Guard: tool metadata impl_id, still v1 30/30 30/30 The resume went through; the original implementation ran
Guard: function fingerprint, implementation swapped 30/30 30/30 The guard refused; neither sink was written
Guard: function fingerprint, same implementation 30/30 30/30 The resume went through; the original implementation ran
Guard: function fingerprint, same effect, a new sink list 30/30 30/30 The fingerprint matched (the list is skipped); the effect ran as old-effect:demo:25 on the new sink
Trap: compare inspect.getsource only 0/30 0/30 30/30 = refused. 0/30: the source was identical, the resume went through and the new implementation ran every time
Trap: compare the child name and tool name only 0/30 0/30 30/30 = refused. 0/30: the names were unchanged, the resume went through and the new implementation ran every time

That is 18 rows of 30 runs, 540 runs in total.

The two trap rows are 0/30 because the check never fired, not because nothing happened. In every trap run, async and sync, the resume went through and the new implementation ran.

The fix: pin the approval to the implementation in your app (no library change)

The idea is the same for both guards. When the run pauses, record which implementation raised the approval. Store that next to the deferred call. Before you resume, compare it to what is registered now. If it differs, do not call run.

1. Recommended: an implementation id in tool metadata

Agent.tool already accepts metadata. Put an id on the tool and change it whenever the behaviour changes:

@child.tool(requires_approval=True, metadata={"impl_id": "authorize_action:v1"})
def authorize_action(ctx: RunContext[Any], account: str, amount: int) -> str:
    if not ctx.tool_call_approved:
        raise ApprovalRequired
    ...

Read it when the run pauses, store it with the approval request, and check it before you resume:

from pydantic_ai import Agent


class ImplementationChanged(Exception):
    """The registered tool is not the one that raised the approval."""


def tool_metadata(agent: Agent, tool_name: str) -> dict | None:
    for ts in agent.toolsets:
        tools = getattr(ts, "tools", None)
        if tools and tool_name in tools:
            return tools[tool_name].metadata
    return None


# When the parent run pauses
paused = await parent.run("start delegation")
stored_id = (tool_metadata(child, "authorize_action") or {}).get("impl_id")
# Save stored_id with paused.all_messages() and the approval request.


# Later, maybe in a new deployment
async def guarded_resume(parent, current_child, history, payload, stored_id):
    current_id = (tool_metadata(current_child, "authorize_action") or {}).get("impl_id")
    if current_id != stored_id:
        raise ImplementationChanged(f"impl_id: {stored_id!r} != {current_id!r}")
    return await parent.run(message_history=history, deferred_tool_results=payload)

With v1 stored and v2 registered, the guard refused in 30 of 30 runs and neither sink was written. With v1 still registered, the resume went through and the original implementation ran in 30 of 30. Async and sync matched. For the sync path, call parent.run_sync(...) in the same place.

If neither tool has an impl_id, both values are None and this check passes. Set the id on every tool that needs approval.

When the guard refuses, you can ask for a new approval for the new implementation instead of resuming the old one. We did not test that step.

Stuck on a Pydantic AI deferred approval or sub-agent resume flow? Send a minimal repro; the fix page lists which frameworks the paid fix covers today.

2. Alternative: a function fingerprint

If you cannot set an id, hash the tool function. Use the source plus the closed-over values that are not containers or callables. That way a closed-over effect tag counts, but a mutable sink list or an inner callable does not:

import hashlib
import inspect


def function_fingerprint(fn) -> str:
    try:
        src = inspect.getsource(fn)
    except OSError:
        src = ""
    closed = []
    if fn.__closure__:
        for name, cell in zip(fn.__code__.co_freevars, fn.__closure__):
            val = cell.cell_contents
            if callable(val) or isinstance(val, (list, dict, set)):
                continue
            closed.append(f"{name}={val!r}")
    raw = "\n".join([fn.__qualname__, src, *closed])
    return hashlib.sha256(raw.encode()).hexdigest()

In our suite the function came from the child's toolset, the same way as the metadata above (tools["authorize_action"].function). Store the fingerprint at pause time and compare it before resume, as in guard 1.

Results: after a swap, the guard refused in 30 of 30 runs and neither sink was written. With the same implementation, the resume went through in 30 of 30. With the same effect but a new sink list, the fingerprint still matched and the effect ran in 30 of 30, because lists are skipped.

A fingerprint only sees what is in the function and its simple closure values. A change elsewhere, for example in a module the tool calls, would not change it. An explicit id does not have that limit, which is why it is the first choice.

3. Traps: source only, or names only

All of these guards are check-then-act. We did not test concurrent resumes of the same stored state.

What we didn't test

FAQ

What happens if I resume a forwarded Pydantic AI sub-agent approval after replacing the child implementation?

The new implementation runs, not the one that raised the approval. With SubAgents(forward_deferred_calls=True), we stored the deferred state and history, replaced the child under the same child and tool names, and resumed with the same call id. The old sink stayed empty and the new one got new-effect:demo:25 in 30 of 30 runs, async and sync, on pydantic-ai 2.77.0 and pydantic-ai-harness 0.77.0. Resuming on the unchanged parent and child ran the original implementation in 30 of 30.

Is this the intended Pydantic AI contract, and have maintainers decided?

Not yet. Issue #15231 asks whether resolving the child and tool by name on resume is the intended contract and, if so, for docs. As of Nov 30, 2026 there is no human maintainer reply. The only comment is from pydanty[bot]: its decision line is maintainer discussion, it recommends keeping and documenting the name-based behaviour unless maintainers want approval identity to survive deployments, and it asks for the policy to be settled in issue #13135. The bug label was applied by the issue author.

Does this still happen in the latest pydantic-ai and pydantic-ai-harness?

Yes. pydantic-ai 2.77.0 and pydantic-ai-harness 0.77.0, both uploaded to PyPI on Nov 28, 2026 UTC, were the latest on Nov 30, 2026. The issue script, run unmodified, printed old sink: [] and new sink: ['new-effect:demo:25']. The stored deferred state holds agent_name, task, tool_call_id, requests and messages, and the resume looks the sub-agent up by name. There is no fix PR.

How do I pin a deferred sub-agent approval to the implementation that raised it without changing the library?

Give the tool an implementation id in its metadata, for example metadata={'impl_id': 'authorize_action:v1'}. Store the id with the deferred call when the run pauses. Before resume, compare it to the currently registered tool's metadata and do not call run if it differs. That refused a swap in 30 of 30 runs and let a matching resume through in 30 of 30, async and sync. If you cannot set an id, a fingerprint of the tool's source plus its simple closure values also held 30 of 30 on a swap and on a match.

Why is comparing only the tool's source or the child name not enough?

Because neither has to change when the behaviour does. In our test both tools came from the same factory, so inspect.getsource was identical and only a closed-over effect string differed. The child and tool names stayed billing_child and authorize_action, which is what the library already matches on. Both checks refused 0 of 30 swaps, and the new implementation ran every time.

Does the site have a tested Pydantic AI template for this?

No. The site has no tested Pydantic AI template. The Durable, typed task runner page is planned, not built or tested yet, and it is about durable tasks, not this approval guard. Note that forward_deferred_calls is not supported under durable execution. The guard in this guide is the tested pattern: 30 of 30 runs on pydantic-ai 2.77.0 and pydantic-ai-harness 0.77.0.

Related

There is no tested Pydantic AI template on the site yet. A planned Durable, typed task runner starter is listed on the templates index as not built or tested yet (there is no page for it yet). It is about durable tasks, not this approval-pinning guard, and forward_deferred_calls is not supported under durable execution. The Human-in-the-loop approval graph is a tested LangGraph starter, not Pydantic AI, and it does not include this guard. You can browse everything in the templates index.

Stuck on a Pydantic AI deferred approval or sub-agent resume flow? Send a minimal repro; the fix page lists which frameworks the paid fix covers today.

Free starter pack

The approval-flow starter pack

Tested human-in-the-loop approval starters for LangGraph, OpenAI Agents SDK, Vercel AI SDK and Google ADK, plus the Agent Signal newsletter. Free.

Get the Agent Signal newsletter