Skip to content

Start the Langroid Bot on an Anthropic key - #611

Merged
davidmckayv merged 1 commit into
CopilotKit:mainfrom
kevin9327:langroid-anthropic-key
Sep 19, 2026
Merged

davidmckayv merged 1 commit into
CopilotKit:mainfrom
kevin9327:langroid-anthropic-key

Conversation

@kevin9327

Copy link
Copy Markdown
Contributor

What this changes

Picked with an Anthropic key, the Langroid Bot exits on startup.

The harness already names a non-OpenAI model the way Langroid wants, litellm/anthropic/claude-sonnet-4-5. Two things stopped it from getting that far:

  1. An empty OpenAI key. Langroid builds an OpenAI client even for a model it hands to litellm, and reads that client's key from OPENAI_API_KEY as one of its own OPENAI_* settings. For the Anthropic choice the desktop writes that variable empty (env.rs: "Every model key, every time, and empty unless the choice implies it"), and Compose passes it into the harness as "". The client refuses an empty key, so ChatAgent(...) failed at import with openai.OpenAIError: Missing credentials. Please pass an api_key ... or set the OPENAI_API_KEY ... and the container never served a run. With the variable unset, Langroid falls back to its placeholder key. That placeholder is also Langroid's signal to leave the key to litellm and not pass it on (if self.api_key != DUMMY_API_KEY: kwargs["api_key"] = self.api_key in openai_gpt.py). So the harness now removes an empty OPENAI_API_KEY before building the agent, and litellm reads ANTHROPIC_API_KEY itself.
  2. litellm was not installed. It is an extra of Langroid's, not a dependency, and the image installed plain langroid. With only the key fixed, the module still fails at import, now on No module named 'litellm'. The requirement is now langroid[litellm].

The OpenAI key and OpenAI-compatible endpoint choices already worked and are unchanged: both set a non-empty OPENAI_API_KEY, and their model is named bare, as before.

Where it runs

  • New state that outlives a request? None. One environment variable removed from the harness process at import when it is empty.
  • What happens on the second replica? The same. Each harness process reads the same environment.
  • Anything serialised? No.
  • Anything fanned out to a browser? No.
  • New listener, port, or schedule? No. The CI step added here runs beside the harness suites already in python-harness.

Boundary and audit

  • Every acting call still goes through the gateway: nothing on the server changes, and the harness still refuses a request without the server's token.
  • New refusals and new failures each write a row: no new refusal or failure.
  • Nothing new is trusted from the client.

Changelog

  • A line in CHANGELOG.md under Unreleased.

Proof

  • New agent-langroid/tests/test_main.py is agent-llamaindex/tests/test_main.py with the run posted to /, where create_langroid_app serves it. It starts a local fake provider serving /v1/chat/completions and /v1/messages, imports the harness under the environment the desktop writes for each of the three choices, and posts an AG-UI run. It asserts HTTP 200, RUN_FINISHED, no RUN_ERROR, and that the provider got the chosen model on the chosen route.
  • Linux (ubuntu-latest, Python 3.12, a throwaway workflow on my fork running the same commands as the new CI step):
    • This branch: 3 passed.
    • agent-langroid/src from main (2d09a08): 1 failed, 2 passed. [an Anthropic key] fails with OpenAIError: Missing credentials.
    • This branch's source with main's requirements.txt: 1 failed, 2 passed. [an Anthropic key] fails with No module named 'litellm'. So both halves are needed.
  • Windows, Python 3.12: the same three results.
  • Versions: langroid 0.68.0, ag-ui-langroid 0.1.1, litellm 1.101.0.
  • Not run: a real Anthropic key, and the published image.

This adds a step at the end of python-harness and an entry at the top of Unreleased, which #609 and #610 also touch. Whichever lands later needs a rebase, and I'll do it.

🤖 Generated with Claude Code

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

The Langroid Bot names a model from any provider but OpenAI as `litellm/<provider>/<model>`, which
is Langroid's own way of reaching one through litellm. Picked with an Anthropic key it never got
that far, for two reasons.

Langroid builds an OpenAI client even for a model it hands to litellm, and reads the key for it
from `OPENAI_API_KEY` as one of its own settings. Compose writes that variable empty when the
choice was not OpenAI, so the client was built with an empty key and refused: the module failed at
import with `OpenAIError: Missing credentials`, and the container never served a run. Unset, the
setting falls back to Langroid's placeholder, which is also what tells Langroid to leave the key to
litellm rather than pass the placeholder on; litellm then reads `ANTHROPIC_API_KEY` itself. So an
empty `OPENAI_API_KEY` is now removed before the agent is built.

And litellm is an extra of Langroid's rather than a dependency, which the image did not install:
with the key fixed alone, the module still fails at import, on `No module named 'litellm'`. The
requirement is now `langroid[litellm]`.

The test follows the LlamaIndex Bot's. Before this change the Anthropic key choice fails at import
and the OpenAI key and compatible endpoint choices pass.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@davidmckayv
davidmckayv force-pushed the langroid-anthropic-key branch from ecf97e0 to 7147a5c Compare September 19, 2026 01:05
@davidmckayv
davidmckayv merged commit 9bd594c into CopilotKit:main Sep 19, 2026
18 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.

2 participants