@devries-cameron20 / composio Mirror · read-only / commits / 85d492350
Fork 0

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, 13:30 UTC

fix(python): dereference $ref/$defs in Google provider (#4297)

## Summary The Python Vertex AI Google provider rebuilt tool parameter schemas from `properties` and `required` without resolving internal `$ref`/`$defs` references first. As a result, referenced properties were sent as dangling references and could not be interpreted by Vertex AI. This change dereferences internal schema references before the existing Google-specific translation. It follows the provider behavior fixed in [TypeScript PR #4288](https://github.com/ComposioHQ/composio/pull/4288). ## Changes - Dereference Google provider input schemas with the existing `dereference_json_schema` helper. - Use the resolved schema when extracting properties and required fields. - Add a regression test covering a property defined through `$ref`/`$defs`. ## Type of change - [x] Bug fix - [ ] New feature - [ ] Refactor/Chore - [ ] Documentation - [ ] Breaking change ## How Has This Been Tested? - `pytest tests/test_google_provider.py tests/test_json_schema.py tests/test_provider.py -q -k 'not TestLangchainReservedKeywords and not TestLangchainFreeFormObjectArguments'` — 59 passed, 4 skipped, 5 deselected. - `ruff check --config config/ruff.toml providers/google/composio_google/provider.py tests/test_google_provider.py` — passed. - `ruff format --check providers/google/composio_google/provider.py tests/test_google_provider.py` — passed. - `mypy --config-file config/mypy.ini providers/google/composio_google/provider.py tests/test_google_provider.py` — passed. ## Screenshots (if applicable) Not applicable. ## Checklist - [x] I have read the Code of Conduct and this PR adheres to it - [x] I ran linters/tests locally and they passed - [x] I updated documentation as needed - [x] I added tests or explain why not applicable - [x] I added a changeset if this change affects published TypeScript packages ## Additional context This is a Python-only provider fix; no TypeScript changeset is required. No existing issue was found for the Python provider, so this PR includes the minimal reproduction and regression test directly. --------- Co-authored-by: jkomyno <alberto@composio.dev>

CoralGarden52 committed Sep 7, 2026 at 22:00 UTC 85d49235072d6b88c44ece050fa41b80ededa27b
5 files changed +269 -3
python/providers/crewai/composio_crewai/providers.py
+10 -1
@@ -5,6 +5,7 @@ from crewai.tools import BaseTool
5
6 from composio.core.provider import AgenticProvider, AgenticProviderExecuteFn
7 from composio.types import Tool
8 +from composio.utils.json_schema import dereference_json_schema
9 from composio.utils.pydantic import parse_pydantic_error
10 from composio.utils.shared import (
11 json_schema_to_model,
@@ -57,11 +58,19 @@ class CrewAIProvider(AgenticProvider[BaseTool, list[BaseTool]], name="crewai"):
58 "data": None,
59 }
60
61 + # Inline internal $ref/$defs before building the Pydantic model. The
62 + # converter types a referenced property as Any, so CrewAI would show the
63 + # model an untyped argument. Dangling references degrade to a permissive
64 + # object instead of raising, matching the other providers.
65 + input_parameters = dereference_json_schema(
66 + tool.input_parameters,
67 + on_unresolved="sentinel",
68 + )
69 return Wrapper(
70 name=tool.slug,
71 description=tool.description,
72 args_schema=json_schema_to_model(
64 - json_schema=tool.input_parameters,
73 + json_schema=input_parameters,
74 skip_default=self.skip_default,
75 ),
76 )
python/providers/google/composio_google/provider.py
+7 -2
@@ -14,6 +14,7 @@ from vertexai.generative_models import (
14
15 from composio.core.provider import NonAgenticProvider
16 from composio.types import Modifiers, Tool, ToolExecutionResponse
17 +from composio.utils.json_schema import dereference_json_schema
18 from composio.utils.shared import normalize_tool_arguments
19
20
@@ -35,10 +36,14 @@ class GoogleProvider(
36
37 def wrap_tool(self, tool: Tool) -> FunctionDeclaration:
38 """Wraps composio tool as Google AI Python Gemini FunctionDeclaration object."""
39 + input_parameters = dereference_json_schema(
40 + tool.input_parameters,
41 + on_unresolved="sentinel",
42 + )
43 # Clean up properties by removing 'examples' field
44 properties = t.cast(
45 dict[str, dict],
41 - tool.input_parameters.get("properties", {}),
46 + input_parameters.get("properties", {}),
47 )
48 cleaned_properties = {
49 prop_name: {k: v for k, v in prop_schema.items() if k != "examples"}
@@ -50,7 +55,7 @@ class GoogleProvider(
55 parameters={
56 "type": "object",
57 "properties": cleaned_properties,
53 - "required": tool.input_parameters.get("required", []),
58 + "required": input_parameters.get("required", []),
59 },
60 )
61
python/tests/test_crewai_provider.py new
+36
@@ -0,0 +1,36 @@
1 +"""Tests for the CrewAI provider."""
2 +
3 +import pytest
4 +from pydantic import BaseModel
5 +
6 +from composio.client.types import Tool
7 +
8 +CrewAIProvider = pytest.importorskip("composio_crewai").CrewAIProvider
9 +
10 +
11 +def test_wrap_tool_dereferences_internal_refs() -> None:
12 + """Referenced input properties must keep their type in the args schema."""
13 + tool = Tool.model_construct(
14 + slug="TEST_REF",
15 + description="test",
16 + input_parameters={
17 + "type": "object",
18 + "properties": {"message": {"$ref": "#/$defs/Message"}},
19 + "required": ["message"],
20 + "$defs": {
21 + "Message": {
22 + "type": "object",
23 + "properties": {"subject": {"type": "string"}},
24 + "required": ["subject"],
25 + }
26 + },
27 + },
28 + )
29 +
30 + wrapped = CrewAIProvider().wrap_tool(tool, lambda slug, arguments: {})
31 + assert wrapped.args_schema is not None
32 + message_type = wrapped.args_schema.model_fields["message"].annotation
33 +
34 + assert isinstance(message_type, type)
35 + assert issubclass(message_type, BaseModel)
36 + assert message_type.model_fields["subject"].annotation is str
python/tests/test_google_provider.py new
+33
@@ -0,0 +1,33 @@
1 +"""Tests for the Vertex AI Google provider."""
2 +
3 +import pytest
4 +
5 +from composio.client.types import Tool
6 +
7 +GoogleProvider = pytest.importorskip("composio_google").GoogleProvider
8 +
9 +
10 +def test_wrap_tool_dereferences_internal_refs() -> None:
11 + """Referenced input properties must be expanded before Vertex translation."""
12 + tool = Tool.model_construct(
13 + slug="TEST_REF",
14 + description="test",
15 + input_parameters={
16 + "type": "object",
17 + "properties": {"message": {"$ref": "#/$defs/Message"}},
18 + "required": ["message"],
19 + "$defs": {
20 + "Message": {
21 + "type": "object",
22 + "properties": {"subject": {"type": "string"}},
23 + "required": ["subject"],
24 + }
25 + },
26 + },
27 + )
28 +
29 + wrapped = GoogleProvider().wrap_tool(tool)
30 + message_schema = wrapped.to_dict()["parameters"]["properties"]["message"]
31 +
32 + assert "ref" not in message_schema
33 + assert message_schema["properties"]["subject"]["type"] == "STRING"
python/tests/test_provider_ref_contract.py new
+183
@@ -0,0 +1,183 @@
1 +"""Cross-provider ``$ref`` handling contract.
2 +
3 +Every provider under ``python/providers`` must be classified here. A provider
4 +either resolves internal ``$ref``/``$defs`` pointers before translating the
5 +schema for its framework, or forwards the schema whole to a vendor that
6 +resolves references natively. Adding a provider without classifying it fails
7 +the suite, so the taxonomy is a build gate rather than tribal knowledge.
8 +
9 +The test reads source text instead of importing the providers: importing all
10 +of them would make every vendor SDK a test dependency of the core package.
11 +Behavioral assertions live next to each provider (for example
12 +``tests/test_google_provider.py``); this test owns completeness.
13 +
14 +TypeScript counterpart: ``ts/packages/core/test/providers/refContract.test.ts``.
15 +"""
16 +
17 +from __future__ import annotations
18 +
19 +import typing as t
20 +from dataclasses import dataclass
21 +from pathlib import Path
22 +
23 +import pytest
24 +
25 +REPO_ROOT = Path(__file__).resolve().parents[2]
26 +PROVIDERS_DIR = REPO_ROOT / "python" / "providers"
27 +
28 +# Helpers that inline internal references before schema translation.
29 +# ``alias_tool_input_schema`` and ``substitute_reserved_python_keywords``
30 +# call ``dereference_json_schema`` internally. ``json_schema_to_model`` is
31 +# not one of them: it types a referenced property as ``Any``.
32 +RESOLVER_HELPERS: t.Final = (
33 + "dereference_json_schema",
34 + "alias_tool_input_schema",
35 + "substitute_reserved_python_keywords",
36 +)
37 +
38 +
39 +@dataclass(frozen=True)
40 +class Classification:
41 + """How a provider treats a tool's input schema."""
42 +
43 + treatment: t.Literal["resolves-refs", "passthrough"]
44 + reason: str
45 + # Helper the provider relies on; required for ``resolves-refs``.
46 + via: t.Optional[str] = None
47 +
48 +
49 +PROVIDER_PACKAGES: t.Final[dict[str, Classification]] = {
50 + "anthropic": Classification(
51 + "resolves-refs",
52 + "aliases property keys, which requires keys behind a ref to be materialized",
53 + via="alias_tool_input_schema",
54 + ),
55 + "autogen": Classification(
56 + "resolves-refs",
57 + "builds a Python signature from properties, so refs must be inlined first",
58 + via="substitute_reserved_python_keywords",
59 + ),
60 + "claude_agent_sdk": Classification(
61 + "resolves-refs",
62 + "aliases property keys before building the MCP tool schema",
63 + via="alias_tool_input_schema",
64 + ),
65 + "crewai": Classification(
66 + "resolves-refs",
67 + "converts to a Pydantic model; the converter types a $ref property as Any",
68 + via="dereference_json_schema",
69 + ),
70 + "gemini": Classification(
71 + "resolves-refs",
72 + "aliases property keys and converts to a Pydantic model",
73 + via="alias_tool_input_schema",
74 + ),
75 + "google": Classification(
76 + "resolves-refs",
77 + "rebuilds the root from properties/required; Vertex FunctionDeclaration "
78 + "has no ref/defs field",
79 + via="dereference_json_schema",
80 + ),
81 + "google_adk": Classification(
82 + "resolves-refs",
83 + "builds a Python signature from properties, so refs must be inlined first",
84 + via="alias_tool_input_schema",
85 + ),
86 + "langchain": Classification(
87 + "resolves-refs",
88 + "builds a Pydantic args schema from properties",
89 + via="substitute_reserved_python_keywords",
90 + ),
91 + "langgraph": Classification(
92 + "resolves-refs",
93 + "builds a Pydantic args schema from properties",
94 + via="substitute_reserved_python_keywords",
95 + ),
96 + "llamaindex": Classification(
97 + "resolves-refs",
98 + "builds a Python signature from properties, so refs must be inlined first",
99 + via="substitute_reserved_python_keywords",
100 + ),
101 + "openai": Classification(
102 + "passthrough",
103 + "re-exports the core OpenAI providers, which forward the whole schema",
104 + ),
105 + "openai_agents": Classification(
106 + "passthrough",
107 + "forwards the whole schema; OpenAI resolves $defs/$ref natively",
108 + ),
109 +}
110 +
111 +# Sources outside ``python/providers`` that hand schemas to a vendor.
112 +EXTRA_PASSTHROUGH_SOURCES: t.Final[dict[str, str]] = {
113 + "python/composio/core/provider/_openai.py": "forwards the whole schema",
114 + "python/composio/core/provider/_openai_responses.py": "forwards the whole schema",
115 +}
116 +
117 +
118 +def _discover_providers() -> list[str]:
119 + return sorted(
120 + entry.name
121 + for entry in PROVIDERS_DIR.iterdir()
122 + if entry.is_dir() and (entry / "pyproject.toml").is_file()
123 + )
124 +
125 +
126 +def _provider_source(provider: str) -> str:
127 + package_dirs = [
128 + entry
129 + for entry in (PROVIDERS_DIR / provider).iterdir()
130 + if entry.is_dir() and entry.name.startswith("composio_")
131 + ]
132 + assert package_dirs, f"no composio_* package under providers/{provider}"
133 + return "\n".join(
134 + path.read_text(encoding="utf-8")
135 + for package_dir in package_dirs
136 + for path in sorted(package_dir.rglob("*.py"))
137 + )
138 +
139 +
140 +DISCOVERED: t.Final = _discover_providers()
141 +
142 +
143 +def test_discovers_provider_packages() -> None:
144 + # Guards the test itself: a broken path would make everything below
145 + # vacuously pass.
146 + assert len(DISCOVERED) >= 12
147 +
148 +
149 +def test_classifies_every_provider_package() -> None:
150 + assert [name for name in DISCOVERED if name not in PROVIDER_PACKAGES] == []
151 +
152 +
153 +def test_does_not_classify_removed_providers() -> None:
154 + assert [name for name in PROVIDER_PACKAGES if name not in DISCOVERED] == []
155 +
156 +
157 +@pytest.mark.parametrize(
158 + "provider",
159 + [n for n, c in PROVIDER_PACKAGES.items() if c.treatment == "resolves-refs"],
160 +)
161 +def test_resolves_refs_before_translation(provider: str) -> None:
162 + classification = PROVIDER_PACKAGES[provider]
163 + assert classification.via in RESOLVER_HELPERS, classification.reason
164 + assert classification.via in _provider_source(provider), classification.reason
165 +
166 +
167 +@pytest.mark.parametrize(
168 + "provider",
169 + [n for n, c in PROVIDER_PACKAGES.items() if c.treatment == "passthrough"],
170 +)
171 +def test_forwards_schema_whole(provider: str) -> None:
172 + classification = PROVIDER_PACKAGES[provider]
173 + assert classification.via is None
174 + source = _provider_source(provider)
175 + assert [h for h in RESOLVER_HELPERS if h in source] == [], classification.reason
176 +
177 +
178 +@pytest.mark.parametrize("relative_path", sorted(EXTRA_PASSTHROUGH_SOURCES))
179 +def test_extra_sources_forward_schema_whole(relative_path: str) -> None:
180 + path = REPO_ROOT / relative_path
181 + assert path.is_file(), f"{relative_path} not found; update this test"
182 + source = path.read_text(encoding="utf-8")
183 + assert [h for h in RESOLVER_HELPERS if h in source] == []