-
Notifications
You must be signed in to change notification settings - Fork 19.9k
feat(xai): Add comprehensive tests and docs for agentic tool calling API #33967
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: master
Are you sure you want to change the base?
feat(xai): Add comprehensive tests and docs for agentic tool calling API #33967
Conversation
- Add unit tests for server_tools parameter validation - Add integration tests for web_search, x_search, and code_execution - Enhance ChatXAI docstring with agentic tools examples - Add deprecation warnings for search_parameters API - Add validation to prevent using both old and new APIs - Update README with migration notice The server_tools parameter enables X.AI's new agentic tool calling API, replacing the deprecated search_parameters (sunset Dec 15, 2025). Available tools: - web_search: Autonomous web search - x_search: Search X (Twitter) posts - code_execution: Execute code to solve problems
PLC0415: Import statements must be at module level, not inside functions. Moved 'import warnings' from validate_environment method to top of file.
Reorder imports into proper groups: 1. __future__ imports 2. Standard library (warnings, typing) 3. Third-party (openai, pydantic, typing_extensions) 4. Local packages (langchain_core, langchain_openai) Fixes ruff I001: Import block is un-sorted or un-formatted
CodSpeed Performance ReportMerging #33967 will not alter performanceComparing Summary
Footnotes
|
Alphabetize third-party imports (langchain_core before pydantic) to match the repository's import ordering rules.
- Add None check before len() on server_tools (can be Optional) - Handle response.content as str or list for .lower() call Fixes mypy errors: - tests/unit_tests/test_chat_models.py:149 (arg-type) - tests/integration_tests/test_chat_models.py:149 (union-attr)
Break long line into multi-line expression to satisfy E501 (line <= 88 chars)
Use formatter-preferred single-line ternary within parentheses
Co-authored-by: Mason Daugherty <[email protected]>
Co-authored-by: Mason Daugherty <[email protected]>
Co-authored-by: Mason Daugherty <[email protected]>
Co-authored-by: Mason Daugherty <[email protected]>
Co-authored-by: Mason Daugherty <[email protected]>
Co-authored-by: Mason Daugherty <[email protected]>
Co-authored-by: Mason Daugherty <[email protected]>
Remove links to MIGRATION_GUIDE.md and examples/agentic_tools_example.py that don't exist in this PR. Link to X.AI docs instead. Addresses reviewer feedback.
|
Thanks for this PR. I noticed that XAI should proactively unify API with OpenAI. However, in the LangChain integration, |
Description
Adds comprehensive test coverage and documentation for X.AI's agentic tool calling API support in
langchain-xai.X.AI is deprecating the Live Search API by December 15, 2025 in favor of the new agentic tool calling API (docs). While the
server_toolsparameter already provides support for this feature, it lacked test coverage and documentation visibility, leading to user confusion.Issue: Closes #33961
Changes
🧪 Test Coverage Added
Unit Tests (
tests/unit_tests/test_chat_models.py):test_server_tools_param(): Validates server_tools parameter handlingtest_server_tools_and_search_parameters_conflict(): Ensures both APIs can't be used togethertest_search_parameters_deprecation_warning(): Verifies deprecation warningsIntegration Tests (
tests/integration_tests/test_chat_models.py):test_server_tools_web_search(): Tests autonomous web searchtest_server_tools_x_search(): Tests X (Twitter) searchtest_server_tools_code_execution(): Tests code execution capabilitytest_server_tools_multiple(): Tests using multiple tools simultaneously📚 Documentation Enhancements
ChatXAIdocstring with comprehensive agentic tool calling examplessearch_parametersAPI🔧 Code Quality
Migration Example
Available Server Tools
web_search: Autonomous web search for current informationx_search: Search posts on X (formerly Twitter)code_execution: Execute code to solve complex problemsDependencies
None - no new dependencies added.
Testing
All tests pass locally and are backwards compatible.
Breaking Changes
None - this PR is fully backward compatible. The old
search_parametersAPI continues to work with deprecation warnings.