Skip to content

Reach the model the setup screen chose from the LlamaIndex Bot, not only an OpenAI one - #533

Merged
davidmckayv merged 2 commits into
CopilotKit:mainfrom
zopeVaibhav:fix/llamaindex-model-choice
Sep 14, 2026
Merged

davidmckayv merged 2 commits into
CopilotKit:mainfrom
zopeVaibhav:fix/llamaindex-model-choice

Conversation

@zopeVaibhav

Copy link
Copy Markdown
Contributor

Fixes #532

What this changes

The LlamaIndex Bot built OpenAI(model=BOT_MODEL) and never called the _model_id() written above it, so it worked only with an OpenAI model name sent to api.openai.com. With an Anthropic key every run failed with Unknown model 'claude-sonnet-4-5', with an OpenAI-compatible endpoint every run failed with Unknown model for that endpoint's model, and an OpenAI model name behind a compatible endpoint went to OpenAI instead, because the client reads OPENAI_API_BASE and Compose passes OPENAI_BASE_URL.

It now builds LiteLLM(model=_model_id()) from llama-index-llms-litellm, which is how the Agno Bot already reaches a model and why _model_id() has that shape. LiteLLM routes anthropic/... to Anthropic with ANTHROPIC_API_KEY and ANTHROPIC_BASE_URL, and openai/... to OPENAI_BASE_URL when it is set, so the three setup choices reach the model they name without any per-provider branching here.

Two LlamaIndex specifics needed handling, both found by running it rather than by reading:

  • The AG-UI workflow asserts that its model is a function-calling model, and LiteLLM only knows that for models in its catalogue. openai/local-model came back false and the router refused to start the run. When LiteLLM does not know the configured model, the harness registers it as a chat model that can call tools. The person named that model on the setup screen and the Bot cannot work at all otherwise.
  • LlamaIndex's LiteLLM class sends temperature=0.1, which LiteLLM refuses for gpt-5.5 as a reasoning model. Before this change that combination worked, so without handling it the fix would have broken the default OpenAI path. The client is built with drop_params, scoped to this one client rather than set globally, so a parameter a model does not accept is dropped instead of failing the run.

Deliberately left alone: the ChatGPT and Claude plan choices, which go through their own dedicated Bots, the catalogue, and every other harness. llama-index-llms-openai is removed from the requirements because nothing imports it now.

Where it runs

  • New state that outlives a request? No. litellm.register_model adds one entry to LiteLLM's in-process model table when the module loads, for the single model this container was started with.
  • What happens on the second replica? The same thing: each harness process reads the same environment at import and registers the same entry. Nothing is shared or coordinated.
  • Anything serialised? No.
  • Anything fanned out to a browser? No.
  • New listener, port, or schedule? No. The CI step added runs the new test beside the two harness test suites already there.

Boundary and audit

Nothing on the server side changes, and the harness still refuses every request without the server's token. Two things do widen, stated so a reviewer does not have to find them. A model LiteLLM does not know is now assumed able to call tools; if an endpoint cannot, a run that offers tools fails at that endpoint instead of never starting. And a parameter a model rejects is dropped silently rather than returned as an error. The image also grows, from 612 MB to 869 MB in local builds, because LiteLLM is a larger dependency than the OpenAI client; agent-adk, agent-agno and agent-strands already ship it.

Changelog

A line under Unreleased.

Proof

  • New agent-llamaindex/tests/test_main.py starts a local fake provider serving /v1/chat/completions and /v1/messages, imports the harness under the environment the desktop writes for each choice, and posts an AG-UI run. It asserts HTTP 200, RUN_FINISHED, no RUN_ERROR, and that the fake provider received the chosen model on the chosen route. Against main (a97f775) all three fail: Unknown model 'claude-sonnet-4-5', Unknown model 'local-model', and for the OpenAI case a 401 from api.openai.com itself, because the base URL was ignored. On this branch: 3 passed.
  • The image built from this branch's Dockerfile, run with a fake provider and api.openai.com / api.anthropic.com pointed at loopback: the Anthropic choice reaches POST /v1/messages for claude-sonnet-4-5, the compatible endpoint reaches POST /v1/chat/completions for local-model, and gpt-5.5 reaches the endpoint under both OPENAI_BASE_URL and OPENAI_API_BASE. All four runs end RUN_FINISHED with the fake provider's answer in the stream.
  • The same four runs against the published v0.0.10 image: HTTP 500 twice, a connection error to api.openai.com once, and only the OPENAI_API_BASE control answering. The published v0.0.10 Agno image, given the Anthropic environment, reaches /v1/messages, which is the behaviour this brings LlamaIndex in line with.
  • Versions resolved on this branch: llama-index-core 0.14.24, llama-index-llms-litellm 0.8.0, litellm 1.100.1, llama-index-protocols-ag-ui 0.5.0.
  • Not run: a real Anthropic or OpenAI key, and the new CI step itself, which runs on this pull request.

@zopeVaibhav
zopeVaibhav force-pushed the fix/llamaindex-model-choice branch 4 times, most recently from ec5c5ff to 00afa60 Compare September 14, 2026 16:45
@zopeVaibhav
zopeVaibhav force-pushed the fix/llamaindex-model-choice branch from 00afa60 to 815cbdc Compare September 14, 2026 16:49
@davidmckayv
davidmckayv merged commit 841e9f0 into CopilotKit:main Sep 14, 2026
16 checks passed
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.

The LlamaIndex Bot only answers with an OpenAI model sent to OpenAI

2 participants