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): use generated client types everywhere, remove custom TypedDicts
- session.execute() returns SessionExecuteResponse for both local and remote - proxy_execute() returns SessionProxyExecuteResponse directly from client (no more manual dict construction) - Remove dead ProxyExecuteResponse/ProxyExecuteBinaryData TypedDicts - SessionContext protocol uses generated types - No t.Any return types on new methods Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Dhawal Upadhyay committed
Mar 24, 2026 at 14:30 UTC
b7424401e2d78f79b9614288b1eaf76d3e7cfbe4
5 files changed
+21
-52
python/composio/core/models/__init__.py
-2
@@ -3,7 +3,6 @@ from .connected_accounts import ConnectedAccounts
3
from .custom_tool import ExperimentalAPI, ExperimentalToolkit
4
from .custom_tool_types import (
5
CustomTool,
6
- ProxyExecuteResponse,
6
RegisteredCustomTool,
7
RegisteredCustomToolkit,
8
SessionContext,
@@ -36,7 +35,6 @@ __all__ = [
35
"ExperimentalAPI",
36
"ExperimentalToolkit",
37
"MCP",
39
- "ProxyExecuteResponse",
38
"RegisteredCustomTool",
39
"RegisteredCustomToolkit",
40
"RemoteFile",
python/composio/core/models/custom_tool_types.py
+5
-20
@@ -12,6 +12,10 @@ 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_proxy_execute_response import (
16
+ SessionProxyExecuteResponse,
17
+)
18
+
19
from composio.core.models.tools import ToolExecutionResponse
20
21
# ────────────────────────────────────────────────────────────────
@@ -69,7 +73,7 @@ class SessionContext(te.Protocol):
73
method: t.Literal["GET", "POST", "PUT", "DELETE", "PATCH"],
74
body: t.Any = None,
75
parameters: t.Optional[t.List[t.Dict[str, t.Any]]] = None,
72
- ) -> ProxyExecuteResponse:
76
+ ) -> SessionProxyExecuteResponse:
77
"""Proxy API calls through Composio's auth layer."""
78
...
79
@@ -145,22 +149,3 @@ class RegisteredCustomToolkit:
149
name: str
150
description: str
151
tools: t.List[RegisteredCustomTool]
148
-
149
-
150
-# ────────────────────────────────────────────────────────────────
151
-# Proxy execute response types
152
-# ────────────────────────────────────────────────────────────────
153
-
154
-
155
-class ProxyExecuteBinaryData(te.TypedDict, total=False):
156
- content_type: str
157
- size: int
158
- url: str
159
- expires_at: t.Optional[str]
160
-
161
-
162
-class ProxyExecuteResponse(te.TypedDict, total=False):
163
- status: int
164
- data: t.Optional[t.Any]
165
- headers: t.Optional[t.Dict[str, str]]
166
- binary_data: ProxyExecuteBinaryData
python/composio/core/models/session_context.py
+7
-23
@@ -10,16 +10,16 @@ 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_proxy_execute_response import (
14
+ SessionProxyExecuteResponse,
15
+)
16
17
from composio.client import HttpClient
18
from composio.core.models.custom_tool_execution import (
19
execute_custom_tool,
20
find_custom_tool,
21
)
19
-from composio.core.models.custom_tool_types import (
20
- CustomToolsMap,
21
- ProxyExecuteResponse,
22
-)
22
+from composio.core.models.custom_tool_types import CustomToolsMap
23
from composio.core.models.tools import ToolExecutionResponse, _serialize_arguments
24
from composio.exceptions import ValidationError
25
@@ -37,7 +37,7 @@ def proxy_execute_impl(
37
method: t.Literal["GET", "POST", "PUT", "DELETE", "PATCH"],
38
body: t.Any = None,
39
parameters: t.Optional[t.List[t.Dict[str, t.Any]]] = None,
40
-) -> ProxyExecuteResponse:
40
+) -> SessionProxyExecuteResponse:
41
"""Shared proxy execute implementation used by SessionContextImpl and ToolRouterSession."""
42
# Client-side validation (matches TS SessionProxyExecuteParamsSchema)
43
if not toolkit:
@@ -71,7 +71,7 @@ def proxy_execute_impl(
71
)
72
)
73
74
- response = client.tool_router.session.proxy_execute(
74
+ return client.tool_router.session.proxy_execute(
75
session_id=session_id,
76
toolkit_slug=toolkit,
77
endpoint=endpoint,
@@ -80,22 +80,6 @@ def proxy_execute_impl(
80
parameters=api_params if api_params else omit,
81
)
82
83
- result: ProxyExecuteResponse = {
84
- "status": int(response.status),
85
- "data": response.data,
86
- "headers": response.headers,
87
- }
88
-
89
- if response.binary_data:
90
- result["binary_data"] = {
91
- "content_type": response.binary_data.content_type,
92
- "size": int(response.binary_data.size),
93
- "url": response.binary_data.url,
94
- "expires_at": response.binary_data.expires_at,
95
- }
96
-
97
- return result
98
-
83
84
class SessionContextImpl:
85
"""Concrete implementation of SessionContext.
@@ -160,7 +144,7 @@ class SessionContextImpl:
144
method: t.Literal["GET", "POST", "PUT", "DELETE", "PATCH"],
145
body: t.Any = None,
146
parameters: t.Optional[t.List[t.Dict[str, t.Any]]] = None,
163
- ) -> ProxyExecuteResponse:
147
+ ) -> SessionProxyExecuteResponse:
148
"""Proxy API calls through Composio's auth layer."""
149
return proxy_execute_impl(
150
self._client,
python/composio/core/models/tool_router_session.py
+8
-6
@@ -12,6 +12,12 @@ import typing as t
12
from concurrent.futures import ThreadPoolExecutor
13
14
from composio_client import omit
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
22
from composio.client import HttpClient
23
from composio.core.models.connected_accounts import ConnectionRequest
@@ -22,7 +28,6 @@ from composio.core.models.custom_tool_execution import (
28
from composio.core.models.custom_tool_types import (
29
CustomToolsMap,
30
CustomToolsMapEntry,
25
- ProxyExecuteResponse,
31
RegisteredCustomTool,
32
RegisteredCustomToolkit,
33
)
@@ -470,7 +475,7 @@ class ToolRouterSession(t.Generic[TTool, TToolCollection]):
475
tool_slug: str,
476
*,
477
arguments: t.Optional[t.Dict[str, t.Any]] = None,
473
- ) -> t.Any:
478
+ ) -> SessionExecuteResponse:
479
"""
480
Execute a tool within the session.
481
@@ -574,12 +579,9 @@ class ToolRouterSession(t.Generic[TTool, TToolCollection]):
579
method: t.Literal["GET", "POST", "PUT", "DELETE", "PATCH"],
580
body: t.Any = None,
581
parameters: t.Optional[t.List[t.Dict[str, t.Any]]] = None,
577
- ) -> ProxyExecuteResponse:
582
+ ) -> SessionProxyExecuteResponse:
583
"""Proxy an API call through Composio's auth layer.
584
580
- The backend resolves the connected account from the toolkit
581
- within the session.
582
-
585
:param toolkit: Composio toolkit slug (e.g. 'gmail', 'github')
586
:param endpoint: API endpoint URL
587
:param method: HTTP method
python/tests/test_custom_tools.py
+1
-1
@@ -501,7 +501,7 @@ class TestSessionContextImpl:
501
result = ctx.proxy_execute(
502
toolkit="gmail", endpoint="https://example.com", method="GET"
503
)
504
- assert result["status"] == 200
504
+ assert result.status == 200
505
506
507
# ────────────────────────────────────────────────────────────────