Skip to content

fix(xai): preserve tool result IDs and require xai-sdk 1.6.0 - #5355

Merged
adtyavrdhn merged 6 commits into
pydantic:mainfrom
FU-max-boop:fix/xai-tool-result-ids
May 21, 2026
Merged

adtyavrdhn merged 6 commits into
pydantic:mainfrom
FU-max-boop:fix/xai-tool-result-ids

Conversation

@FU-max-boop

@FU-max-boop FU-max-boop commented May 10, 2026 •

Copy link
Copy Markdown
Contributor

Closes #5328.

This updates the xAI model adapter to preserve tool_call_id when mapping ToolReturnPart and tool-bound RetryPromptPart into xai_sdk.chat.tool_result(...) messages. This keeps parallel tool-call results associated with the correct xAI tool calls.

The xAI optional dependency is bumped from xai-sdk>=1.5.0 to xai-sdk>=1.6.0 because 1.6.0 is the first SDK version where tool_result(...) accepts the tool_call_id keyword argument.

Tests were updated to assert reordered xAI tool-result history retains the expected tool_call_id values.

@github-actions github-actions Bot added size: S Small PR (≤100 weighted lines) bug Report that something isn't working, or PR implementing a fix labels May 10, 2026
Comment thread pydantic_ai_slim/pyproject.toml Resolved
@adtyavrdhn adtyavrdhn self-assigned this May 11, 2026
@FU-max-boop

Copy link
Copy Markdown
Contributor Author

Thanks, both points make sense.

I removed the unrelated xAI model-name/schema updates from this PR so it stays focused on preserving tool result IDs.

I also checked the xai-sdk versions: 1.5.0 has tool_result(result) without tool_call_id, while 1.6.0 adds tool_result(result, tool_call_id: Optional[str] = None). So I lowered the minimum from 1.12.2 to 1.6.0.

@adtyavrdhn adtyavrdhn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks!

@adtyavrdhn
adtyavrdhn merged commit 87de23b into pydantic:main May 21, 2026
46 checks passed
@adtyavrdhn adtyavrdhn changed the title Preserve xAI tool result IDs Preserve xAI tool result IDs and require xai-sdk 1.6.0 May 21, 2026
@adtyavrdhn adtyavrdhn changed the title Preserve xAI tool result IDs and require xai-sdk 1.6.0 fix(xai): preserve tool result IDs and require xai-sdk 1.6.0 May 21, 2026
DouweM added a commit that referenced this pull request May 21, 2026
Adapts incoming main changes to v2 idioms:
- Bedrock adaptive-thinking/effort (#5326): rewrote `bedrock_anthropic_model_profile` and `BedrockModelProfile` flag reads to the v2 TypedDict shape (`merge_profile`, `.get(...)`) instead of `.update()`/attribute access; fixed the two new profile fields that were merged in as dataclass-style defaults.
- XSearch model-agnostic refactor (#5120): adopted the moved `capabilities/x_search.py` + `common_tools/x_search.py`, stripping the v1 `builtin`/`native` deprecation shims (removed in v2) and reconciling the XSearch test suite.
- MCP background tasks / SEP-1686 (#5192): kept v2's runtime fastmcp import structure plus the new `ToolTask` import; relocated the new background-task tests into `tests/test_mcp.py` (v2 dropped `tests/test_mcp_toolset.py`).
- xAI tool result IDs (#5355): tracks the latest `xai-sdk` (1.12.2), which keeps `tool_result(result, tool_call_id=...)`; all 112 `tests/models/test_xai.py` pass against it.
- Reconciled capabilities/MCP docs to keep v2 default-behavior wording while adding the XSearch entries.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Report that something isn't working, or PR implementing a fix size: S Small PR (≤100 weighted lines)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

xai: tool_result messages sent without tool_call_id

2 participants