← Back to Pull requests

Keep the conversation going while tool calls are running #829

Closed
unknown closed this pull request without merging on Nov 17, 2026 10:18 UTC
View on GitHub
unknown unknown commented on Nov 13, 2026 14:31 UTC
Author

Problem

A tool that has not returned blocks the conversation: any turn that arrives while a function call output is missing is rejected with "Cannot generate a response while function call outputs are pending." The user keeps talking and nothing answers. Related: #772, #805.

What changes

A running tool no longer blocks a turn. Stored history is unchanged, and other clients need no change. The one wire-visible change is that a second result for the same call is now rejected.

  • A call without an output is shown to the model with a stand-in tool output saying it is still running.

  • An output that arrives before any later reply sits next to its call, exactly as today.

  • An output that arrives after the conversation moved on is shown where it arrived, as a message marked as not said by the user.

  • While any call is running, the newest user message carries one line listing the running calls. It is rebuilt per request, never stored, and left out of compaction.

  • response.create is still rejected with function_call_output_pending in one case: an incomplete parallel batch with no user speech since.

  • Each call takes one result. A second function_call_output for a call that already has one is rejected with invalid_conversation_item (invalid_input_item as response.create input); main accepted it and showed the model both.

  • The packaged Python client (talk, local) no longer holds a result behind a slower tool from an earlier turn. Results of one response are still delivered in call order with one follow-up; responses do not wait for each other. A follow-up the server holds back leaves the results queued for the next one instead of stopping the client. If more results were queued before that refusal arrived, the client asks once more.
  • The README's "Long-running tools" section describes this, and adds the start-and-notify pattern (return a handle at once, report the outcome later as a marked message) as the approach to prefer when the client controls the tool.

    Why this design

    Each choice was compared against an alternative on live models. "Correct" below means the reply did what the situation called for and nothing else: answered an unrelated question without calling a tool, did not invent a result for a running call, called a newly requested tool, announced a result that landed, and so on.

    Keep the call as a real tool call, with a stand-in result. The alternative in #805's fallback path rewrites tool calls as user-role text records. Keeping the structure the models were trained on does better, mostly on small models, and repeats running calls far less often:

    | 23 models, 1 to 4 tools running, 8 situations, 2,001 requests per arm | This PR | This PR without the status line | #805 fallback rewrite |
    |---|---|---|---|
    | Correct (repeated a running call) | 96% (1%) | 94% (2%) | 88% (8%) |
    | 12 large models | 98% (0%) | 96% (1%) | 99% (0%) |
    | 11 small models | 94% (2%) | 91% (4%) | 77% (17%) |

    Only #805's fallback rewrite was compared, since it is the path that applies to Chat Completions and local backends; its native-async path needs provider support and was not tested.

    Nothing changes when tools return in time. The stand-in and the status line exist only while a call has no output. With every result in before the next reply, the request is identical to main (checked by rendering finished-tool conversations with both versions of the code). Apps whose tools all return at once are unaffected.

    A late result is a marked message where it arrived, not a tool message. Chat templates expect a tool result directly after its call, and by then the model has already replied to later turns, so moving the result back would rewrite history it answered from. Showing it where it arrived keeps earlier requests stable. Two independent implementations use the same shape: Pipecat's async tools (a "still running" tool result, replaced if the result arrives before the conversation moves on, otherwise a later message) and the [background event, not said by the user] messages that voice clients built on this server already send.

    The status line is what keeps several running calls straight. Stand-ins sit next to their calls, which can be many turns back. With one call running the line makes no difference (96% with, 97% without); with more it does:

    | Tools running | With the line | Without |
    |---|---|---|
    | 2 | 95% (2% repeats) | 91% (4%) |
    | 3 | 97% (1%) | 94% (3%) |
    | 4 | 97% (0%) | 92% (2%) |
    | "Is the other one ready?" after one of several finished | 96% (3%) | 78% (17%) |

    The line follows the newest user message instead of ending the request: when a request ended with a fresh tool result, two small models answered the status line instead of relaying the result (93% correct at the end, 97% after the user message). A late result is shown in the user role but does not take the line either: the line stays with what the user last said.

    One rejection is kept on purpose. A client that asks for a follow-up after every result of a parallel batch would otherwise get one reply per result. With the batch still incomplete and nothing new from the user, the request is refused as on main; once the user speaks, the reply goes through with stand-ins for the missing results (99% correct on the parallel-batch situations). An image on its own is not the user speaking, whether it arrives before or after the result.

    Further checks

  • Valid for every provider: no request was rejected in the runs above (6,279 requests, 0 rejections) or in live nine-step conversations through the real Chat Completions and Responses handlers with three tools in flight.

  • Live conversations: on the router models, 116 conversations got three tools in flight and 106 completed every later step; 6 repeated a running call. On a Gemma 4 31B vLLM endpoint, 130 of 130 were fully right.

  • Marker text is not copied into speech: 0 of 4,266 Gemma 4 replies recorded with this change contain the status or result markers.

  • Many calls of one tool: five dances in one reply or over five turns, with 0 to 5 finished, on Gemma 4 31B: 320 of 320 requests correct, no running dance repeated, an explicit "do it again" still calls it.

  • Structure: 20,000 random histories render with every call followed by exactly one output and no orphan outputs; running-tool histories render through the Qwen3, Qwen3.5 and Gemma 4 chat templates.

  • Suite: 4,016 passed and 13 skipped locally at 033619cc.
  • Models: Qwen3.8-2.4T, Qwen3.8-27B, Gemma 4 31B, DeepSeek-V4.1-Flash, DeepSeek-V4-Pro, Kimi-K3.1-Pro, GLM-5.3, MiniMax-M3.1-Flash, Mistral-Large-4, Muse-Spark-Open, Nemotron-3.5-Super, Hy4-preview; small: LFM3-1.7B, Ling-3.0-tiny, granite-4.2-3b, granite-4.2-8b, Qwen3.5-9B, LFM2.5-24B, Nemotron-3.5-Lightning, Gemma 4 26B, Inkling-Small, Qwen3.8-Flash-Next, Muse-Glimmer-30B. All through Hugging Face inference providers.

    Known limits

  • The weakest situation is a second call to a tool that is already running with different arguments (87%). Most of those misses are replies that say "starting that now" without a call, which happens at the same rate with nothing running; showing the phrase and its call as one assistant message fixes most of it and is a separate change.

  • Ling-3.0-tiny is unreliable in every arm (68% here, 72% without the line, 32% with the rewrite).

  • Conversations in these tests are at most nine steps; a long session with many old stand-ins was not tested.

  • Local transformers and MLX backends are covered by unit tests and template rendering, not by live runs.

  • Repeats of a running call are discouraged by wording only (1%); there is no guard in code.

  • The packaged client change is covered by unit tests, not by live microphone runs. The model results above were measured at the model request level and predate it.

  • Within one response, a slow tool still holds back the results of its sibling calls until the user speaks.

  • Nothing retires a running call. A client that drops a tool and never sends an output leaves it listed as running for the rest of the session; the README asks such clients to send an output or delete the call.

  • A late result is shown in the user role, marked but not isolated. Text a tool returns from outside (a web page, a search result) can imitate the markers.

  • Call arguments are repeated in full in the status line and in the late-result message. Cutting them was tried and dropped: two calls that differ only after a long first argument became indistinguishable.

  • Two wording details were added after the measurements above and were not measured: the status line no longer follows a late result, and a late result is closed with [End of tool result] when the user's words follow it in the same message.

  • Whether a result is late depends on a side table that follows each reply through rollback, truncation and renaming. Deciding it from message order alone was tried; it changes how text after a call in the same response is rendered, which main tests pin.
  • Not in this PR

  • Rendering a spoken phrase and its tool call as one assistant message.

  • Voice-rule or pipeline changes for a first request that is answered with a promise and no call.
  • Diff: 650 lines (+487 / -163) across 8 files Reviewer: jackboyla Review duration: 5506m
    All Vouch review confidence checks passed
    Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #829"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 20.5% · Safe to merge
    20.5%