Repository navigation
LlamaIndex Bot: send earlier steps as real tool calls, so a long job finishes - #2441
Merged
Merged
Conversation
davidmckayv
requested review from
MikeRyanDev,
dustywusty,
guidovizoso,
mxmzb,
samjulien and
tylerslaton
as code owners
November 29, 2026 02:09
…finishes LlamaIndex's AG-UI package (llama-index-protocols-ag-ui 0.7.0, the latest) reads the thread with each earlier tool call as <tool_call> text in the assistant's message and each result as a message from the person. Every step of a job is a run of its own and replays the whole thread, so Claude Sonnet 5.5 saw two or three steps of that text, stopped calling tools and never answered. Upstream: run-llama/llama_index issue 23500, fix in pull request 23501, unreleased. The Bot's LiteLLM client now sends each earlier call as the model's own tool call and each result as a tool message for it, with a step that only called a tool sent with no words (LiteLLM otherwise writes it to Claude as "[System: Empty message content sanitised ...]", which Claude then said to the person). Only what the model is sent changes; the snapshot and the person's thread are as before. It also gets the progress reminder every Python Bot has (shared/progress_reminder.py, read as the LiteLLM Bots read it): after five silent tool steps, one model-only reminder, reset by a line from the model.
davidmckayv
force-pushed
the
fix/llamaindex-tool-history
branch
from
November 29, 2026 02:28
a9700cd to
f1bee9f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
The LlamaIndex Bot now finishes long tool jobs. Every earlier step of a job reaches the model as the tool call and tool result it was, not as text, and the Bot gets the same progress reminder as the other engines: after five silent tool steps, one reminder the model alone sees, reset by a line from the model.
Why
Each step of a job is a run of its own, so every run replays the whole thread to the model. LlamaIndex's AG-UI package (
llama-index-protocols-ag-ui0.7.0, the latest release, which this Bot installs) turns each earlier tool call into<tool_call><name>...</name><arguments>...</arguments></tool_call>text inside the assistant's message, and each tool result into a plain message from the person. Live, Claude Sonnet 5.5 read two steps of that, then stopped calling tools and never answered.Upstream: run-llama/llama_index issue 23500 ("prior tool calls are sent to the LLM as <tool_call> text, so models stop making native tool calls"), fixed by pull request 23501, which is open and unreleased. No release or option of the package sends them natively, so this works around it in the Bot. It can come out once a release carries that fix; it also keeps working with it, since it reads the same
ag_ui_tool_callsandtool_call_idthe fixed package keeps.How
agent-llamaindex/src/sent.py, applied in the Bot's LiteLLM client (_prepare_chat_with_tools), so it touches only what each model call sends. The package's own messages, its MESSAGES_SNAPSHOT and the thread the person sees are unchanged.ag_ui_tool_callsis sent as the model's owntool_calls(LiteLLM turns them intotool_usefor Claude), with the<tool_call>text removed and any words the model said kept.tool_call_id) is sent as atoolmessage for that call (tool_resultfor Claude)."", and LiteLLM sends Claude an empty turn as[System: Empty message content sanitised to satisfy protocol]as though the model had said it. In the first live run of this fix, Claude repeated that line to the person on 5 or 6 of 30 steps.shared/progress_reminder.py, since One progress reminder rule for every Python Bot #2443), read as the LiteLLM Bots read it (every chat message a step of its own; a system message for OpenAI's own models, a note in the turn for the rest): worked out from the thread on every call, so it stays where it was first sent, never in the run's events or the thread. The Dockerfile copies that file.Tests
Driven through the Bot's real AG-UI endpoint as the server drives a job (each step a run, its call handed back, answered, and the whole thread sent back), with real LiteLLM and the shared scripted provider (
shared/progress_reminder_contract.py); read on the requests the provider receives and the AG-UI events.tests/test_tool_history.py(Claude and GPT): every request carries each earlier step as a tool call with its id, name and arguments, followed by its result for that id; no<tool_call>text and no sanitised placeholder anywhere; the job ends with its answer, and the person's thread keeps each call as it was made.tests/test_progress_reminder.py: a silent 30-step job is reminded once, right after step 5's result, and it stays in place with an unchanged prefix; a 4-step job never; lines on steps 5 and 12 move the reminders to after steps 10 and 17; GPT gets a system message, other models a note in the turn; never in any event or snapshot.Red on main, green here (the new tests run against origin/main's engine): 6 failed, 14 passed on main; 20 passed on this branch. The empty-words check alone fails with the
Noneline taken out.Live, Claude Sonnet 5.5, the 30-step ledger job (
L= a line,.= a silent step)L.L.L.....L.....L.....L.....L.....L.....L.....L.....L.....L.....In the web app, Chromium and WebKit
The real product on a fresh stack, with the Personal Assistant powered by a picked LlamaIndex harness built from each commit, on Claude Sonnet 5.5, asked to weigh 24 crates one at a time with an app's scale and give the total (498 kg).
<tool_call>written as textOn this branch the lines read as the Bot's own ("Crates 1 to 12 are weighed... I'm weighing crate 13 next."), the steps fold under "Used Fernhill Shed" between them, and neither the reminder, the sanitised placeholder nor any
<tool_call>text reaches the screen, before or after a reload. Asked without "one at a time", Claude weighs all 24 in one step on both, and both answer.