Repository navigation
Description
Description
When a model's response holds reasoning before a gateway-executed call (MCP, web search, or hosted tool search), a
previous_response_id continuation sends the model that call and its output before the reasoning that led to it.
The live round and a store: false replay of the public output keep the original order, so the continuation does not
share the live round's prompt prefix (no prompt-cache reuse), and a reasoning model reads its reasoning after the
action it produced.
Steps to reproduce
- Run the gateway against a reasoning model on vLLM (seen with
Qwen/Qwen3.6-35B-A3B-FP8), with a logging proxy
between the gateway and vLLM so the upstream request bodies can be read. POST /v1/responseswithstore: true, hosted tool search and one deferred function:The response output is{"model": "Qwen/Qwen3.6-35B-A3B-FP8", "store": true, "input": "What's the weather in Paris right now? The get_weather tool is deferred: first call tool_search with paths [\"get_weather\"] to load it, then call get_weather for Paris.", "tools": [{"type": "tool_search"}, {"type": "function", "name": "get_weather", "description": "Get the current weather for a city", "parameters": {"type": "object", "properties": {"city": {"type": "string"}}, "required": ["city"], "additionalProperties": false}, "strict": true, "defer_loading": true}]}reasoning, tool_search_call, tool_search_output, reasoning, function_call(get_weather).- Continue with
previous_response_idset to that response and afunction_call_outputforget_weather. - Compare the input of the upstream request for step 3 with the input of the live second round in step 2, and with
astore: falserequest whose input is the user message, step 2's output and the samefunction_call_output.
Expected behavior
The continuation sends the stored history in the order it happened, the same as the live round and a store: false
replay: user, reasoning, function_call(tool_search), function_call_output, reasoning, function_call(get_weather), function_call_output.
Actual behavior
The continuation sends user, function_call(tool_search), function_call_output, reasoning, reasoning, function_call(get_weather), function_call_output: the gateway call and its output come before the reasoning that
preceded them.
Cause: without a session continuation lease (a first turn, or conversation mode), record_round_history
(executor/engine/agent_turn.rs) records only the gateway calls, append_gateway_results
(executor/gateway/history.rs) adds their outputs to new_input_items, and persistence writes new_input_items
before the round's output items, where the reasoning is. A response with a continuation lease (a WebSocket session)
records reasoning in place and is not affected.
Environment
- agentic-api: PR feat: execute hosted tool_search over deferred functions, namespaces, and MCP servers #472 branch (
hosted-tool-search), run before 4608829.mainrecords history the same way:
record_round_historyhas the same two branches, andappend_tool_outputs(renamedappend_gateway_resultsin
feat: execute hosted tool_search over deferred functions, namespaces, and MCP servers #472) pushes the gateway outputs tonew_input_items. - Upstream: vLLM serving
Qwen/Qwen3.6-35B-A3B-FP8.
Additional context
- Observed live with hosted tool search during feat: execute hosted tool_search over deferred functions, namespaces, and MCP servers #472's end-to-end verification. MCP and web search calls are
recorded by the same path, so the same reordering applies to them; that part is from reading the code, not a
separate run. - Fix direction: record each gateway call's history at its position in the public output (interleaved with the
round's recorded output items) instead of after the request's input, keeping the duplicate skip feat: execute hosted tool_search over deferred functions, namespaces, and MCP servers #472 adds to
the storage writers (is_already_in_history); add a test with reasoning before a call for each gateway tool.
Activity
Than0316 commentedon Nov 1, 2026
Hi @haoshan98, thanks for the detailed write-up. Are you planning to fix this yourself, or would a contribution be welcome?
If it's open, I'd follow the direction in the issue: record each gateway call at its position in the round's output instead of after the request input, keep the
is_already_in_historyskip from #472, and add a test with reasoning before a call for each gateway tool. The test would check the continuation's input against the live round's order using the mock upstream, likehosted_tool_search_projection_test.rs. Happy to take a different approach if you prefer.GCSimba commentedon Nov 6, 2026
@Than0316 are you working on this? If not, I'd be glad to take it, following the direction in the issue: record each gateway call at its position in the round's output instead of after the request input, keep the
is_already_in_historyskip from #472, and add a continuation test where reasoning precedes a hosted tool search call. @haoshan98 does that match what you had in mind?Than0316 commentedon Nov 12, 2026
Update: I re-checked on current main. #505 fixed this for tool search, web search and MCP (regression tests in #519), but file_search (added in #486 after #505) still sends the reasoning after the search on a
previous_response_idcontinuation. I have a failing test for it.@franciscojavierarceo are you planning to fix the file_search case, or would you like me to? @GCSimba @haoshan98 for visibility.
test: keep reasoning before gateway calls on previous_response_id con…
chore: document what a turn persists and update the roadmap (#533)