Answer on an Anthropic key from the AG2 Bot, not only on an OpenAI one - #612
Merged
Merged
Conversation
kevin9327
requested review from
MikeRyanDev,
davidmckayv,
guidovizoso,
mxmzb and
tylerslaton
as code owners
September 18, 2026 22:40
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
9 tasks
The AG2 Bot built `OpenAIConfig(model=BOT_MODEL)` whatever the setup screen chose and never read `BOT_PROVIDER`. The catalogue offers every harness it installs with any model the screen offers, so AG2 can be picked with an Anthropic key: the desktop then writes `BOT_PROVIDER=anthropic`, `BOT_MODEL=claude-sonnet-4-5` and an empty `OPENAI_API_KEY`, and every run failed inside the OpenAI client with `OpenAIError: Missing credentials` before any request was made. AG2 reaches Anthropic through its own `AnthropicConfig`, from the `anthropic` extra, which reads `ANTHROPIC_API_KEY` and `ANTHROPIC_BASE_URL` the way the Anthropic SDK does. The harness now picks that config when the provider is `anthropic` and `OpenAIConfig` otherwise, so an OpenAI key and an OpenAI-compatible endpoint behave as they did. AG2 has no LiteLLM config to route through, which is why this is a branch rather than one `provider/model` string as in the LlamaIndex Bot. The test follows the LlamaIndex Bot's. Before this change the Anthropic key choice fails and the other two pass. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
davidmckayv
force-pushed
the
ag2-anthropic-key
branch
from
September 19, 2026 01:17
e723b76 to
e547c2b
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 this changes
Picked with an Anthropic key, the AG2 Bot fails every run.
The harness built
OpenAIConfig(model=BOT_MODEL)whatever the setup screen chose, and never readBOT_PROVIDER. The desktop catalogue gives every harness it installsCredential::AnyProvider("Every harness on the list takes any model through an API key"), so AG2 can be paired with an Anthropic key. The desktop then writesBOT_PROVIDER=anthropicandBOT_MODEL=claude-sonnet-4-5, and leavesOPENAI_API_KEYempty. Each run died in the OpenAI client before any request went out:AG2 has its own Anthropic client,
ag2.config.AnthropicConfig, in the package'santhropicextra. It readsANTHROPIC_API_KEYandANTHROPIC_BASE_URLthe way the Anthropic SDK does. The harness now builds that config when the provider isanthropic, andOpenAIConfigas before otherwise, so the OpenAI key and OpenAI-compatible endpoint choices are unchanged. The requirement becomesag2[ag-ui,anthropic,openai].This is a branch, not the single
provider/modelstring #533 gave the LlamaIndex Bot, because AG2 has no LiteLLM config to route through. Google is left out: the setup screen offers no Google key, and Compose passes the harness noGOOGLE_API_KEY.Where it runs
python-harness.Boundary and audit
Changelog
CHANGELOG.mdunderUnreleased.Proof
agent-ag2/tests/test_main.pyisagent-llamaindex/tests/test_main.pywith the run posted to/, where the harness mounts AG2's ASGI app. It starts a local fake provider serving/v1/chat/completionsand/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, noRUN_ERROR, and that the provider got the chosen model on the chosen route.ubuntu-latest, Python 3.12, a throwaway workflow on my fork running the same commands as the new CI step). This branch:3 passed. Withagent-ag2/srcfrommain(2d09a08):1 failed, 2 passed.[an Anthropic key]fails with theOpenAIErrorabove.ag21.0.5,anthropic1.7.0,openai3.16.2.This adds a step at the end of
python-harnessand an entry at the top ofUnreleased, which #609, #610 and #611 also touch. Whichever lands later needs a rebase, and I'll do it.Default endpoint regression
The default Compose environment sets
ANTHROPIC_BASE_URLto an empty string. AG2's Anthropic client passed that through instead of selecting the official endpoint. The harness now explicitly useshttps://api.anthropic.comfor a blank override and preserves a nonblank custom URL.The additional authenticated AG-UI regression uses the real framework and Anthropic SDK, replacing only HTTP transport. It checks the official URL, API-key header, chosen model, answer, and successful run completion. All four tests pass locally, including the original provider cases. This is SDK integration coverage; no live Anthropic account or published image was exercised.
🤖 Generated with Claude Code