Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
TypeScript agentic-aiagentsaiai-agentsaiagentsdeveloper-toolsfunction-callinggpt-4javascriptjsllmllmopsmcppythonremote-mcp-serverssetypescript
fix(python): address codex review round 2 findings
Dhawal Upadhyay514173de7714
diff --git a/python/composio/core/models/custom_tool.py b/python/composio/core/models/custom_tool.pyindex eabec101e..cfcb586fe 100644--- a/python/composio/core/models/custom_tool.py+++ b/python/composio/core/models/custom_tool.py@@ -227,10 +227,19 @@ def experimental_create_tool(except ImportError:pass # RootModel not available in older Pydantic- # Validate execute is callable+ # Validate execute is callable and synchronousif not callable(execute):raise ValidationError(f"{context}: execute must be a callable")+ import asyncio++ if asyncio.iscoroutinefunction(execute):+ raise ValidationError(+ f"{context}: execute must be a synchronous function, not async. "+ f"The Composio Python SDK is synchronous — use a regular "+ f"'def execute(input, ctx)' instead of 'async def'."+ )+# Early length validation_validate_slug_length(slug, extends_toolkit, context)diff --git a/python/composio/core/models/tool_router_session.py b/python/composio/core/models/tool_router_session.pyindex 6ca5382d0..104e19cb8 100644--- a/python/composio/core/models/tool_router_session.py+++ b/python/composio/core/models/tool_router_session.py@@ -319,8 +319,14 @@ class ToolRouterSession(t.Generic[TTool, TToolCollection]):remote_result is not None and not remote_result.get("successful", True))+ # Preserve any extra metadata from the remote batch response+ merged_data: t.Dict[str, t.Any] = {}+ if isinstance(remote_data, dict):+ merged_data.update(remote_data)+ merged_data["results"] = merged+return {- "data": {"results": merged},+ "data": merged_data,"error": (f"{failed_count} out of {len(merged)} tools failed"if has_any_error@@ -479,12 +485,17 @@ class ToolRouterSession(t.Generic[TTool, TToolCollection]):"log_id": "",}- # Remote execution- return self._client.tool_router.session.execute(+ # Remote execution — normalize to dict for consistent return type+ response = self._client.tool_router.session.execute(session_id=self.session_id,tool_slug=tool_slug,arguments=arguments if arguments is not None else omit,)+ return {+ "data": response.data if hasattr(response, "data") else {},+ "error": response.error if hasattr(response, "error") else None,+ "log_id": response.log_id if hasattr(response, "log_id") else "",+ }def custom_tools(self, *, toolkit: t.Optional[str] = Nonediff --git a/python/tests/test_custom_tools.py b/python/tests/test_custom_tools.pyindex d7f15b8ab..505d8cefe 100644--- a/python/tests/test_custom_tools.py+++ b/python/tests/test_custom_tools.py@@ -272,6 +272,19 @@ class TestCreateCustomTool:execute=lambda i, c: {},)+ def test_rejects_async_execute(self):+ async def async_execute(input, ctx):+ return {"result": "ok"}++ with pytest.raises(ValidationError, match="synchronous"):+ experimental_create_tool(+ "ASYNC",+ name="Async",+ description="Desc",+ input_params=GrepInput,+ execute=async_execute,+ )+def test_input_schema_includes_defaults(self, grep_tool):# path has default="." - Pydantic won't include it in requiredassert "pattern" in grep_tool.input_schema.get("required", [])