@devries-cameron20 / composio Mirror · read-only / commits / b608abaca
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, 08:30 UTC

fix(py): preserve free-form tool arguments in AutoGen, Google ADK and OpenAI Agents (#4996)

This PR: - closes [SUP-1643](https://linear.app/composio/issue/SUP-1643/python-providers-drop-free-form-object-arguments) - builds on top of https://github.com/ComposioHQ/composio/pull/4094, which fixed LangChain, LangGraph and CrewAI in Python `0.19.0` - AutoGen: both `autogen_core` `run_json` and AG2 `register_tools` validate the model's raw arguments with `json_schema_to_model` + `validate_and_serialize_tool_arguments`, and the advertised schema mirrors the source root's `additionalProperties` / `patternProperties` - Google ADK: `_prepare_invocation_args` restores root keys ADK filtered to signature names; arguments are validated before execution - OpenAI Agents: the advertised root keeps the source's `additionalProperties` instead of always `false`; a root with no properties is advertised open, matching the TypeScript provider - adds a cross-provider matrix in `tests/test_provider_argument_serialization.py` that drives each framework's real entry point; nox and `py.test.yml` set `COMPOSIO_EXPECTED_PROVIDERS` so a missing provider fails instead of skipping, and CI now installs `google_adk` and `llamaindex` - breaking (AutoGen and Google ADK, parity with LangChain/CrewAI): - unknown root keys on a schema that declares properties, and string-encoded scalars such as `"5"` for an integer, return `{"successful": False, ...}` instead of being dropped or coerced - omitted optional arguments are no longer sent as `""`, `0` or `{}` - an invalid `patternProperties` / schema-valued `additionalProperties` raises when the tool is wrapped ## Context On AG2 and Google ADK the model-facing declaration is still built from named parameters, so a tool whose whole argument object is free-form is not advertised as open. Nested free-form arguments, the shape from the support report, work on every provider. The changelog entry documents this. Testing: `nox -s tst` (2486 passed), `nox -s tst_autogen`, `nox -s chk`, `nox -s type_inference`. The matrix failed for AutoGen (both paths) and ADK before the fixes. ## Unapplied review findings - [ ] P2 (pre-existing) — `python/providers/autogen/composio_autogen/provider.py:134` — tools whose whole argument object is free-form are not advertised as open on AG2 / Google ADK - suggested fix: build each framework's declaration from the aliased source JSON Schema and assert it after registration - [ ] testing gap — AutoGen `run_json` cancellation path and the AG2 `log_function_use` branch are untested

Alberto Schiabel committed Oct 20, 2026 at 19:12 UTC b608abaca74ea896a7f8afd460fd220fd4cf16a0
9 files changed +804 -34
.github/workflows/py.test.yml
+9 -2
@@ -94,11 +94,16 @@ jobs:
94 uv venv --python ${{ matrix.python-version }}
95 source .venv/bin/activate
96 uv pip install -e .
97 - for provider in crewai langchain langgraph gemini google openai_agents claude_agent_sdk anthropic; do
97 + expected=""
98 + for provider in crewai langchain langgraph gemini google openai_agents claude_agent_sdk anthropic google_adk llamaindex; do
99 if [[ " $EXCLUDED_PACKAGES " != *" $provider "* ]]; then
100 uv pip install -e "providers/$provider"
101 + expected="$expected $provider"
102 fi
103 done
104 + # The free-form argument matrix fails, rather than skips, for every
105 + # provider this leg installs.
106 + echo "COMPOSIO_EXPECTED_PROVIDERS=$expected" >> "$GITHUB_ENV"
107 uv pip install hypothesis pytest pytest-mock
108
109 - name: Run Import Tests
@@ -109,6 +114,7 @@ jobs:
114 # The Gemini and Google provider tests skip when these are missing, so
115 # fail here instead of letting the unit tests skip silently.
116 python -c "import composio_gemini, composio_google, google.genai; print('✓ Gemini and Google provider imports successful')"
117 + python -c "import composio_google_adk, composio_llamaindex; print('✓ Google ADK and LlamaIndex provider imports successful')"
118
119 - name: Test Autogen Provider Installation
120 run: |
@@ -120,9 +126,10 @@ jobs:
126 source autogen-env/bin/activate
127 uv pip install -e . -e providers/autogen pytest pytest-mock
128 python -c "import composio_autogen; print('✓ Autogen provider import successful')"
123 - python -m pytest \
129 + COMPOSIO_EXPECTED_PROVIDERS=autogen python -m pytest \
130 tests/test_provider.py::TestAgenticSkipDefaultsParity::test_autogen_signature_honors_skip_defaults \
131 tests/test_provider.py::TestAgenticSkipDefaultsParity::test_autogen_signature_preserves_default \
132 + tests/test_provider_argument_serialization.py \
133 -v --tb=short
134
135 - name: Test TypeSafe Provider
docs/content/changelog/10-20-26-python-provider-free-form-arguments.mdx new
+46
@@ -0,0 +1,46 @@
1 +---
2 +title: 'Free-Form Arguments Reach Execution in AutoGen, Google ADK, and OpenAI Agents'
3 +description: 'The Python AutoGen and Google ADK providers no longer drop free-form tool arguments, and OpenAI Agents stops telling the model that open arguments are closed'
4 +date: '2026-10-20'
5 +---
6 +
7 +A tool argument that accepts arbitrary keys, such as an object with no `properties`, `additionalProperties: true`, or `patternProperties`, could reach your tool as `{}` in the Python AutoGen and Google ADK providers. No input error was raised, so the tool ran with different arguments from the ones the model sent.
8 +
9 +LangChain, LangGraph, and CrewAI were fixed in Python `0.19.0` (see [Free-Form Object Arguments Are Preserved Across SDKs](/docs/changelog/2026/08/06)). This release covers the remaining agentic providers.
10 +
11 +### Bug Fixes
12 +
13 +- **AutoGen** (`composio-autogen`): both runtime paths, `autogen_core` tools and AG2's `register_tools`, now pass every key the tool schema allows to execution and validate it with the same rules as LangChain and CrewAI. The advertised tool schema now marks the top-level object as open when the source schema does.
14 +- **Google ADK** (`composio-google-adk`): top-level keys the tool schema allows are no longer filtered down to named parameters, and arguments are validated before execution.
15 +- **OpenAI Agents** (`composio-openai-agents`): the advertised top-level schema keeps the source's `additionalProperties` instead of always setting it to `false`. A schema that declares no properties is advertised as open, matching the TypeScript provider.
16 +
17 +**Before:**
18 +
19 +```python
20 +# tool comes from Composio(provider=AutogenProvider()).tools.get(...)
21 +# its input schema is {"type": "object", "properties": {}}
22 +await tool.run_json({"filters": {"status": "open"}}, CancellationToken())
23 +# The tool executed with {}
24 +```
25 +
26 +**After:**
27 +
28 +```python
29 +await tool.run_json({"filters": {"status": "open"}}, CancellationToken())
30 +# The tool executes with {"filters": {"status": "open"}}
31 +```
32 +
33 +### Behavior Change for AutoGen and Google ADK
34 +
35 +<Callout type="warn">
36 +AutoGen and Google ADK now validate tool arguments against the tool's JSON schema, as LangChain, LangGraph, and CrewAI already do. Calls that used to succeed after the provider silently dropped or converted a value now return an error result to the agent: `{"successful": false, "error": "...", "data": null}`.
37 +</Callout>
38 +
39 +- An unknown top-level key on a schema that declares properties and omits `additionalProperties` is rejected instead of dropped.
40 +- A value of the wrong type, such as `"5"` for an integer, is rejected instead of converted.
41 +- An optional argument the model leaves out is no longer sent as `""`, `0`, or `{}`. The schema's declared default applies instead.
42 +- An invalid `patternProperties` or schema-valued `additionalProperties` raises when the tool is wrapped.
43 +
44 +### Known Limitation
45 +
46 +On Google ADK and on AutoGen's AG2 `register_tools` path, the tool declaration is still built from named parameters. A tool whose whole argument object is free-form is therefore not advertised to the model as open, so the model may not send those keys. Free-form objects nested under a declared argument work on every provider.
python/noxfile.py
+21 -2
@@ -102,6 +102,19 @@ def chk_examples(session: Session):
102 )
103
104
105 +# Providers the `tst` environment installs that the free-form argument matrix
106 +# in tests/test_provider_argument_serialization.py covers.
107 +TST_MATRIX_PROVIDERS = (
108 + "crewai",
109 + "langchain",
110 + "langgraph",
111 + "gemini",
112 + "openai_agents",
113 + "google_adk",
114 + "llamaindex",
115 +)
116 +
117 +
118 @nox.session
119 def tst(session: Session):
120 """Run the Python unit test suite."""
@@ -114,8 +127,12 @@ def tst(session: Session):
127 session.install("./providers/openai_agents")
128 session.install("./providers/claude_agent_sdk")
129 session.install("./providers/anthropic")
130 + session.install("./providers/google_adk")
131 + session.install("./providers/llamaindex")
132 + # The free-form argument matrix fails, rather than skips, for these.
133 + env = {"COMPOSIO_EXPECTED_PROVIDERS": " ".join(TST_MATRIX_PROVIDERS)}
134 if session.posargs:
118 - session.run("pytest", *session.posargs, "-v", "--tb=short")
135 + session.run("pytest", *session.posargs, "-v", "--tb=short", env=env)
136 return
137 # Separate runs: the provider packages' `test_provider.py` files share a
138 # basename with tests/, which pytest cannot collect in a single session.
@@ -125,7 +142,7 @@ def tst(session: Session):
142 "providers/claude_agent_sdk/tests",
143 "providers/anthropic/tests",
144 ):
128 - session.run("pytest", test_path, "-v", "--tb=short")
145 + session.run("pytest", test_path, "-v", "--tb=short", env=env)
146
147
148 @nox.session
@@ -137,8 +154,10 @@ def tst_autogen(session: Session):
154 "pytest",
155 "tests/test_provider.py::TestAgenticSkipDefaultsParity::test_autogen_signature_honors_skip_defaults",
156 "tests/test_provider.py::TestAgenticSkipDefaultsParity::test_autogen_signature_preserves_default",
157 + "tests/test_provider_argument_serialization.py",
158 "-v",
159 "--tb=short",
160 + env={"COMPOSIO_EXPECTED_PROVIDERS": "autogen"},
161 )
162
163
python/providers/autogen/composio_autogen/provider.py
+119 -21
@@ -1,22 +1,96 @@
1 +import asyncio
2 +import functools
3 import hashlib
4 +import logging
5 import types
6 import typing as t
7 from inspect import Signature
8
6 -import autogen
9 +import pydantic
10 from autogen.agentchat.conversable_agent import ConversableAgent
8 -from autogen_core.tools import FunctionTool
11 +from autogen.runtime_logging import log_function_use, logging_enabled
12 +from autogen.tools import serialize_to_str
13 +from autogen_core import EVENT_LOGGER_NAME, CancellationToken, trace_tool_span
14 +from autogen_core.logging import ToolCallEvent
15 +from autogen_core.tools import FunctionTool, ToolSchema
16
17 from composio.client.types import Tool
18 from composio.core.provider import AgenticProvider
19 from composio.core.provider.agentic import AgenticProviderExecuteFn
20 +from composio.utils.pydantic import parse_pydantic_error
21 +from composio.utils.schema_converter import object_is_open
22 from composio.utils.shared import (
23 + alias_tool_input_schema,
24 get_signature_format_from_schema_params,
25 + json_schema_to_model,
26 normalize_tool_arguments,
16 - reinstate_reserved_python_keywords,
17 - substitute_reserved_python_keywords,
27 + validate_and_serialize_tool_arguments,
28 )
29
30 +_event_logger = logging.getLogger(EVENT_LOGGER_NAME)
31 +
32 +
33 +class ComposioFunctionTool(FunctionTool):
34 + """A ``FunctionTool`` that runs a Composio tool on the model's raw arguments.
35 +
36 + ``FunctionTool.run_json`` validates the arguments against a model built
37 + from the function signature, which drops every key the signature does not
38 + name and fills omitted ones with fallback defaults. This tool hands the
39 + raw mapping to the wrapped function instead, which validates it against
40 + the source schema, and advertises the source root's openness so the model
41 + can send the keys that schema admits.
42 + """
43 +
44 + def __init__(
45 + self,
46 + func: t.Callable[..., t.Any],
47 + description: str,
48 + name: str,
49 + root_schema: t.Dict[str, t.Any],
50 + ) -> None:
51 + super().__init__(func=func, description=description, name=name)
52 + self._root_schema = root_schema
53 +
54 + @property
55 + def schema(self) -> ToolSchema:
56 + schema = super().schema
57 + parameters = t.cast(t.Dict[str, t.Any], schema["parameters"])
58 + root = self._root_schema
59 + parameters["additionalProperties"] = root.get(
60 + "additionalProperties", object_is_open(root)
61 + )
62 + if "patternProperties" in root:
63 + parameters["patternProperties"] = root["patternProperties"]
64 + return schema
65 +
66 + async def run_json(
67 + self,
68 + args: t.Mapping[str, t.Any],
69 + cancellation_token: CancellationToken,
70 + call_id: t.Optional[str] = None,
71 + ) -> t.Any:
72 + arguments = normalize_tool_arguments(args)
73 + # Same span and event as `BaseTool.run_json`, which this does not call
74 + # because it re-runs the signature model that drops keys.
75 + with trace_tool_span(
76 + tool_name=self._name,
77 + tool_description=self._description,
78 + tool_call_id=call_id,
79 + ):
80 + future = asyncio.get_running_loop().run_in_executor(
81 + None, functools.partial(self._func, **arguments)
82 + )
83 + cancellation_token.link_future(future)
84 + result = await future
85 + _event_logger.info(
86 + ToolCallEvent(
87 + tool_name=self.name,
88 + arguments=arguments,
89 + result=self.return_value_as_string(result),
90 + )
91 + )
92 + return result
93 +
94
95 class AutogenProvider(
96 AgenticProvider[FunctionTool, list[FunctionTool]],
@@ -56,13 +130,28 @@ class AutogenProvider(
130 :param tools: List of tools to register.
131 """
132 for tool in tools:
59 - autogen.agentchat.register_function(
60 - f=tool._func,
61 - caller=caller,
62 - executor=executor,
63 - name=tool.name,
64 - description=tool.description,
133 + # The model-facing declaration is derived from the function signature.
134 + caller.register_for_llm(name=tool.name, description=tool.description)(
135 + tool._func
136 )
137 + # Execution bypasses AG2's signature-based parameter injection,
138 + # which drops keys the signature does not name, so the wrapped
139 + # function validates the model's raw arguments itself.
140 + executor.register_function({tool.name: self._ag2_executor(executor, tool)})
141 +
142 + @staticmethod
143 + def _ag2_executor(
144 + executor: ConversableAgent, tool: FunctionTool
145 + ) -> t.Callable[..., str]:
146 + func = tool._func
147 +
148 + def execute(**arguments: t.Any) -> str:
149 + result = func(**arguments)
150 + if logging_enabled():
151 + log_function_use(executor, func, arguments, result)
152 + return serialize_to_str(result)
153 +
154 + return execute
155
156 def wrap_tool(
157 self,
@@ -70,18 +159,25 @@ class AutogenProvider(
159 execute_tool: AgenticProviderExecuteFn,
160 ) -> FunctionTool:
161 """Wraps a composio tool as an Autogen FunctionTool."""
73 - schema_params, keywords = substitute_reserved_python_keywords(
74 - schema=tool.input_parameters
162 + aliases = alias_tool_input_schema(schema=tool.input_parameters)
163 + args_schema = json_schema_to_model(
164 + aliases.schema, skip_default=self.skip_default
165 )
166
167 def execute_action(**kwargs: t.Any) -> t.Dict:
78 - """Placeholder function for executing action."""
79 - kwargs = reinstate_reserved_python_keywords(
80 - request=kwargs, keywords=keywords
81 - )
82 - # Normalize defensively so a stringified payload is coerced to a dict (issue #2406).
168 + """Validate the model's arguments and execute the tool."""
169 + try:
170 + arguments = validate_and_serialize_tool_arguments(
171 + args_schema, normalize_tool_arguments(kwargs)
172 + )
173 + except pydantic.ValidationError as e:
174 + return {
175 + "successful": False,
176 + "error": parse_pydantic_error(e),
177 + "data": None,
178 + }
179 return execute_tool(
84 - slug=tool.slug, arguments=normalize_tool_arguments(kwargs)
180 + slug=tool.slug, arguments=aliases.restore_arguments(arguments)
181 )
182
183 # Create function with proper signature
@@ -92,9 +188,10 @@ class AutogenProvider(
188 name=self._process_function_name_for_registration(input_string=tool.slug),
189 )
190
95 - # Set signature and annotations
191 + # The signature only declares the tool; `execute_action` accepts any
192 + # keys and validates them against the source schema.
193 params = get_signature_format_from_schema_params(
97 - schema_params=schema_params,
194 + schema_params=aliases.schema,
195 skip_default=self.skip_default,
196 )
197 function.__doc__ = tool.description
@@ -104,10 +201,11 @@ class AutogenProvider(
201 "__annotations__",
202 {p.name: p.annotation for p in params} | {"return": t.Dict[str, t.Any]},
203 )
107 - return FunctionTool(
204 + return ComposioFunctionTool(
205 func=function,
206 description=tool.description,
207 name=self._process_function_name_for_registration(input_string=tool.slug),
208 + root_schema=aliases.schema,
209 )
210
211 def wrap_tools(
python/providers/google_adk/composio_google_adk/provider.py
+56 -5
@@ -2,13 +2,50 @@ import types
2 import typing as t
3 from inspect import Signature
4
5 +import pydantic
6 from google.adk.tools import FunctionTool
7
8 from composio.client.types import Tool
9 from composio.core.provider import AgenticProvider
10 from composio.core.provider.agentic import AgenticProviderExecuteFn
11 from composio.utils.openapi import function_signature_from_jsonschema
11 -from composio.utils.shared import alias_tool_input_schema, normalize_tool_arguments
12 +from composio.utils.pydantic import parse_pydantic_error
13 +from composio.utils.shared import (
14 + alias_tool_input_schema,
15 + json_schema_to_model,
16 + normalize_tool_arguments,
17 + validate_and_serialize_tool_arguments,
18 +)
19 +
20 +if t.TYPE_CHECKING:
21 + from google.adk.tools.tool_context import ToolContext
22 +
23 +
24 +class _ComposioFunctionTool(FunctionTool):
25 + """`FunctionTool` that hands the wrapped function every root argument.
26 +
27 + ADK keeps only the arguments named in the function signature, so root keys
28 + the tool schema admits through `additionalProperties` or
29 + `patternProperties` never reach the function. The function body validates
30 + the full mapping against the tool schema instead.
31 +
32 + ADK reserves its context parameter and `input_stream` for objects it
33 + injects. Those names are never forwarded: neither a value the model sent
34 + under them nor ADK's own objects reach the tool backend.
35 + """
36 +
37 + def _prepare_invocation_args(
38 + self,
39 + args: t.Dict[str, t.Any],
40 + tool_context: "ToolContext",
41 + ) -> t.Dict[str, t.Any]:
42 + prepared = super()._prepare_invocation_args(args, tool_context)
43 + reserved = getattr(self, "_ignore_params", ("tool_context", "input_stream"))
44 + return {
45 + key: value
46 + for key, value in {**args, **prepared}.items()
47 + if key not in reserved
48 + }
49
50
51 class GoogleAdkProvider(
@@ -50,11 +87,25 @@ class GoogleAdkProvider(
87 docstring += "\nReturns:"
88 docstring += "\n A dictionary containing response from the action"
89
90 + # ADK treats every signature parameter as mandatory, so the model
91 + # requires every declared field too.
92 + args_schema = json_schema_to_model(
93 + aliases.schema, skip_default=self.skip_default
94 + )
95 +
96 def _execute(**kwargs: t.Any) -> t.Dict:
54 - kwargs = aliases.restore_arguments(kwargs)
55 - # Normalize defensively so a stringified payload is coerced to a dict (issue #2406).
97 + try:
98 + arguments = validate_and_serialize_tool_arguments(
99 + args_schema, normalize_tool_arguments(kwargs)
100 + )
101 + except pydantic.ValidationError as e:
102 + return {
103 + "successful": False,
104 + "error": parse_pydantic_error(e),
105 + "data": None,
106 + }
107 return execute_tool(
57 - slug=tool.slug, arguments=normalize_tool_arguments(kwargs)
108 + slug=tool.slug, arguments=aliases.restore_arguments(arguments)
109 )
110
111 function = types.FunctionType(
@@ -74,7 +125,7 @@ class GoogleAdkProvider(
125 {p.name: p.annotation for p in parameters} | {"return": dict},
126 )
127 function.__doc__ = docstring
77 - return FunctionTool(function)
128 + return _ComposioFunctionTool(function)
129
130 def wrap_tools(
131 self,
python/providers/openai_agents/composio_openai_agents/provider.py
+8 -3
@@ -13,6 +13,7 @@ from composio.core.provider.base import BaseProviderConfig
13 from composio.types import Tool
14 from composio.utils.logging import get as get_logger
15 from composio.utils.pydantic import parse_pydantic_error
16 +from composio.utils.schema_converter import object_is_open
17 from composio.utils.shared import normalize_tool_arguments
18 from composio.utils.strict_schema import omit_null_tool_arguments, to_strict_json_schema
19
@@ -180,14 +181,18 @@ class OpenAIAgentsProvider(
181 reasons,
182 )
183
183 - # Ensure the schema has additionalProperties set to false
184 - # this is required by OpenAI's function validation.
184 + # Advertise the root as open or closed exactly as the source schema
185 + # does: an explicit ``additionalProperties`` (true, a schema, or false)
186 + # is kept as-is, and an omitted one follows the shared object policy
187 + # (open only when no properties are declared). Open is written out as
188 + # ``true``, matching the TypeScript provider.
189 # Deep-copy so the in-place edits below (additionalProperties + the
190 # examples/pattern/default removal) never mutate the caller's
191 # Tool.input_parameters, matching the deepcopy contract in
192 # composio.utils.shared.
193 modified_schema = copy.deepcopy(tool.input_parameters)
190 - modified_schema["additionalProperties"] = False
194 + if "additionalProperties" not in modified_schema:
195 + modified_schema["additionalProperties"] = object_is_open(modified_schema)
196
197 # Apply the example removal function. This is done to optimize the
198 # schema as much as possible for Responses API
python/providers/openai_agents/tests/test_openai_agents_provider.py
+77
@@ -265,3 +265,80 @@ def test_strict_defaults_to_false():
265 wrapped_tool = OpenAIAgentsProvider().wrap_tool(tool, lambda **kwargs: {})
266
267 assert wrapped_tool.strict_json_schema is False
268 +
269 +
270 +def _wrap_tool(input_parameters, strict=False):
271 + tool = MagicMock(
272 + slug="FREE_FORM",
273 + description="Accept free-form arguments",
274 + input_parameters=input_parameters,
275 + )
276 + wrapped_tool = OpenAIAgentsProvider(strict=strict).wrap_tool(
277 + tool, lambda **kwargs: {}
278 + )
279 + return wrapped_tool
280 +
281 +
282 +@pytest.mark.parametrize(
283 + "additional_properties",
284 + [True, {"type": "string"}, False],
285 + ids=["true", "schema", "false"],
286 +)
287 +def test_root_keeps_the_source_additional_properties(additional_properties):
288 + """A root that sets ``additionalProperties`` is advertised with that value."""
289 + wrapped_tool = _wrap_tool(
290 + {
291 + "type": "object",
292 + "properties": {"title": {"type": "string"}},
293 + "additionalProperties": additional_properties,
294 + }
295 + )
296 +
297 + assert (
298 + wrapped_tool.params_json_schema["additionalProperties"] == additional_properties
299 + )
300 +
301 +
302 +def test_root_without_properties_is_advertised_open():
303 + """A root that names no properties and omits ``additionalProperties`` is
304 + open, so the model may send arbitrary keys.
305 + """
306 + wrapped_tool = _wrap_tool({"type": "object"})
307 +
308 + assert wrapped_tool.params_json_schema == {
309 + "type": "object",
310 + "additionalProperties": True,
311 + }
312 +
313 +
314 +def test_root_pattern_properties_survive():
315 + """Root ``patternProperties`` stay in the advertised schema alongside the
316 + source's closed ``additionalProperties``.
317 + """
318 + wrapped_tool = _wrap_tool(
319 + {
320 + "type": "object",
321 + "patternProperties": {"^count_": {"type": "integer", "minimum": 1}},
322 + "additionalProperties": False,
323 + }
324 + )
325 +
326 + assert wrapped_tool.params_json_schema == {
327 + "type": "object",
328 + "patternProperties": {"^count_": {"type": "integer", "minimum": 1}},
329 + "additionalProperties": False,
330 + }
331 +
332 +
333 +def test_strict_mode_free_form_root_falls_back_and_is_advertised_open():
334 + """Strict mode cannot express an open root, so it registers the tool
335 + without strict mode and advertises the root open.
336 + """
337 + wrapped_tool = _wrap_tool({"type": "object", "properties": {}}, strict=True)
338 +
339 + assert wrapped_tool.strict_json_schema is False
340 + assert wrapped_tool.params_json_schema == {
341 + "type": "object",
342 + "properties": {},
343 + "additionalProperties": True,
344 + }
python/tests/test_provider_argument_serialization.py
+467
@@ -1,7 +1,13 @@
1 """Provider-boundary tests for validated tool argument serialization."""
2
3 +import ast
4 +import asyncio
5 +import importlib
6 +import json
7 +import os
8 import typing as t
9
10 +import pydantic
11 import pytest
12
13 from composio.client.types import Tool, tool_list_response
@@ -554,3 +560,464 @@ def test_crewai_returns_structured_validation_errors(
560 assert result["data"] is None
561 assert parameter in result["error"]
562 assert received == []
563 +
564 +
565 +# ---------------------------------------------------------------------------
566 +# Cross-provider matrix for free-form object arguments (SUP-1643).
567 +#
568 +# Each row drives a provider through the entry point its framework really
569 +# calls, because the frameworks drop keys before our wrapper code runs.
570 +# ---------------------------------------------------------------------------
571 +
572 +# Providers this environment must have. CI and nox set it so a missing
573 +# install fails instead of skipping; locally it is usually empty.
574 +EXPECTED_PROVIDERS = frozenset(
575 + os.environ.get("COMPOSIO_EXPECTED_PROVIDERS", "").replace(",", " ").split()
576 +)
577 +
578 +# Row name -> (provider package, provider class).
579 +MATRIX_PROVIDERS: t.Dict[str, t.Tuple[str, str]] = {
580 + "crewai": ("crewai", "CrewAIProvider"),
581 + "langchain": ("langchain", "LangchainProvider"),
582 + "langchain_async": ("langchain", "LangchainProvider"),
583 + "langgraph": ("langgraph", "LanggraphProvider"),
584 + "gemini": ("gemini", "GeminiProvider"),
585 + "autogen": ("autogen", "AutogenProvider"),
586 + "autogen_ag2": ("autogen", "AutogenProvider"),
587 + "google_adk": ("google_adk", "GoogleAdkProvider"),
588 + "llamaindex": ("llamaindex", "LlamaIndexProvider"),
589 + "openai_agents": ("openai_agents", "OpenAIAgentsProvider"),
590 +}
591 +
592 +# Providers that validate arguments on the client. LlamaIndex and OpenAI
593 +# Agents pass the model's arguments through, so they only get preservation
594 +# rows.
595 +VALIDATING_PROVIDERS = frozenset(
596 + {
597 + "crewai",
598 + "langchain",
599 + "langchain_async",
600 + "langgraph",
601 + "gemini",
602 + "autogen",
603 + "autogen_ag2",
604 + "google_adk",
605 + }
606 +)
607 +
608 +
609 +def _matrix_provider(row: str):
610 + package, class_name = MATRIX_PROVIDERS[row]
611 + try:
612 + module = importlib.import_module(f"composio_{package}")
613 + except ImportError as error:
614 + if package in EXPECTED_PROVIDERS:
615 + pytest.fail(f"composio_{package} is expected here but missing: {error}")
616 + pytest.skip(f"composio_{package} is not installed")
617 + return getattr(module, class_name)()
618 +
619 +
620 +def _matrix_call(row: str, input_parameters: t.Dict[str, t.Any], arguments):
621 + """Wrap a tool, call it through the framework, and record what executes."""
622 + received: t.List[t.Dict[str, t.Any]] = []
623 +
624 + def execute_tool(slug: str, arguments: t.Dict[str, t.Any]):
625 + assert slug == "TEST_TOOL"
626 + received.append(arguments)
627 + return {"successful": True, "data": {}, "error": None}
628 +
629 + provider = _matrix_provider(row)
630 + tool = _make_tool(input_parameters)
631 + wrapped = provider.wrap_tool(tool, execute_tool)
632 + try:
633 + result = _matrix_invoke(row, provider, wrapped, arguments)
634 + except pydantic.ValidationError as error:
635 + # Gemini's callable raises; google-genai reports it back to the model.
636 + result = error
637 + return received, result
638 +
639 +
640 +def _matrix_invoke(row: str, provider, wrapped, arguments):
641 + if row == "crewai":
642 + result = wrapped.run(**arguments)
643 + elif row in ("langchain", "langgraph"):
644 + result = wrapped.invoke(arguments)
645 + elif row == "langchain_async":
646 + result = asyncio.run(wrapped.ainvoke(arguments))
647 + elif row == "gemini":
648 + # Gemini's automatic function calling invokes the callable directly.
649 + result = wrapped(**arguments)
650 + elif row == "autogen":
651 + from autogen_core import CancellationToken
652 +
653 + result = asyncio.run(wrapped.run_json(arguments, CancellationToken()))
654 + elif row == "autogen_ag2":
655 + from autogen import ConversableAgent
656 +
657 + caller = ConversableAgent(
658 + "caller",
659 + llm_config={"config_list": [{"model": "gpt-4o-mini", "api_key": "x"}]},
660 + human_input_mode="NEVER",
661 + )
662 + executor = ConversableAgent(
663 + "executor", llm_config=False, human_input_mode="NEVER"
664 + )
665 + provider.register_tools(caller=caller, executor=executor, tools=[wrapped])
666 + _, result = executor.execute_function(
667 + {"name": wrapped.name, "arguments": json.dumps(arguments)}
668 + )
669 + elif row == "google_adk":
670 + from unittest.mock import MagicMock
671 +
672 + context = MagicMock()
673 + context.tool_confirmation = None
674 + result = asyncio.run(wrapped.run_async(args=arguments, tool_context=context))
675 + elif row == "llamaindex":
676 + result = wrapped.call(**arguments)
677 + elif row == "openai_agents":
678 + result = asyncio.run(wrapped.on_invoke_tool(None, json.dumps(arguments)))
679 + else: # pragma: no cover - guarded by MATRIX_PROVIDERS
680 + raise AssertionError(row)
681 + return result
682 +
683 +
684 +# Cases whose arguments every provider must deliver unchanged.
685 +PRESERVATION_CASES: t.Dict[str, t.Tuple[t.Dict[str, t.Any], t.Dict[str, t.Any]]] = {
686 + # The customer-reported shape: a free-form object under a declared property.
687 + "nested_free_form": (
688 + {
689 + "type": "object",
690 + "title": "NestedFreeForm",
691 + "properties": {
692 + "title": {"type": "string"},
693 + "body": {"type": "object"},
694 + },
695 + "required": ["title", "body"],
696 + },
697 + {"title": "t", "body": {"unit": {"id": 7}, "tags": ["a"]}},
698 + ),
699 + "nested_additional_properties_schema": (
700 + {
701 + "type": "object",
702 + "title": "NestedMap",
703 + "properties": {
704 + "body": {
705 + "type": "object",
706 + "additionalProperties": {"type": "string"},
707 + },
708 + },
709 + "required": ["body"],
710 + },
711 + {"body": {"a": "x", "b": "y"}},
712 + ),
713 + "array_of_free_form_objects": (
714 + {
715 + "type": "object",
716 + "title": "FreeFormItems",
717 + "properties": {
718 + "items": {"type": "array", "items": {"type": "object"}},
719 + },
720 + "required": ["items"],
721 + },
722 + {"items": [{"a": 1}, {"b": {"c": 2}}]},
723 + ),
724 + "root_free_form": (
725 + {"type": "object", "title": "RootFreeForm", "properties": {}},
726 + {"custom": {"nested": True}},
727 + ),
728 + "root_additional_properties": (
729 + {
730 + "type": "object",
731 + "title": "RootOpen",
732 + "properties": {"title": {"type": "string"}},
733 + "required": ["title"],
734 + "additionalProperties": True,
735 + },
736 + {"title": "t", "extra": {"k": 1}},
737 + ),
738 +}
739 +
740 +# Cases every validating provider must reject without executing the tool.
741 +REJECTION_CASES: t.Dict[str, t.Tuple[t.Dict[str, t.Any], t.Dict[str, t.Any]]] = {
742 + "nested_map_value_type": (
743 + PRESERVATION_CASES["nested_additional_properties_schema"][0],
744 + {"body": {"a": 1}},
745 + ),
746 + "pattern_property_type": (
747 + {
748 + "type": "object",
749 + "title": "PatternArguments",
750 + "properties": {},
751 + "patternProperties": {"^count_": {"type": "integer", "minimum": 1}},
752 + "additionalProperties": False,
753 + },
754 + {"count_x": "nope"},
755 + ),
756 + # Unknown root keys on a schema that declares properties and omits
757 + # additionalProperties are rejected, not dropped.
758 + "closed_root_unknown_key": (
759 + {
760 + "type": "object",
761 + "title": "ClosedRoot",
762 + "properties": {"title": {"type": "string"}},
763 + "required": ["title"],
764 + },
765 + {"title": "t", "extra": 1},
766 + ),
767 + # String-encoded scalars are rejected, not coerced.
768 + "string_for_integer": (
769 + {
770 + "type": "object",
771 + "title": "IntegerArgument",
772 + "properties": {"limit": {"type": "integer"}},
773 + "required": ["limit"],
774 + },
775 + {"limit": "5"},
776 + ),
777 +}
778 +
779 +
780 +def _matrix_params(rows, cases):
781 + return [
782 + pytest.param(row, case, id=f"{row}-{case}") for row in rows for case in cases
783 + ]
784 +
785 +
786 +@pytest.mark.parametrize(
787 + ("row", "case"), _matrix_params(MATRIX_PROVIDERS, PRESERVATION_CASES)
788 +)
789 +def test_matrix_preserves_free_form_arguments(row: str, case: str):
790 + input_parameters, arguments = PRESERVATION_CASES[case]
791 +
792 + received, _ = _matrix_call(row, input_parameters, arguments)
793 +
794 + assert received == [arguments]
795 +
796 +
797 +@pytest.mark.parametrize(
798 + ("row", "case"),
799 + _matrix_params(
800 + [row for row in MATRIX_PROVIDERS if row in VALIDATING_PROVIDERS],
801 + REJECTION_CASES,
802 + ),
803 +)
804 +def test_matrix_rejects_invalid_dynamic_arguments(row: str, case: str):
805 + input_parameters, arguments = REJECTION_CASES[case]
806 +
807 + received, result = _matrix_call(row, input_parameters, arguments)
808 +
809 + assert received == []
810 + error = _rejection_error(row, result)
811 + if error is not None:
812 + assert REJECTION_FIELDS[case] in error
813 +
814 +
815 +# The argument each rejection case's error must name.
816 +REJECTION_FIELDS = {
817 + "nested_map_value_type": "body.a",
818 + "pattern_property_type": "count_x",
819 + "closed_root_unknown_key": "extra",
820 + "string_for_integer": "limit",
821 +}
822 +
823 +
824 +def _rejection_error(row: str, result: t.Any) -> t.Optional[str]:
825 + """The validation error a rejected call reported, in its framework's shape.
826 +
827 + Fails on any other result, so a crash cannot pass as a rejection. Returns
828 + ``None`` where the framework hides the detail.
829 + """
830 + if row in ("langchain", "langchain_async", "langgraph"):
831 + # `handle_validation_error=True` replaces the detail with this string.
832 + assert result == "Tool input validation error"
833 + return None
834 + if row == "gemini":
835 + assert isinstance(result, pydantic.ValidationError)
836 + return str(result)
837 + if row == "autogen_ag2":
838 + # AG2 returns the tool result serialized into the function message.
839 + result = ast.literal_eval(result["content"])
840 + assert isinstance(result, dict), result
841 + assert result["successful"] is False
842 + assert result["data"] is None
843 + return result["error"]
844 +
845 +
846 +# ---------------------------------------------------------------------------
847 +# Google ADK: validation errors reach the agent as results (SUP-1643).
848 +# ---------------------------------------------------------------------------
849 +
850 +
851 +def test_google_adk_returns_validation_errors_without_executing():
852 + input_parameters, arguments = REJECTION_CASES["pattern_property_type"]
853 +
854 + received, result = _matrix_call("google_adk", input_parameters, arguments)
855 +
856 + assert received == []
857 + assert result["successful"] is False
858 + assert result["data"] is None
859 + assert "count_x" in result["error"]
860 +
861 +
862 +def test_google_adk_keeps_tool_context_out_of_arguments():
863 + received, _ = _matrix_call(
864 + "google_adk",
865 + {"type": "object", "title": "RootFreeForm", "properties": {}},
866 + {"custom": {"nested": True}},
867 + )
868 +
869 + assert received == [{"custom": {"nested": True}}]
870 +
871 +
872 +def test_google_adk_does_not_forward_reserved_argument_names():
873 + # ADK reserves `tool_context` and `input_stream`; a model-supplied value
874 + # for either must not reach the tool backend on a free-form root.
875 + received, _ = _matrix_call(
876 + "google_adk",
877 + {"type": "object", "title": "RootFreeForm", "properties": {}},
878 + {"tool_context": {"forged": True}, "input_stream": "x", "data": 1},
879 + )
880 +
881 + assert received == [{"data": 1}]
882 +
883 +
884 +def test_google_adk_never_sends_its_context_object_to_the_backend():
885 + # A schema property named like ADK's context parameter makes ADK inject
886 + # its own ToolContext under that name; it must never be executed with.
887 + received, result = _matrix_call(
888 + "google_adk",
889 + {
890 + "type": "object",
891 + "title": "ReservedProperty",
892 + "properties": {
893 + "query": {"type": "string"},
894 + # Untyped, so validation alone would accept any object.
895 + "tool_context": {"description": "A tool argument"},
896 + },
897 + "required": ["query", "tool_context"],
898 + },
899 + {"query": "q", "tool_context": "model value"},
900 + )
901 +
902 + assert received == []
903 + assert "tool_context" in result["error"]
904 +
905 +
906 +# ---------------------------------------------------------------------------
907 +# AutoGen: both runtime paths share one validated execution (SUP-1643).
908 +# ---------------------------------------------------------------------------
909 +
910 +AUTOGEN_ROWS = ("autogen", "autogen_ag2")
911 +
912 +
913 +def _autogen_result(row: str, result: t.Any) -> t.Any:
914 + """The tool's return value, unwrapped from AG2's function message."""
915 + if row == "autogen_ag2":
916 + # AG2 serializes a dict result with ``str()``.
917 + return ast.literal_eval(result["content"])
918 + return result
919 +
920 +
921 +@pytest.mark.parametrize("row", AUTOGEN_ROWS)
922 +def test_autogen_returns_structured_validation_error(row: str):
923 + input_parameters, arguments = REJECTION_CASES["pattern_property_type"]
924 +
925 + received, result = _matrix_call(row, input_parameters, arguments)
926 +
927 + result = _autogen_result(row, result)
928 + assert received == []
929 + assert result["successful"] is False
930 + assert result["data"] is None
931 + assert "count_x" in result["error"]
932 +
933 +
934 +@pytest.mark.parametrize("row", AUTOGEN_ROWS)
935 +def test_autogen_omits_optional_arguments_the_model_left_out(row: str):
936 + received, _ = _matrix_call(
937 + row,
938 + {
939 + "type": "object",
940 + "title": "OptionalArguments",
941 + "properties": {
942 + "query": {"type": "string"},
943 + "note": {"type": "string"},
944 + },
945 + "required": ["query"],
946 + },
947 + {"query": "agents"},
948 + )
949 +
950 + assert received == [{"query": "agents"}]
951 +
952 +
953 +@pytest.mark.parametrize("row", AUTOGEN_ROWS)
954 +def test_autogen_restores_reserved_keyword_arguments(row: str):
955 + received, _ = _matrix_call(
956 + row,
957 + {
958 + "type": "object",
959 + "title": "ReservedArguments",
960 + "properties": {"from": {"type": "string"}},
961 + "required": ["from"],
962 + },
963 + {"from_rs": "alice"},
964 + )
965 +
966 + assert received == [{"from": "alice"}]
967 +
968 +
969 +def test_autogen_run_json_normalizes_string_payload():
970 + received, _ = _matrix_call(
971 + "autogen",
972 + PRESERVATION_CASES["nested_free_form"][0] | {"required": ["body"]},
973 + '{"body": {"a": 1}}',
974 + )
975 +
976 + assert received == [{"body": {"a": 1}}]
977 +
978 +
979 +def test_autogen_run_json_logs_the_tool_call(caplog: pytest.LogCaptureFixture):
980 + input_parameters, arguments = PRESERVATION_CASES["root_free_form"]
981 +
982 + with caplog.at_level("INFO"):
983 + received, _ = _matrix_call("autogen", input_parameters, arguments)
984 +
985 + from autogen_core import EVENT_LOGGER_NAME
986 + from autogen_core.logging import ToolCallEvent
987 +
988 + events = [
989 + record.msg
990 + for record in caplog.records
991 + if record.name == EVENT_LOGGER_NAME and isinstance(record.msg, ToolCallEvent)
992 + ]
993 + assert received == [arguments]
994 + assert [json.loads(str(event))["arguments"] for event in events] == [arguments]
995 +
996 +
997 +@pytest.mark.parametrize(
998 + ("input_parameters", "expected"),
999 + [
1000 + (
1001 + PRESERVATION_CASES["root_free_form"][0],
1002 + {"additionalProperties": True},
1003 + ),
1004 + (
1005 + REJECTION_CASES["pattern_property_type"][0],
1006 + {
1007 + "additionalProperties": False,
1008 + "patternProperties": {"^count_": {"type": "integer", "minimum": 1}},
1009 + },
1010 + ),
1011 + ],
1012 + ids=["root_free_form", "pattern_only"],
1013 +)
1014 +def test_autogen_schema_mirrors_root_openness(
1015 + input_parameters: t.Dict[str, t.Any], expected: t.Dict[str, t.Any]
1016 +):
1017 + wrapped = _matrix_provider("autogen").wrap_tool(
1018 + _make_tool(input_parameters), lambda slug, arguments: {}
1019 + )
1020 +
1021 + parameters = wrapped.schema["parameters"]
1022 +
1023 + assert {key: parameters.get(key) for key in expected} == expected
python/tests/test_provider_ref_contract.py
+1 -1
@@ -55,7 +55,7 @@ PROVIDER_PACKAGES: t.Final[dict[str, Classification]] = {
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",
58 + via="alias_tool_input_schema",
59 ),
60 "claude_agent_sdk": Classification(
61 "resolves-refs",