@devries-cameron20 / composio Mirror · read-only / commits / 2e42d7525
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, 19:45 UTC

fix(py): apply skip_default to agentic provider signatures (langchain, langgraph, autogen) (#3730)

## Summary Agentic providers honor `schema_config={"skip_defaults": True}` for `args_schema` (defaults stripped, fields become required) but were **not** applying the same `skip_default` to the function `__signature__`, so the wrapped tool's signature and `args_schema` disagreed about which defaulted params were optional. The sibling `llamaindex` provider already passed it to both. **Supersedes #3727.** This is the polished version, now that the ag2 migration (#3729) landed and `composio-autogen` imports again — so the autogen case uses a real import instead of the earlier source-load stub, and the parity tests run in CI. ## Changes - **langchain / langgraph** (original commit by @anxkhn): pass `skip_default=self.skip_default` to `get_signature_format_from_schema_params`. - **autogen**: same one-line alignment. autogen builds **only** `__signature__` (no `args_schema`), so it never had the *mismatch* — but its signature still ignored `skip_defaults`. Aligned for consistency; verified on the signature alone. - **tests**: `TestAgenticSkipDefaultsParity` guards each provider with `pytest.importorskip`; adds real-import autogen regression tests (no stub). - **CI + nox**: install `providers/autogen` in the unit-test job (`py.test.yml`) and the nox `tst` session so the autogen parity tests actually run, plus a **hard `import composio_autogen` smoke check** in CI. ## Why the CI import guard (not just the tests) The `importorskip`-guarded unit tests **skip** when a provider can't be imported — which is the correct behavior for optional providers, but means they'd *silently skip* if autogen broke on a fresh install (exactly the failure that #3729 just fixed). The extra `python -c "import composio_autogen"` in the import step is a **hard** check that fails loudly, so a future dependency breakage can't slip through as a green build. `providers/langchain` + `providers/autogen` co-install cleanly (verified: 59 packages, ag2 0.14.0, no conflict). langgraph continues to skip in CI — its code path is identical to langchain's, which runs. ## Type of change - [x] Bug fix ## How Has This Been Tested? - Base venv (langchain only): langchain parity **passes**, langgraph + autogen **skip** (no error). - CI-mirror (langchain + autogen, editable): **4 passed, 2 skipped (langgraph)** — autogen tests actually run and pass. - Regression proof, each provider: reverting only the provider line fails the skip-defaults case with `assert 5 is Parameter.empty`; restoring passes. Verified for langchain **and** autogen. - `ruff check`, `ruff format --check`, `mypy`, and full `tests/test_provider.py` (29 passed, 4 skipped) → clean. `py.test.yml` parses. ## Checklist - [x] I ran linters/tests locally and they passed - [x] I added tests: langchain/langgraph parity + regression, and autogen parity that runs in CI - [ ] Changeset: not applicable — Python-only change. ## Credits Original fix by @anxkhn (#3713 → #3727), preserved as the first commit and co-authored on the follow-up. --------- Co-authored-by: Anas Khan <83116240+anxkhn@users.noreply.github.com>

Alberto Schiabel committed Jul 2, 2026 at 15:38 UTC 2e42d75259c6ca4d00b8f96fadb5cfb091698423
6 files changed +109 -2
.github/workflows/py.test.yml
+5
@@ -75,6 +75,7 @@ jobs:
75 source .venv/bin/activate
76 uv pip install -e .
77 uv pip install -e providers/langchain
78 + uv pip install -e providers/autogen
79 uv pip install pytest pytest-mock
80
81 - name: Run Import Tests
@@ -82,6 +83,10 @@ jobs:
83 cd python/
84 source .venv/bin/activate
85 python -c "from composio import Composio; print('✓ Basic import successful')"
86 + # Guards against the autogen provider becoming un-importable on a fresh
87 + # install (e.g. a broken framework dependency). A hard import here fails
88 + # loudly, unlike the importorskip-guarded unit tests, which would skip.
89 + python -c "import composio_autogen; print('✓ Autogen provider import successful')"
90
91 - name: Run Unit Tests
92 run: |
python/noxfile.py
+1
@@ -78,6 +78,7 @@ def tst(session: Session):
78 """Run the Python unit test suite."""
79 session.install(".", "--group", "dev")
80 session.install("./providers/langchain")
81 + session.install("./providers/autogen")
82 test_paths = session.posargs or ["tests/"]
83 session.run("pytest", *test_paths, "-v", "--tb=short")
84
python/providers/autogen/composio_autogen/provider.py
+1
@@ -95,6 +95,7 @@ class AutogenProvider(
95 # Set signature and annotations
96 params = get_signature_format_from_schema_params(
97 schema_params=schema_params,
98 + skip_default=self.skip_default,
99 )
100 function.__doc__ = tool.description
101 setattr(function, "__signature__", Signature(parameters=params))
python/providers/langchain/composio_langchain/provider.py
+2 -1
@@ -63,7 +63,8 @@ class LangchainProvider(
63 )
64 action_func.__signature__ = Signature( # type: ignore
65 parameters=get_signature_format_from_schema_params(
66 - schema_params=schema_params
66 + schema_params=schema_params,
67 + skip_default=self.skip_default,
68 )
69 )
70 action_func.__doc__ = tool.description
python/providers/langgraph/composio_langgraph/provider.py
+2 -1
@@ -59,7 +59,8 @@ class LanggraphProvider(
59 )
60 action_func.__signature__ = Signature( # type: ignore
61 parameters=get_signature_format_from_schema_params(
62 - schema_params=schema_params
62 + schema_params=schema_params,
63 + skip_default=self.skip_default,
64 )
65 )
66 action_func.__doc__ = description
python/tests/test_provider.py
+98
@@ -1107,3 +1107,101 @@ class TestProviderIntegration:
1107
1108 assert result2["successful"] is True
1109 assert result2["data"]["starred"] is True
1110 +
1111 +
1112 +class TestAgenticSkipDefaultsParity:
1113 + """Regression: agentic providers must honor skip_defaults in __signature__.
1114 +
1115 + The langchain and langgraph providers strip schema defaults from
1116 + args_schema when schema_config={"skip_defaults": True}, but kept the
1117 + defaults in the function __signature__, so the signature and args_schema
1118 + disagreed about which optional params were required. They now pass the
1119 + same skip_default to both, matching the sibling llamaindex provider.
1120 +
1121 + autogen only builds __signature__ (no args_schema), so it never had the
1122 + mismatch, but its signature likewise ignored skip_defaults; it is aligned
1123 + too and checked on the signature alone.
1124 +
1125 + Provider packages are optional (the unit-test job installs langchain and
1126 + autogen), so each case skips via importorskip when its provider is absent.
1127 + """
1128 +
1129 + def _make_tool_with_default(self):
1130 + return Tool(
1131 + name="Test Tool",
1132 + slug="TEST_TOOL",
1133 + description="A tool with a defaulted optional param",
1134 + input_parameters={
1135 + "type": "object",
1136 + "title": "TestToolRequest",
1137 + "properties": {
1138 + "limit": {
1139 + "type": "integer",
1140 + "description": "Max results",
1141 + "default": 5,
1142 + },
1143 + },
1144 + "required": [],
1145 + },
1146 + output_parameters={},
1147 + available_versions=["12012025_00"],
1148 + version="12012025_00",
1149 + scopes=[],
1150 + toolkit=tool_list_response.ItemToolkit(name="Test", slug="test", logo=""),
1151 + deprecated=tool_list_response.ItemDeprecated(
1152 + available_versions=["12012025_00"],
1153 + displayName="Test Tool",
1154 + version="12012025_00",
1155 + toolkit=tool_list_response.ItemDeprecatedToolkit(logo=""),
1156 + is_deprecated=False,
1157 + ),
1158 + is_deprecated=False,
1159 + no_auth=False,
1160 + tags=[],
1161 + )
1162 +
1163 + def _provider(self, name, schema_config=None):
1164 + module = pytest.importorskip(f"composio_{name}")
1165 + provider_cls = getattr(module, f"{name.capitalize()}Provider")
1166 + return (
1167 + provider_cls(schema_config=schema_config)
1168 + if schema_config
1169 + else provider_cls()
1170 + )
1171 +
1172 + @pytest.mark.parametrize("name", ["langchain", "langgraph"])
1173 + def test_skip_defaults_signature_matches_args_schema(self, name):
1174 + from inspect import Parameter
1175 +
1176 + provider = self._provider(name, {"skip_defaults": True})
1177 + wrapped = provider.wrap_tool(self._make_tool_with_default(), Mock())
1178 +
1179 + limit = wrapped.func.__signature__.parameters["limit"]
1180 + assert limit.default is Parameter.empty
1181 + assert wrapped.args_schema.model_fields["limit"].is_required()
1182 +
1183 + @pytest.mark.parametrize("name", ["langchain", "langgraph"])
1184 + def test_default_preserved_without_skip_defaults(self, name):
1185 + provider = self._provider(name)
1186 + wrapped = provider.wrap_tool(self._make_tool_with_default(), Mock())
1187 +
1188 + limit = wrapped.func.__signature__.parameters["limit"]
1189 + assert limit.default == 5
1190 + assert not wrapped.args_schema.model_fields["limit"].is_required()
1191 +
1192 + def test_autogen_signature_honors_skip_defaults(self):
1193 + from inspect import Parameter
1194 +
1195 + provider = self._provider("autogen", {"skip_defaults": True})
1196 + wrapped = provider.wrap_tool(self._make_tool_with_default(), Mock())
1197 +
1198 + # autogen exposes the wrapped function as `_func` and has no args_schema.
1199 + limit = wrapped._func.__signature__.parameters["limit"]
1200 + assert limit.default is Parameter.empty
1201 +
1202 + def test_autogen_signature_preserves_default(self):
1203 + provider = self._provider("autogen")
1204 + wrapped = provider.wrap_tool(self._make_tool_with_default(), Mock())
1205 +
1206 + limit = wrapped._func.__signature__.parameters["limit"]
1207 + assert limit.default == 5