Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
Mirrored from https://github.com/Camo67/composio.git
Synced Nov 21, 08:30 UTC
Fix Pydantic field aliases in Python tool execution (#4907)
## Summary Python tool execution currently converts Pydantic models to dictionaries using their Python field names, even when the models declare aliases. For example, a field named `display_name` with the alias `displayName` is sent as `display_name`, which can disagree with the tool's schema. This preserves the declared aliases when serializing model arguments. Fixes #4904 ## Changes - Use `by_alias=True` in the core Pydantic argument serializer. Optional fields, defaults, and null values keep their existing behavior. - Add HTTP-level regression tests for direct models, lists, nested dictionaries, root models, and tuples, covering both ordinary aliases and explicit serialization aliases. - Add a nested-model regression that checks defaults and null values remain present and input models are not modified. ## Type of change - [x] Bug fix - [ ] New feature - [ ] Refactor/Chore - [ ] Documentation - [ ] Breaking change ## How Has This Been Tested? Python 3.12.13, Pydantic 2.14.1, composio-client 2.0.0rc16. Before the production change, nine new regression cases failed on incorrect argument keys. Both tuple controls passed. With the change, all 50 tests in `tests/test_tool_execution.py` pass. Run from `python/` in the SDK test environment: ```sh python -m pytest tests/test_tool_execution.py tests/test_tool_router.py tests/test_tool_router_session_files.py tests/test_normalize_tool_arguments.py tests/test_tool_retrieval_errors.py tests/test_tools_proxy.py tests/test_custom_tools.py tests/test_imports.py tests/test_sdk.py --timeout=20 -q --tb=short python -m pytest tests/test_tool_schema_aliasing.py tests/test_provider_argument_serialization.py --timeout=20 -q --tb=short ruff check --config config/ruff.toml composio/core/models/tools.py tests/test_tool_execution.py ruff format --check composio/core/models/tools.py tests/test_tool_execution.py mypy --config-file config/mypy.ini composio/core/models/tools.py tests/test_tool_execution.py ``` - First pytest command: 435 passed, with an existing unknown `core` marker warning. - Second pytest command: 9 passed, 32 skipped because optional provider packages are not installed. - Ruff lint and formatting: passed for both changed files. - `git diff --check`: passed. - Mypy 2.3.1: reports one error in untouched `composio/utils/schema_converter.py:813` involving `TypeAdapter`/`TypeForm`. I verified the same error with the production change removed. The HTTP regressions use the real SDK client with `httpx.MockTransport` to inspect outgoing JSON. No live toolkit or credentials were used. The complete provider/nox test matrix has not been run locally. ## Screenshots (if applicable) Not applicable. ## Checklist - [ ] I have read the Code of Conduct and this PR adheres to it - [ ] I have read and understand every line of this diff, including any LLM-generated code - [ ] Any third-party docs links or promotional content follow the third-party links policy - [ ] I ran linters/tests locally and they passed - [ ] I updated documentation as needed - [ ] I added tests or explain why not applicable - [ ] I added a changeset if this change affects published packages ## Additional context Python-only runtime fix; no TypeScript changeset is needed under the contribution guidelines. No public signatures or dependencies change.