Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
Studio: let search_conversation find this turn's results on API providers (#16666)
Daniel Hand80856cf9af8
diff --git a/studio/backend/core/inference/studio_tool_loop.py b/studio/backend/core/inference/studio_tool_loop.pyindex 7ecc09e2df0..07c0e180bda 100644--- a/studio/backend/core/inference/studio_tool_loop.py+++ b/studio/backend/core/inference/studio_tool_loop.py@@ -1465,8 +1465,18 @@ async def _stream_with_studio_tools(resumes_partial = run.continue_final_message# cap run-owned image parts across the full loop without counting caller attachments.loop_mcp_image_parts: list = list(run.promoted_image_parts)- # preserve the request branch for tools that search conversation history.- request_branch = list(restored)+ # search_conversation filters on this: the request plus every message the loop added, so a+ # result of this turn that a refit evicted stays findable (llama_cpp's _extend_live_branch).+ live_branch = list(restored)+ live_branch_ids = {id(message) for message in conversation}++ def extend_live_branch() -> list[dict]:+ for message in conversation:+ if id(message) not in live_branch_ids:+ live_branch_ids.add(id(message))+ live_branch.append(message)+ return list(live_branch)+remaining = policy.max_callsunlimited = remaining >= 9999session_id = run.session_id@@ -2104,7 +2114,7 @@ async def _stream_with_studio_tools(# once a thread has an archive and needs the same branch: the stored rows are the whole DAG, and Retry# leaves the replaced response in them.if accepts_kwarg(execute_tool, "conversation_branch"):- kwargs["conversation_branch"] = request_branch+ kwargs["conversation_branch"] = extend_live_branch()if approved and accepts_kwarg(execute_tool, "host_access_approved"):kwargs["host_access_approved"] = True# External window is unknowable: 0 keeps the default page cap; unmeasurable budget means one recall, since 8 chunks is ~4K tokens replayed each later call.diff --git a/studio/backend/tests/test_external_tool_edge_cases.py b/studio/backend/tests/test_external_tool_edge_cases.pyindex 9113bc2a3a1..81f93d9be90 100644--- a/studio/backend/tests/test_external_tool_edge_cases.py+++ b/studio/backend/tests/test_external_tool_edge_cases.py@@ -285,6 +285,23 @@ def test_intermediate_done_sentinel_is_not_relayed(executed):assert "the real answer" in _visible_text(lines)+def test_search_conversation_branch_holds_this_turns_tool_results(executed):+ """A refit can evict this turn's results; the branch must still hold them or the archive filters them out (#16602)."""+ transport = FakeTransport(+ [+ _call_turn("c1", "web_search", '{"query":"valve"}'),+ _call_turn("c2", "search_conversation", '{"query":"valve"}'),+ _answer_turn(),+ ]+ )+ _run(transport, tools = [WEB, _tool("search_conversation")])++ [search] = [call for call in executed if call["name"] == "search_conversation"]+ branch = search["conversation_branch"]+ assert branch[0] == {"role": "user", "content": "hi"}+ assert any(m.get("role") == "tool" and m.get("content") == "RESULT<web_search>" for m in branch)++def test_non_json_data_line_is_relayed_untouched(executed):"""Garbage on the wire is passed through, not parsed and not fatal."""transport = FakeTransport(