-
Notifications
You must be signed in to change notification settings - Fork 625
Feat/add xai model provider #1542
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
- Add xAIModel provider with support for Grok models - Support for reasoning models, image inputs, and structured outputs - Add unit and integration tests - Add xai optional dependency to pyproject.toml
|
The PR is large, but 1400 (out of 2230) lines come from unit tests and integration tests. The added model provider is 765 lines. |
|
Hey @Cerrix , Thank you so much for this PR and your contribution! We really appreciate the work you've put into this, and a xai model provider looks like a fantastic addition to Strands. That said, we absolutely want to support your integration! We'd recommend one of these approaches:
Either way, we'd be happy to feature you on our documentation page as a supported model provider, giving you visibility to our community. You can find more details here. Would either of these approaches work for your use case? We're excited to see xai with our ecosystem! |
|
Hi @yonib05 thank you for your answer! I think I'll go with option 1. I'm working on it. Keep this PR posted |
|
Hi @yonib05, here the package: https://pypi.org/project/strands-xai/ what is the next step? Can I proceed to create a PR in the docs? |
- Add comprehensive xAI/Grok model provider documentation - Include server-side tools (X search, web search, code execution) - Document reasoning models and hybrid tool usage - Add xAI to community model providers navigation Closes: strands-agents/sdk-python#1542
|
@yonib05 done: strands-agents/docs#504 :) |
Motivation
xAI's Grok models offer unique capabilities including server-side agentic tools (web_search, x_search, code_execution), reasoning models with visible or encrypted thinking, and high-performance inference. Developers building agents that need real-time web information, X/Twitter search, or advanced reasoning capabilities currently cannot use these features with Strands Agents.
This PR adds native support for xAI's Grok models using the official
xai-sdkPython package, enabling developers to leverage the full xAI feature set within the Strands Agents framework.Public API Changes
New
xAIModelclass for xAI integration:Configuration Options
model_idstrclient_argsdictparamsdictxai_toolslistreasoning_effortstruse_encrypted_contentboolincludelist["inline_citations", "verbose_streaming"])Installation
Use Cases
web_searchorx_searchserver-side tools to get current information without implementing custom search toolsx_searchfor sentiment analysis, trend monitoring, or content researchImplementation Notes
The xAI SDK uses a gRPC-based API where server-side tools (x_search, web_search, code_execution) are executed by xAI's infrastructure and return encrypted results. These encrypted results cannot be reconstructed from plain text, which presents a challenge for multi-turn conversations.
To solve this, the provider serializes the xAI SDK's internal protobuf messages after each response and stores them in
reasoningContent.redactedContent. This field was chosen because:AgentResult.__str__(), keeping output clean for usersOn subsequent turns, the provider extracts this state and restores the full conversation context, enabling seamless multi-turn conversations even with server-side tools.
Testing
Interactive Test Script
Copy the script below to manually test all xAI features after installing
strands-agents[xai]:The script provides a menu with 10 different agent configurations:
reasoning_effort="high"include=["inline_citations"]Full test script code (click to expand)