Skip to content

feat: add ANTHROPIC_BASE_URL support#1886

Open
dongjiang1989 wants to merge 1 commit into
kagent-dev:mainfrom
dongjiang1989:add-env
Open

feat: add ANTHROPIC_BASE_URL support#1886
dongjiang1989 wants to merge 1 commit into
kagent-dev:mainfrom
dongjiang1989:add-env

Conversation

@dongjiang1989
Copy link
Copy Markdown
Contributor

@dongjiang1989 dongjiang1989 commented May 18, 2026

Summary

  • Add ANTHROPIC_BASE_URL environment variable support across Go controller and Python ADK, mirroring the existing OPENAI_API_BASE pattern
  • Inject ANTHROPIC_BASE_URL into agent pods when Anthropic provider has a custom BaseURL configured
  • Add unittest test for Anthropic

Copilot AI review requested due to automatic review settings May 18, 2026 13:01
@github-actions github-actions Bot added the enhancement New feature or request label May 18, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds first-class support for overriding Anthropic API base URLs via ANTHROPIC_BASE_URL across the Go controller/runtime env registration and the Python ADK Anthropic model wrapper, plus introduces a new basic-anthropic sample and an E2E test that invokes it against a mock Anthropic server.

Changes:

  • Register and inject ANTHROPIC_BASE_URL into agent pods when an Anthropic model is configured with a custom BaseURL (Go controller).
  • Teach the Python ADK Anthropic model wrapper to read ANTHROPIC_BASE_URL when no explicit base_url is set.
  • Add a basic-anthropic sample (Dockerfile, YAML, agent-card) and a Go E2E test + mock fixture for Anthropic invocation.

Reviewed changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
python/samples/anthropic/basic_agent/README.md Adds a short README for the new Anthropic sample.
python/samples/anthropic/basic_agent/pyproject.toml Defines the sample Python package and dependencies.
python/samples/anthropic/basic_agent/Dockerfile Builds a container image for the Anthropic sample agent.
python/samples/anthropic/basic_agent/basic_agent/agent.py Implements the Anthropic ADK agent + tools and exposes it via KAgent ADK app.
python/samples/anthropic/basic_agent/basic_agent/agent-card.json Adds an A2A agent card artifact for the sample.
python/samples/anthropic/basic_agent/basic_agent/init.py Exposes the sample app object.
python/samples/anthropic/basic_agent/agent.yaml Adds a KAgent Agent CR example for deploying the sample.
python/pyproject.toml Adds Anthropic samples to the uv workspace members list.
python/packages/kagent-adk/src/kagent/adk/models/_anthropic.py Reads ANTHROPIC_BASE_URL from env when creating the Anthropic SDK client.
python/packages/kagent-adk/src/kagent/adk/_a2a.py Logs presence of ANTHROPIC_BASE_URL at app build time.
python/Makefile Adds basic-anthropic-sample docker build target.
Makefile Adds basic-anthropic to the push-test-agent build/push list.
go/core/test/e2e/mocks/invoke_anthropic_agent.json Adds mock Anthropic responses for calculator/weather tool flow.
go/core/test/e2e/invoke_api_test.go Adds E2E test that deploys and invokes the Anthropic BYO agent image against the mock server.
go/core/pkg/env/providers.go Registers ANTHROPIC_BASE_URL env var for agent runtime injection.
go/core/internal/controller/translator/agent/adk_api_translator.go Injects ANTHROPIC_BASE_URL into pods when Anthropic BaseURL is configured.
Comments suppressed due to low confidence (2)

python/samples/anthropic/basic_agent/basic_agent/agent.py:101

  • kagent.adk.KAgentApp stores agent_card without validation and passes it through to A2AFastAPIApplication; in this package the expected type is a2a.types.AgentCard (see kagent/adk/_a2a.py). Passing a plain dict here is likely to fail when the A2A app tries to use AgentCard fields/methods; construct an AgentCard (or call AgentCard.model_validate(...)) before passing it in, similar to python/packages/kagent-openai/src/kagent/openai/_a2a.py.
app = KAgentApp(
    root_agent_factory=lambda: root_agent,
    agent_card={
        "name": "basic-anthropic-agent",
        "description": "A basic Anthropic agent with calculator and weather tools",
        "url": "localhost:8000",
        "version": "0.1.0",
        "capabilities": {"streaming": True},
        "defaultInputModes": ["text"],
        "defaultOutputModes": ["text"],
        "skills": [
            {
                "id": "basic",
                "name": "Basic Assistant",
                "description": "Can perform calculations and get weather information",
                "tags": ["calculator", "weather", "assistant"],
            }
        ],
    },

python/samples/anthropic/basic_agent/basic_agent/agent.py:90

  • The agent card URL/port is inconsistent across the sample: here it's set to localhost:8000, while basic_agent/agent-card.json uses http://localhost:8080 and the container exposes 8080. This inconsistency can break discovery/clients depending on which artifact is used; please standardize the URL (including scheme + port) across the sample.
        "name": "basic-anthropic-agent",
        "description": "A basic Anthropic agent with calculator and weather tools",
        "url": "localhost:8000",
        "version": "0.1.0",
        "capabilities": {"streaming": True},

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread python/samples/anthropic/basic_agent/basic_agent/agent.py Outdated
Comment thread python/packages/kagent-adk/src/kagent/adk/_a2a.py
Comment thread python/packages/kagent-adk/src/kagent/adk/models/_anthropic.py
Copy link
Copy Markdown
Contributor

@EItanya EItanya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks so much for the contribution. Can we leave the new sample agent out of this PR. Frankly the existing sample agents are already causing issues with dependencies and other issues. I think a separate repo with sample agents might be a better long-term solution, but for now can you please remove it.

@dongjiang1989
Copy link
Copy Markdown
Contributor Author

dongjiang1989 commented May 19, 2026

Thanks so much for the contribution. Can we leave the new sample agent out of this PR. Frankly the existing sample agents are already causing issues with dependencies and other issues. I think a separate repo with sample agents might be a better long-term solution, but for now can you please remove it.

Thanks @EItanya
I totally agree. I will remove the sample agent and add corresponding unit test cases. Please review again.

@github-actions github-actions Bot added enhancement New feature or request and removed enhancement New feature or request labels May 19, 2026
@dongjiang1989 dongjiang1989 changed the title feat: add ANTHROPIC_BASE_URL support and basic-anthropic agent sample feat: add ANTHROPIC_BASE_URL support May 19, 2026
@github-actions github-actions Bot added enhancement New feature or request and removed enhancement New feature or request labels May 19, 2026
Signed-off-by: dongjiang <dongjiang1989@126.com>
@dongjiang1989
Copy link
Copy Markdown
Contributor Author

cc @EItanya Please re-check it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants