Skip to content

LlamaIndex Bot: send earlier steps as real tool calls, so a long job finishes - #2441

Merged
davidmckayv merged 1 commit into
mainfrom
fix/llamaindex-tool-history
Nov 29, 2026
Merged

davidmckayv merged 1 commit into
mainfrom
fix/llamaindex-tool-history

Conversation

@davidmckayv

@davidmckayv davidmckayv commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

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-ui 0.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_calls and tool_call_id the 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.

  • An assistant message carrying ag_ui_tool_calls is sent as the model's own tool_calls (LiteLLM turns them into tool_use for Claude), with the <tool_call> text removed and any words the model said kept.
  • A tool result the package made a person's message (it keeps the tool_call_id) is sent as a tool message for that call (tool_result for Claude).
  • A step that only called a tool is sent with no words at all. LlamaIndex's LiteLLM client writes no words as "", 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.
  • The progress reminder is every Python Bot's one rule and wording (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 None line taken out.

Live, Claude Sonnet 5.5, the 30-step ledger job (L = a line, . = a silent step)

steps answer pattern
main, run 1 2 none L.
main, run 2 2 none L.
this branch, run 1 30 $5,305 (right) L.....L.....L.....L.....L.....
this branch, run 2 30 $5,305 (right) 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).

Chromium WebKit
main stops after 3 weighings; the person sees the opening line and nothing more, the model's last turn a <tool_call> written as text stops after 2 weighings, the same
this branch all 24, 498 kg, 4 lines (start, after 6, 12 and 18) all 24, 498 kg, 4 lines

On 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.

…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
davidmckayv force-pushed the fix/llamaindex-tool-history branch from a9700cd to f1bee9f Compare November 29, 2026 02:28
@davidmckayv
davidmckayv merged commit 0d02888 into main Nov 29, 2026
37 checks passed
@davidmckayv
davidmckayv deleted the fix/llamaindex-tool-history branch November 29, 2026 02:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant