skip to content

How should a model gateway translate tool definitions, tool calls and tool results between providers whose call identifiers, parallel-call support and result placement differ?

level: seniorimportance: should knowfreq 38%

answer

  1. definitions, calls, results: three translations
  2. schema keyword subsets differ
  3. mint ids when the provider has none
  4. no per-conversation state on replicas
  5. parallel history rewritten as sequential pairs

basics

~20 s

Treat definitions, calls and results as three translations: check schemas and tool-choice modes against what the target supports, mint call identifiers the next turn can map back without gateway state, and rebuild where results go, reporting any lossy rewrite.

solid answer

~50 s

Most providers describe a tool as a name, a description and JSON Schema parameters, but they accept different schema keyword subsets and name rules, and not every tool-choice mode exists everywhere, so the gateway validates against the target and rejects what it cannot carry. Calls differ in argument form, a JSON-encoded string or a parsed object, and in identifiers: where a provider mints none, the gateway mints its own, derived from turn and position so any stateless replica can map results back on the next turn. Results go in a tool-role message in some shapes and in result blocks inside the next user turn in others, with ordering rules and an error flag only some support. When history holds parallel calls and the target lacks them, rewrite them as sequential call-and-result pairs, or reject, and report the rewrite.

code

json · 10 lines
json
{
  "messages": [
    {"role": "assistant", "tool_requests": [
      {"id": "gw_t4_0", "name": "get_order", "arguments": "{\"order\": \"A17\"}"},
      {"id": "gw_t4_1", "name": "get_refund_policy", "arguments": "{\"region\": \"EU\"}"}
    ]},
    {"role": "tool_result", "request_id": "gw_t4_0", "content": "{\"status\": \"shipped\"}"},
    {"role": "tool_result", "request_id": "gw_t4_1", "content": "30 days", "is_failure": false}
  ]
}

go deeper

for a junior

Recall that a tool round trip has definitions, calls and results, and that providers place tool results in different turns.

for a middle

Explain the argument-form and call-identifier differences, why name rewrites must be reversed, and why unsupported tool-choice modes should be rejected.

for a senior

Show stateless id derivation from turn and position, rebuilding result placement, and rewriting parallel history as sequential pairs with a reported adjustment.

for a principal

Weigh how much tool-shape divergence the gateway absorbs versus rejects, and how golden-transcript testing is owned as providers and alias targets change.

## Three translations, not one A tool round trip passes through the gateway three times: the **definitions** go out with the request, the model's **tool calls** come back in the response, and the caller's **tool results** go out again in the next request. Each crossing has to be translated between the gateway's shape and the provider's, and each one can lose something. | aspect | how providers differ | the gateway's job | |---|---|---| | definitions | supported JSON Schema keywords, tool-name characters and length | validate against the target; map names reversibly | | tool choice | auto, none, required, one named tool: not all exist everywhere | reject a mode the target lacks | | call arguments | a JSON-encoded string or a parsed object | pick one form in its own shape | | call identifiers | minted by the provider, or none at all | mint stable ids when absent | | parallel calls | supported, switchable, or unsupported | never promise what the target cannot do | | result placement | a tool-role message per result, or result blocks in the next user turn | rebuild the turn structure | | error flag on a result | a field in some shapes, absent in others | carry it, or encode it and report the loss | ## Definitions and tool choice Most providers describe a tool the same way, a **name**, a **description** and **parameters as JSON Schema**, which is why translation looks easy. The differences sit in the details: - Some providers accept only a **subset of JSON Schema keywords**. Removing a constraint keyword changes the contract the model is held to, so the gateway should reject a schema it cannot carry. Stripping non-constraining annotations is a reportable adjustment at most. - **Name rules** (allowed characters, maximum length) differ. If the gateway rewrites a name to fit, it must map it back in the returned calls, or the caller's dispatcher will not recognise its own tool. - **Tool-choice modes** are not universal. A target with no way to require a tool call cannot honour "required"; imitating it with prompt text is best-effort at most, so the honest default is to reject. ## Identifiers without gateway state Callers pair each result with its call by identifier. Some providers mint identifiers; others return calls without any and pair results by name and position. The gateway must therefore **mint identifiers** for those providers. The trap is where the mapping lives. A gateway runs as stateless replicas, and the next turn may reach a different replica, so an in-memory map of gateway ids to provider pairing breaks. Make the mapping **recoverable from the conversation itself**: 1. Where the provider minted an id, wrap or reuse it so the gateway id carries it. 2. Where the provider minted none, derive the gateway id from the assistant turn's index and the call's position in it. 3. On the next request, compute the provider's pairing from the history the caller sends: by the embedded id, or by turn and position. ## Results and their placement Some shapes expect **one tool-role message per result**, each naming its call id; others expect the results as **blocks inside the next user-role turn**, often all results of one batch together and directly after the calls. The gateway rebuilds the turn structure the target requires. An **error flag** on a result exists in some shapes and not others; where it is missing, the gateway can mark the failure in the result's text, but that is a lossy rewrite and should appear in the response's adjustments. ## Parallel calls the target lacks Take a conversation whose history holds an assistant turn with **two parallel calls**, made earlier against a provider that supports them, now routed to one that does not. Two honest options: - **Rewrite** the history as two sequential pairs: call A, result A, call B, result B. No result is lost, but the transcript the model sees now shows two turns instead of one, so report the rewrite. - **Reject** when the caller needs the transcript reproduced exactly, as an evaluation harness might. Going forward, the gateway cannot make a model emit parallel calls it does not support. A caller's request to allow parallel calls is a preference the gateway may drop with a note; the caller's loop must handle one call per turn regardless. ## Testing the translation Keep **golden transcripts**, real multi-turn tool conversations, per provider, and check two properties: translating a transcript to the provider's shape and back yields the original apart from reported adjustments, and each provider accepts the translated history. Run them whenever a provider or an alias target changes. What makes tool calls dependable (invented arguments, out-of-range values, forcing a call), and the general protocol of how an agent pairs results with calls, are separate subjects; the gateway only has to carry them across providers without losing or mispairing anything.

  • Why not keep a map of gateway call ids to provider pairing in a shared cache instead of deriving them?
    It works, but it adds a stateful dependency to every tool turn, with expiry, eviction and outage behaviour of its own, and a conversation resumed after the entry expires breaks. Deriving ids from turn and position, or embedding the provider's id, puts everything needed in the history the caller already sends, so any replica can translate any turn.
  • A schema keyword your target provider does not support is only a format hint. Can the gateway strip it?
    Only if it is truly non-constraining, such as a description or an example, and then as a reported adjustment. If the keyword limits valid values, such as an enumeration or a pattern, stripping it widens what the model may send and moves a validation burden onto the caller without telling them. Reject, or let the caller send a schema the target supports.
  • How do you test that tool-call translation is faithful across providers?
    Keep golden multi-turn tool transcripts per provider and assert two properties: translating to each provider's shape and back returns the original apart from reported adjustments, and the provider accepts the translated history. Include parallel calls, failed results and renamed tools, and rerun the suite whenever a provider changes or an alias moves to a new target.

  • Tool calls translate trivially because every provider uses JSON Schema identically.
  • A replica can keep each conversation's call-id map in its own memory.
  • If the provider returns no call ids, the gateway's shape can omit ids too.
  • A model without parallel calls will emit them if the gateway asks in the prompt.
  • Stripping an unsupported constraint keyword from a tool schema is harmless.