Skip to content

Answer on an Anthropic key from the AG2 Bot, not only on an OpenAI one - #612

Merged
davidmckayv merged 2 commits into
CopilotKit:mainfrom
kevin9327:ag2-anthropic-key
Sep 19, 2026
Merged

davidmckayv merged 2 commits into
CopilotKit:mainfrom
kevin9327:ag2-anthropic-key

Conversation

@kevin9327

@kevin9327 kevin9327 commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

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 read BOT_PROVIDER. The desktop catalogue gives every harness it installs Credential::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 writes BOT_PROVIDER=anthropic and BOT_MODEL=claude-sonnet-4-5, and leaves OPENAI_API_KEY empty. Each run died in the OpenAI client before any request went out:

openai.OpenAIError: Missing credentials. Please pass an `api_key`, ... or set the `OPENAI_API_KEY` ...

AG2 has its own Anthropic client, ag2.config.AnthropicConfig, in the package's anthropic extra. It reads ANTHROPIC_API_KEY and ANTHROPIC_BASE_URL the way the Anthropic SDK does. The harness now builds that config when the provider is anthropic, and OpenAIConfig as before otherwise, so the OpenAI key and OpenAI-compatible endpoint choices are unchanged. The requirement becomes ag2[ag-ui,anthropic,openai].

This is a branch, not the single provider/model string #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 no GOOGLE_API_KEY.

Where it runs

  • New state that outlives a request? None. The config is chosen once at import.
  • What happens on the second replica? The same. Each harness process picks the same config from 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-ag2/tests/test_main.py is agent-llamaindex/tests/test_main.py with the run posted to /, where the harness mounts AG2's ASGI app. 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. With agent-ag2/src from main (2d09a08): 1 failed, 2 passed. [an Anthropic key] fails with the OpenAIError above.
  • Windows, Python 3.12: the same results.
  • Versions: ag2 1.0.5, anthropic 1.7.0, openai 3.16.2.
  • 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, #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_URL to an empty string. AG2's Anthropic client passed that through instead of selecting the official endpoint. The harness now explicitly uses https://api.anthropic.com for 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

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

kevin9327 and others added 2 commits September 18, 2026 18:17
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
davidmckayv merged commit 28acd25 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