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): unify ctx.execute() to return SessionExecuteResponse
Both session.execute() and ctx.execute() now return the same SessionExecuteResponse type. No more ToolExecutionResponse dict for ctx — consistent API whether called from user code or from within a custom tool. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Dhawal Upadhyay committed
Mar 24, 2026 at 14:34 UTC
cce496cc794897f05c713030650811c68af7ca75
3 files changed
+18
-13
python/composio/core/models/custom_tool_types.py
+4
-3
@@ -12,12 +12,13 @@ from dataclasses import dataclass, field
12
import typing_extensions as te
13
from pydantic import BaseModel
14
15
+from composio_client.types.tool_router.session_execute_response import (
16
+ SessionExecuteResponse,
17
+)
18
from composio_client.types.tool_router.session_proxy_execute_response import (
19
SessionProxyExecuteResponse,
20
)
21
19
-from composio.core.models.tools import ToolExecutionResponse
20
-
22
# ────────────────────────────────────────────────────────────────
23
# Constants
24
# ────────────────────────────────────────────────────────────────
@@ -61,7 +62,7 @@ class SessionContext(te.Protocol):
62
self,
63
tool_slug: str,
64
arguments: t.Dict[str, t.Any],
64
- ) -> ToolExecutionResponse:
65
+ ) -> SessionExecuteResponse:
66
"""Execute any Composio tool from within a custom tool."""
67
...
68
python/composio/core/models/session_context.py
+12
-9
@@ -10,6 +10,9 @@ import typing as t
10
11
from composio_client import omit
12
from composio_client.types.tool_router.session_proxy_execute_params import Parameter
13
+from composio_client.types.tool_router.session_execute_response import (
14
+ SessionExecuteResponse,
15
+)
16
from composio_client.types.tool_router.session_proxy_execute_response import (
17
SessionProxyExecuteResponse,
18
)
@@ -20,7 +23,7 @@ from composio.core.models.custom_tool_execution import (
23
find_custom_tool,
24
)
25
from composio.core.models.custom_tool_types import CustomToolsMap
23
-from composio.core.models.tools import ToolExecutionResponse, _serialize_arguments
26
+from composio.core.models.tools import _serialize_arguments
27
from composio.exceptions import ValidationError
28
29
@@ -110,7 +113,7 @@ class SessionContextImpl:
113
self,
114
tool_slug: str,
115
arguments: t.Dict[str, t.Any],
113
- ) -> ToolExecutionResponse:
116
+ ) -> SessionExecuteResponse:
117
"""Execute any tool from within a custom tool.
118
119
Routes to sibling local tools in-process when available,
@@ -119,22 +122,22 @@ class SessionContextImpl:
122
# Try local tool first (sibling routing)
123
entry = find_custom_tool(self._custom_tools_map, tool_slug)
124
if entry:
122
- return execute_custom_tool(entry, arguments, self)
125
+ result = execute_custom_tool(entry, arguments, self)
126
+ return SessionExecuteResponse(
127
+ data=result["data"],
128
+ error=result["error"],
129
+ log_id="",
130
+ )
131
132
# Serialize any Pydantic model instances before sending to remote API
133
serialized = _serialize_arguments(arguments)
134
135
# Fall back to remote execution
128
- response = self._client.tool_router.session.execute(
136
+ return self._client.tool_router.session.execute(
137
session_id=self._session_id,
138
tool_slug=tool_slug,
139
arguments=serialized,
140
)
133
- return {
134
- "data": response.data if hasattr(response, "data") else {},
135
- "error": response.error if hasattr(response, "error") else None,
136
- "successful": not (hasattr(response, "error") and response.error),
137
- }
141
142
def proxy_execute(
143
self,
python/tests/test_custom_tools.py
+2
-1
@@ -478,7 +478,8 @@ class TestSessionContextImpl:
478
client=MagicMock(), user_id="u", session_id="s", custom_tools_map=m
479
)
480
result = ctx.execute("GREP", {"pattern": "test"})
481
- assert result["successful"] is True
481
+ assert result.error is None
482
+ assert result.data["matches"] == ["test"]
483
484
def test_remote_fallback(self, grep_tool):
485
m = build_custom_tools_map([grep_tool])