Skip to content

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

fix(python): return SessionExecuteResponse for local tools too

Dhawal Upadhyay975d0dd23fa8
diff --git a/python/composio/core/models/tool_router_session.py b/python/composio/core/models/tool_router_session.py
index b0f4f14ac..64eee03a6 100644
--- a/python/composio/core/models/tool_router_session.py
+++ b/python/composio/core/models/tool_router_session.py
@@ -478,21 +478,24 @@ class ToolRouterSession(t.Generic[TTool, TToolCollection]):
full slug (e.g. "LOCAL_GREP"). Custom tools are executed in-process;
remote tools are sent to the Composio backend.
- Local tools return a dict with ``data``, ``error``, ``log_id`` keys.
- Remote tools return the ``SessionExecuteResponse`` model from the client
- (backward-compatible — supports attribute access like ``result.data``).
+ Both paths return a ``SessionExecuteResponse`` with ``data``,
+ ``error``, and ``log_id`` attributes.
"""
+ from composio_client.types.tool_router.session_execute_response import (
+ SessionExecuteResponse,
+ )
+
# Check if this is a local tool (by original or final slug)
entry = find_custom_tool(self._custom_tools_map, tool_slug)
if entry and self._session_context:
result = execute_custom_tool(entry, arguments or {}, self._session_context)
- return {
- "data": result["data"],
- "error": result["error"],
- "log_id": "",
- }
+ return SessionExecuteResponse(
+ data=result["data"],
+ error=result["error"],
+ log_id="",
+ )
- # Remote execution — return client model as-is for backward compat
+ # Remote execution
return self._client.tool_router.session.execute(
session_id=self.session_id,
tool_slug=tool_slug,
diff --git a/python/tests/test_custom_tools.py b/python/tests/test_custom_tools.py
index 384be531c..b3c6a0a3c 100644
--- a/python/tests/test_custom_tools.py
+++ b/python/tests/test_custom_tools.py
@@ -538,8 +538,10 @@ class TestToolRouterSessionCustomTools:
def test_execute_local(self, mock_session_deps):
s = _session(mock_session_deps)
result = s.execute("GREP", arguments={"pattern": "x"})
- assert result["error"] is None
- assert result["log_id"] == ""
+ # Returns SessionExecuteResponse — same type as remote
+ assert result.error is None
+ assert result.log_id == ""
+ assert result.data["matches"] == ["x"]
mock_session_deps["client"].tool_router.session.execute.assert_not_called()
def test_execute_remote(self, mock_session_deps):