Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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)