@devries-cameron20 / composio Mirror · read-only / commits / 514173de7
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 22, 02:00 UTC

fix(python): address codex review round 2 findings

- Reject async execute handlers at creation time (SDK is sync-only) - Preserve remote batch metadata when merging local/remote multi-execute - Normalize session.execute() to always return plain dict (both local and remote paths now return {data, error, log_id}) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

Dhawal Upadhyay committed Mar 20, 2026 at 13:38 UTC 514173de77143c4c6bb28913818bf6c6de7bff03
3 files changed +37 -4
python/composio/core/models/custom_tool.py
+10 -1
@@ -227,10 +227,19 @@ def experimental_create_tool(
227 except ImportError:
228 pass # RootModel not available in older Pydantic
229
230 - # Validate execute is callable
230 + # Validate execute is callable and synchronous
231 if not callable(execute):
232 raise ValidationError(f"{context}: execute must be a callable")
233
234 + import asyncio
235 +
236 + if asyncio.iscoroutinefunction(execute):
237 + raise ValidationError(
238 + f"{context}: execute must be a synchronous function, not async. "
239 + f"The Composio Python SDK is synchronous — use a regular "
240 + f"'def execute(input, ctx)' instead of 'async def'."
241 + )
242 +
243 # Early length validation
244 _validate_slug_length(slug, extends_toolkit, context)
245
python/composio/core/models/tool_router_session.py
+14 -3
@@ -319,8 +319,14 @@ class ToolRouterSession(t.Generic[TTool, TToolCollection]):
319 remote_result is not None and not remote_result.get("successful", True)
320 )
321
322 + # Preserve any extra metadata from the remote batch response
323 + merged_data: t.Dict[str, t.Any] = {}
324 + if isinstance(remote_data, dict):
325 + merged_data.update(remote_data)
326 + merged_data["results"] = merged
327 +
328 return {
323 - "data": {"results": merged},
329 + "data": merged_data,
330 "error": (
331 f"{failed_count} out of {len(merged)} tools failed"
332 if has_any_error
@@ -479,12 +485,17 @@ class ToolRouterSession(t.Generic[TTool, TToolCollection]):
485 "log_id": "",
486 }
487
482 - # Remote execution
483 - return self._client.tool_router.session.execute(
488 + # Remote execution — normalize to dict for consistent return type
489 + response = self._client.tool_router.session.execute(
490 session_id=self.session_id,
491 tool_slug=tool_slug,
492 arguments=arguments if arguments is not None else omit,
493 )
494 + return {
495 + "data": response.data if hasattr(response, "data") else {},
496 + "error": response.error if hasattr(response, "error") else None,
497 + "log_id": response.log_id if hasattr(response, "log_id") else "",
498 + }
499
500 def custom_tools(
501 self, *, toolkit: t.Optional[str] = None
python/tests/test_custom_tools.py
+13
@@ -272,6 +272,19 @@ class TestCreateCustomTool:
272 execute=lambda i, c: {},
273 )
274
275 + def test_rejects_async_execute(self):
276 + async def async_execute(input, ctx):
277 + return {"result": "ok"}
278 +
279 + with pytest.raises(ValidationError, match="synchronous"):
280 + experimental_create_tool(
281 + "ASYNC",
282 + name="Async",
283 + description="Desc",
284 + input_params=GrepInput,
285 + execute=async_execute,
286 + )
287 +
288 def test_input_schema_includes_defaults(self, grep_tool):
289 # path has default="." - Pydantic won't include it in required
290 assert "pattern" in grep_tool.input_schema.get("required", [])