Skip to content

feat(beta): add xAI provider#2890

Merged
marklysze merged 13 commits into
mainfrom
feat/xai-client
May 23, 2026
Merged

feat(beta): add xAI provider#2890
marklysze merged 13 commits into
mainfrom
feat/xai-client

Conversation

@vvlrff
Copy link
Copy Markdown
Collaborator

@vvlrff vvlrff commented May 20, 2026

Summary

Adds xAI Grok as a model provider.

import asyncio

from autogen.beta import Agent
from autogen.beta.config import XAIConfig
from autogen.beta.tools import WebSearchTool, XSearchTool


agent = Agent(
    "researcher",
    prompt="You are a research assistant.",
    config=XAIConfig(
        model="grok-4",
        api_key="xai-...",
        streaming=True,
        reasoning_effort="high",
    ),
    tools=[
        WebSearchTool(),
        XSearchTool(allowed_x_handles=["xai"]),
    ],
)


async def main() -> None:
    reply = await agent.ask("What did @xai announce about Grok this week?")
    print(reply.body)


asyncio.run(main())

Supported built-in tools

Tool Status
WebSearchTool
XSearchTool (new, xAI-only)
CodeExecutionTool
MCPServerTool
ShellTool / MemoryTool / ImageGenerationTool / SkillsTool / WebFetchTool unsupported → UnsupportedToolError

@vvlrff vvlrff marked this pull request as draft May 20, 2026 16:46
@github-actions github-actions Bot added dependencies Pull requests that update a dependency file beta labels May 20, 2026
@github-actions github-actions Bot added the documentation Improvements or additions to documentation label May 21, 2026
@vvlrff vvlrff marked this pull request as ready for review May 21, 2026 19:42
vvlrff and others added 5 commits May 22, 2026 17:56
XAIClient._call_streaming read chunk.usage and chunk.finish_reason, but
xai_sdk.chat.Chunk exposes neither attribute, so the first delta raised
AttributeError and every streaming call failed. Read usage, model, and
finish_reason from the accumulated `response` instead — matching the
non-streaming path and the existing post-loop fallback.

Verified manually: streaming now emits ModelMessageChunk / ModelReasoning
events and returns the accumulated body with usage populated.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Collaborator

@marklysze marklysze 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 @vvlrff!

@codecov
Copy link
Copy Markdown

codecov Bot commented May 22, 2026

Codecov Report

❌ Patch coverage is 85.77878% with 63 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
autogen/beta/config/xai/xai_client.py 77.77% 17 Missing and 13 partials ⚠️
autogen/beta/config/xai/mappers.py 84.21% 11 Missing and 16 partials ⚠️
autogen/beta/tools/builtin/x_search.py 93.18% 3 Missing ⚠️
autogen/beta/config/__init__.py 50.00% 2 Missing ⚠️
autogen/beta/config/xai/events.py 93.33% 0 Missing and 1 partial ⚠️
Files with missing lines Coverage Δ
autogen/beta/config/xai/__init__.py 100.00% <100.00%> (ø)
autogen/beta/config/xai/config.py 100.00% <100.00%> (ø)
autogen/beta/tools/__init__.py 100.00% <ø> (ø)
autogen/beta/tools/builtin/__init__.py 100.00% <100.00%> (ø)
autogen/beta/config/xai/events.py 93.33% <93.33%> (ø)
autogen/beta/config/__init__.py 48.48% <50.00%> (-30.83%) ⬇️
autogen/beta/tools/builtin/x_search.py 93.18% <93.18%> (ø)
autogen/beta/config/xai/mappers.py 84.21% <84.21%> (ø)
autogen/beta/config/xai/xai_client.py 77.77% <77.77%> (ø)

... and 62 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@marklysze marklysze added this pull request to the merge queue May 23, 2026
Merged via the queue into main with commit b66d3a7 May 23, 2026
28 checks passed
@marklysze marklysze deleted the feat/xai-client branch May 23, 2026 00:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

beta dependencies Pull requests that update a dependency file documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants