Practical technical guides / AI engineering: interoperability (tool call histories, pydantic-ai 2.69.0 of 17 November 2026)

Tool Call IDs Can Repeat Across Responses: Pair Calls With Results per Response and Qualify IDs Before Switching Providers

Two responses both used call_0, so a cache keyed by call id skipped a refund. Key results per response, and qualify ids the way pydantic-ai 2.69.0 does.

By Sandeep Belgavi · Published 2026-11-20

Two responses both used call_0, so a cache keyed by call id skipped a refund. Key results per response, and qualify ids the way pydantic-ai 2.69.0 does.

The refund that was never issued

Dinky reviews help-desk transcripts at Belgavi's Book Store. In one conversation for CASE-2207 the agent looked up order ORD-5531, decided a refund of 18.50 was due, called issue_refund, told the customer the refund was on its way, and moved on. No refund was ever issued.

The transcript showed why only on close reading. The model's first response contained one tool call with id call_0: lookup_order. Its second response contained two calls: issue_refund with id call_0 and another lookup_order with id call_1. The provider numbered tool calls per response, starting again at zero each time. The agent runtime kept a cache of tool results keyed by call id, to avoid re-running a tool when a conversation was replayed. When issue_refund arrived as call_0, the cache already had a result for call_0 (the order lookup), so the runtime returned that result and never ran the refund tool. The model read an order record where it expected a refund confirmation and, as models do, carried on.

Call ids are not always unique across a conversation

Most chat APIs pair a tool call with its result through an id: the model emits a call with an id, the client runs the tool and sends back a result carrying the same id. Many providers generate ids that are unique across everything they ever return. Some only guarantee uniqueness within one response. Both are reasonable contracts; the bug lives in code that assumes the first and meets the second.

Pydantic AI hit this with a provider endpoint that reused call_0, and its 2.69.0 release of 17 November 2026 generalizes the fix. Pull request 13128 adds a model-profile flag, tool_call_ids_are_response_scoped, false by default. When an adapter's profile sets it, the library qualifies every id the provider sends so it is unique across the history, and restores the original id when it replays history to the same provider. The pull request describes the problem in one sentence: a tool call id is often only unique within one response, while much of the library pairs calls and results by id across the whole history.

Two ways to make ids unique, and why one failed

The earlier workaround in that library qualified ids as {response_id}:{call_id}, for example resp_9c41:call_0. That is unique, and it is easy to strip back to the original. It broke when a conversation that started on one provider continued on another: Claude on Amazon Bedrock validates tool-use ids against the pattern ^[a-zA-Z0-9_-]+$, and the colon fails it. The pull request records the rejection.

The new form is {call_id}_{8 base62 characters}, where the eight characters are the low-order base62 digits of the SHA-256 of the response id. call_0 from response resp_7f3a becomes call_0_gf8BbhGy. It stays within the strict character set, stays unique, and can be reversed by removing a suffix computed from the known response id. A response without a provider response id is scoped by a hash of its timestamp instead.

The companion example implements the same rule and checks it against the installed library:

BASE62 = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
STRICT_ID = re.compile(r'^[a-zA-Z0-9_-]+$')


def scope_suffix(response_id, n=8):
    """The low-order n base62 digits of SHA-256(response ID), the same rule pydantic-ai 2.69.0 uses."""
    v = int.from_bytes(hashlib.sha256(response_id.encode()).digest(), 'big')
    out = ''
    for _ in range(n):
        v, r = divmod(v, 62)
        out += BASE62[r]
    return out


def qualify(response_id, call_id):
    return f'{call_id}_{scope_suffix(response_id)}'

The recorded live probe shows the library's qualify_tool_call_id producing the same three ids as this function, restoring the raw id, also restoring an id stored in the old colon form, and DEFAULT_PROFILE carrying the new flag as False.

Replaying CASE-2207 both ways

ExecutorTools runRefunds issuedResult returned for issue_refund
Cache keyed by call idlookup_order, lookup_order0the order lookup record
Cache keyed by response id and call idlookup_order, issue_refund, lookup_order1refunded 18.50
Id form for another providerUniquePasses the strict pattern
Raw provider idsno (call_0 twice)yes
{response_id}:{call_id}yesno
{call_id}_{suffix}yesyes

A validator that pairs results with calls by id alone gets the history wrong in a quieter way: it reports the first lookup_order paired with the refund result. Any audit that relies on such pairing will say the conversation was consistent when it was not.

Where your own code makes the assumption

The library fix covers the paths it owns. Your code may hold its own copy of the assumption in places like these:

  • Tool result caches and idempotency keys. Key them by the conversation, the response and the call id, or by a key the runtime generates. Never by the provider's call id alone.
  • Durable execution and replay. Workflow engines that record activity results by call id will replay the wrong result on resume.
  • Tracing and analytics. Spans named after the call id merge two different calls in dashboards.
  • History storage. If you store messages and later replay them to a different model, convert ids into a form every provider you might switch to accepts, before you need the fallback.
  • Parsing ids. The pull request warns that code which parsed the response id out of the old colon form must read provider_response_id from the response instead.

A runtime-side rule that does not depend on the provider

If you control the runtime, the simplest robust rule is to treat provider ids as opaque labels for pairing within a single response and to assign your own id for everything else. The scoped executor in the example does exactly that:

def run_tools_scoped(history, tools):
    cache, executed, results = {}, [], []
    for resp in history:
        for call in resp['calls']:
            key = (resp['response_id'], call['id'])
            if key not in cache:
                cache[key] = tools[call['name']](**call['args'])
                executed.append(call['name'])
            results.append({'id': qualify(resp['response_id'], call['id']), 'for': call['name'], 'result': cache[key]})
    return executed, results

Failure modes

  • Silent skip. A deduplicating cache returns an earlier tool's result and the side effect never happens, as in CASE-2207. Nothing errors.
  • Wrong pairing on replay. The model sees a result that belongs to a different call and reasons from it.
  • Provider switch rejected. A fallback to another provider fails on the first stored id that violates its pattern, often during an incident, which is when the fallback was needed.
  • Hash collisions. Eight base62 characters give about 2.2 × 10^14 values; collisions within one conversation are not a practical concern, but the suffix is not a security boundary.
  • Over-qualifying. Qualifying ids your runtime generated itself is unnecessary; the library leaves those alone.

What the flag covers at 2.69.0

Read the scope before relying on it. At 2.69.0 the adapters that apply the flag are OpenAIChatModel and OpenAIResponsesModel and their subclasses, for streamed and non-streamed responses. Ids that Pydantic AI generates itself are left alone. Original ids are restored only for responses from the same provider and endpoint that the model accepts server state from, and for the results that follow them; any other provider or endpoint receives the qualified id. History stored in the old colon form is still restored when replayed to Bedrock Mantle. The older openai_responses_tool_call_ids_are_response_scoped key is deprecated and translated to the new key with a deprecation warning. If you build your own adapter for a provider that reuses ids, setting the flag in its profile is now the supported way in.

Tradeoffs

Qualifying every id makes stored history slightly larger and less readable, and requires a restore step when replaying to the original provider, which the library performs only for responses from the same provider and endpoint. Keeping raw ids is simpler and correct for providers with globally unique ids, which is why the flag defaults to off. A runtime-generated id for each call is the most robust option but adds a mapping you must persist alongside the history.

Verification

Write one test with two responses that both contain call_0, one of them for a side-effecting tool, and assert that the side effect happens exactly once per call and that each result pairs with its own call. The companion example's test does that with a refund tool. Add a second test that serializes a history, reloads it and checks every id against the strictest pattern of any provider you may route to. For pydantic-ai, check which model profiles set tool_call_ids_are_response_scoped; at 2.69.0 only Bedrock Mantle's GPT-5 Responses profile does, and the pull request notes that live probes of several other providers found no id reuse.

Running the companion code

cd examples/python/response_scoped_tool_call_ids
python example.py
python -m unittest -v test_example.py
pip install -r requirements.lock.txt && python live_probe.py

The example and tests use the standard library. The live probe imports pydantic-ai-slim 2.69.0 to confirm the suffix rule; no model or provider is called.

Primary references and authorship

Original explanation and synthetic examples by Sandeep Belgavi. Companion code: Sandeep-BA/agent-decision-lab/examples/python/response_scoped_tool_call_ids. Views are my own and do not represent any employer, past or present.