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
Both local and remote session.execute() now return SessionExecuteResponse — consistent type, supports attribute access (result.data, result.error, result.log_id) everywhere. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Dhawal Upadhyay committed
Mar 24, 2026 at 14:25 UTC
975d0dd23fa8bb8d2cddf148e05f89de6d15e843
2 files changed
+16
-11
python/composio/core/models/tool_router_session.py
+12
-9
@@ -478,21 +478,24 @@ class ToolRouterSession(t.Generic[TTool, TToolCollection]):
478
full slug (e.g. "LOCAL_GREP"). Custom tools are executed in-process;
479
remote tools are sent to the Composio backend.
480
481
- Local tools return a dict with ``data``, ``error``, ``log_id`` keys.
482
- Remote tools return the ``SessionExecuteResponse`` model from the client
483
- (backward-compatible — supports attribute access like ``result.data``).
481
+ Both paths return a ``SessionExecuteResponse`` with ``data``,
482
+ ``error``, and ``log_id`` attributes.
483
"""
484
+ from composio_client.types.tool_router.session_execute_response import (
485
+ SessionExecuteResponse,
486
+ )
487
+
488
# Check if this is a local tool (by original or final slug)
489
entry = find_custom_tool(self._custom_tools_map, tool_slug)
490
if entry and self._session_context:
491
result = execute_custom_tool(entry, arguments or {}, self._session_context)
489
- return {
490
- "data": result["data"],
491
- "error": result["error"],
492
- "log_id": "",
493
- }
492
+ return SessionExecuteResponse(
493
+ data=result["data"],
494
+ error=result["error"],
495
+ log_id="",
496
+ )
497
495
- # Remote execution — return client model as-is for backward compat
498
+ # Remote execution
499
return self._client.tool_router.session.execute(
500
session_id=self.session_id,
501
tool_slug=tool_slug,
python/tests/test_custom_tools.py
+4
-2
@@ -538,8 +538,10 @@ class TestToolRouterSessionCustomTools:
538
def test_execute_local(self, mock_session_deps):
539
s = _session(mock_session_deps)
540
result = s.execute("GREP", arguments={"pattern": "x"})
541
- assert result["error"] is None
542
- assert result["log_id"] == ""
541
+ # Returns SessionExecuteResponse — same type as remote
542
+ assert result.error is None
543
+ assert result.log_id == ""
544
+ assert result.data["matches"] == ["x"]
545
mock_session_deps["client"].tool_router.session.execute.assert_not_called()
546
547
def test_execute_remote(self, mock_session_deps):