Skip to content

feat(models): add a native xAI provider - #3561

Closed
bwong05umd wants to merge 4 commits into
kagent-dev:mainfrom
bwong05umd:feat/xai-provider
Closed

bwong05umd wants to merge 4 commits into
kagent-dev:mainfrom
bwong05umd:feat/xai-provider

Conversation

@bwong05umd

Copy link
Copy Markdown

Summary

Adds a native xAI model provider, following the Mistral pattern from #2406. xAI's API is OpenAI-compatible (POST /v1/chat/completions with a Bearer key), so both runtimes reuse their OpenAI clients with xAI defaults.

This resolves the three gaps the issue lists:

  • Calls: provider: xAI reaches https://api.x.ai/v1 with XAI_API_KEY, and XAI_API_BASE overrides the URL. Users no longer need an OpenAI config with a hand-written base URL.
  • Egress: the agent egress policy allows https://api.x.ai:443, or only the configured base URL when one is set. Credentials are bound to that origin with authorization: Bearer.
  • Traces: ProviderName returns conv.GenAIProviderNameXAI (x_ai) instead of openai.

Commits, in review order:

  1. feat(api): the xAI enum value, an XAIConfig block (baseUrl, temperature, topP, maxTokens, timeout) with a CEL rule, and ADKXAI as oneof field 21. Generated output is included; make proto-breaking passes.
  2. feat(adk): Go XAIModel and Python KAgentXAILlm wrap the OpenAI clients. Both send the token limit as max_completion_tokens, because xAI's chat completions reference marks max_tokens as deprecated.
  3. feat(models): translation, Secret mounting, credential binding, egress, tracing, and a static catalog. Every model ID comes from docs.x.ai, whose per-model pages each list function calling. grok-4.7 comes first, as the default.
  4. feat(ui): the model form's display name, docs links and token passthrough, plus a providers.xAI Helm entry.

Fixes #3543

Test plan

Following the issue's test plan, with no live key:

  • A local HTTP server receives POST /v1/chat/completions for grok-4.7 with Authorization: Bearer <key>, and the body sets max_completion_tokens but not max_tokens. This is covered in Go (xai_test.go) and Python (test_xai.py).
  • An xAI ModelConfig resolves its Secret, allows https://api.x.ai:443, and compiles a runtime config whose provider is xai. Covered by compiler_test.go, builder_test.go and model_test.go.
  • ProviderName(ModelProviderXAI) is x_ai (otel_test.go).
  • Also covered: CEL validation (envtest), key and base URL precedence, token passthrough, ActorJWT placeholders, the provider and model catalogs over gRPC, and the shared Go/Python runtime config fixture.

Run locally:

  • make -C go lint: 0 issues.
  • make proto-lint proto-generate proto-breaking, and make controller-manifests with no drift.
  • go test for api/..., adk/..., core/internal/translator/..., core/internal/service/model and core/internal/grpcserver.
  • The full kagent-adk unit suite, and ruff format / ruff check.
  • yarn typecheck, yarn lint (no new warnings) and yarn test.
  • helm template with providers.default=xAI, including a rendered config: block.

Not run locally, left for CI:

  • Postgres-backed and envtest gRPC tests, because Docker and envtest binaries were unavailable. They are in packages this change does not touch.
  • Python TLS e2e tests, which need certificates that make test generates.
  • helm unittest.
  • A live call to xAI.

Notes for reviewers

  • One PR or several? I asked on the issue whether you'd prefer one PR or a split. The four commits split cleanly into API, runtimes, control plane, and UI/Helm, so I'm happy to break them up.
  • Icon: no xAI icon was added; the provider list falls back to no icon. I can add one if you'd like.
  • Scope: strict output schema and reasoning options are left out to match the Mistral-shaped config block in the issue.

AI disclosure: I wrote this change with an AI coding assistant (Claude Code). I reviewed every change, ran the checks above, and can explain and stand behind the code.

🤖 Generated with Claude Code

bwong05umd and others added 4 commits November 6, 2026 14:33
Add `xAI` to the ModelProvider enum with an optional `xAI` block (baseUrl,
temperature, topP, maxTokens, timeout) that mirrors the Mistral block, plus a
CEL rule that rejects the block on any other provider. Add the matching
`ADKXAI` runtime message to the ADK config protobuf as oneof field 21.

Regenerate deepcopy code, the Helm-packaged CRDs, and the Go and Python
protobuf output.

Refs kagent-dev#3543

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Benjamin Wong <wongbency05@gmail.com>
xAI serves an OpenAI-compatible chat completions API, so both runtimes
reuse their OpenAI clients with xAI defaults: base URL https://api.x.ai/v1,
credential XAI_API_KEY, and XAI_API_BASE as an override. The token limit is
sent as max_completion_tokens because xAI marks max_tokens as deprecated.

Tests post a chat completion to a local server, with no live key, and
cover key and base URL precedence and passthrough. The shared runtime
config fixture gains an xai sub-agent so both runtimes keep parsing it.

Refs kagent-dev#3543

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Benjamin Wong <wongbency05@gmail.com>
…talog

Translate an xAI ModelConfig into the xai runtime config, mount its API key
Secret as XAI_API_KEY, and bind the credential to https://api.x.ai so the
egress gateway injects it. Allow https://api.x.ai:443 in the agent egress
policy unless a custom base URL is set. Report traces as x_ai, the GenAI
semantic-convention value, instead of openai.

List xAI as a supported provider with Grok model suggestions from
docs.x.ai, with grok-4.7 first as the default.

Refs kagent-dev#3543

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Benjamin Wong <wongbency05@gmail.com>
Show xAI with links to its console and model docs, and allow token
passthrough for it, as the CRD does. Add a providers.xAI Helm entry and an
install example.

Refs kagent-dev#3543

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Benjamin Wong <wongbency05@gmail.com>
@github-actions github-actions Bot added the enhancement New feature or request label Nov 6, 2026
@bwong05umd
bwong05umd marked this pull request as ready for review November 7, 2026 17:51
@bwong05umd
bwong05umd requested review from a team and supreme-gg-gg as code owners November 7, 2026 17:51
@jayunit100

Copy link
Copy Markdown
Contributor

I did initial testing and it appears to do the right thing.

Are you able to deploy end to end @bwong05umd ?

@bwong05umd

Copy link
Copy Markdown
Author

I did initial testing and it appears to do the right thing.

Are you able to deploy end to end @bwong05umd ?

Thanks for testing! Yes, I can deploy it end to end. My plan is to run it on kind tomorrow using the repo’s mockllm through baseUrl, since I don’t have a paid xAI key, and post the results here. I’ll check the Secret, compiled runtime config, credential delivery, the agent’s request and response, and the trace’s provider name. That won’t cover the live xAI API, so did your testing hit the real API?

In the meantime, is there a maintainer who can approve the CI workflows?

@bwong05umd

Copy link
Copy Markdown
Author

Sorry for the delay. Getting the local stack running took longer than I expected.

I deployed this PR end to end on kind (make build + make kagent-cli-deploy). I used the repo's mockllm as the xAI endpoint, since I don't have a paid key. Everything worked:

  • The xAI ModelConfig and Secret were accepted, and the agent became ready.
  • The runtime compiled with provider xai and sent POST /v1/chat/completions with grok-4.7 and max_completion_tokens.
  • The Secret's key reached the endpoint through the egress gateway, and a wrong key was rejected.
  • The agent replied correctly, and a tool-call round trip worked.
  • The UI shows xAI with the Grok models.

One thing I noticed: the traces include the model but not gen_ai.provider.name. On the Go ADK runtime that's true for every provider, not just xAI, because only the Claude and Codex compilers set it. Should I handle that in this PR or open a separate issue?

Not covered: the live xAI API and the default api.x.ai egress entry, which a unit test covers.

@github-actions

Copy link
Copy Markdown

This pull request has been marked as stale because of no activity in the last 15 days. It will be closed in the next 5 days unless it is tagged "no stalebot" or other activity occurs.

@github-actions github-actions Bot added the stale This issue or PR has become stale label Nov 26, 2026
@github-actions

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown

This pull request has been closed after 15 days of inactivity and an additional 5 days after being marked as stale.

@github-actions github-actions Bot closed this Dec 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request stale This issue or PR has become stale

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a native xAI provider so Grok calls and traces are xAI

2 participants