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): address CI lint failures and Cursor Bugbot findings
- Fix 6 ruff lint errors: remove unused imports and variable in tests - Fix case-insensitive lookup: uppercase final_slug keys in build_custom_tools_map_from_response to match find_custom_tool's .upper() - Extract proxy_execute into shared helper (proxy_execute_impl) to eliminate duplicated logic between SessionContextImpl and ToolRouterSession - Remove leftover dead code (return result) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Dhawal Upadhyay committed
Mar 20, 2026 at 13:36 UTC
1ce816fda88c6860a334a5624add34781e03907f
4 files changed
+68
-81
python/composio/core/models/custom_tool.py
+2
-1
@@ -491,7 +491,8 @@ def build_custom_tools_map_from_response(
491
entry = CustomToolsMapEntry(
492
handle=handle, final_slug=final_slug, toolkit=resolved_toolkit
493
)
494
- by_final_slug[final_slug] = entry
494
+ # Store with uppercased keys to match find_custom_tool's .upper() lookup
495
+ by_final_slug[final_slug.upper()] = entry
496
by_original_slug[original_slug.upper()] = entry
497
498
# Map standalone custom tools from response
python/composio/core/models/session_context.py
+58
-40
@@ -8,6 +8,8 @@ from __future__ import annotations
8
9
import typing as t
10
11
+from composio_client import omit
12
+
13
from composio.client import HttpClient
14
from composio.core.models.custom_tool_execution import (
15
execute_custom_tool,
@@ -20,6 +22,55 @@ from composio.core.models.custom_tool_types import (
22
from composio.core.models.tools import ToolExecutionResponse
23
24
25
+def proxy_execute_impl(
26
+ client: HttpClient,
27
+ session_id: str,
28
+ *,
29
+ toolkit: str,
30
+ endpoint: str,
31
+ method: t.Literal["GET", "POST", "PUT", "DELETE", "PATCH"],
32
+ body: t.Any = None,
33
+ parameters: t.Optional[t.List[t.Dict[str, t.Any]]] = None,
34
+) -> ProxyExecuteResponse:
35
+ """Shared proxy execute implementation used by SessionContextImpl and ToolRouterSession."""
36
+ # Transform parameters to API format
37
+ api_params: t.List[t.Dict[str, t.Any]] = []
38
+ if parameters:
39
+ for p in parameters:
40
+ api_params.append(
41
+ {
42
+ "name": p["name"],
43
+ "type": p.get("in", p.get("type", "header")),
44
+ "value": str(p["value"]),
45
+ }
46
+ )
47
+
48
+ response = client.tool_router.session.proxy_execute(
49
+ session_id=session_id,
50
+ toolkit_slug=toolkit,
51
+ endpoint=endpoint,
52
+ method=method,
53
+ body=body if body is not None else omit,
54
+ parameters=api_params if api_params else omit,
55
+ )
56
+
57
+ result: ProxyExecuteResponse = {
58
+ "status": int(response.status),
59
+ "data": response.data,
60
+ "headers": response.headers,
61
+ }
62
+
63
+ if response.binary_data:
64
+ result["binary_data"] = {
65
+ "content_type": response.binary_data.content_type,
66
+ "size": int(response.binary_data.size),
67
+ "url": response.binary_data.url,
68
+ "expires_at": response.binary_data.expires_at,
69
+ }
70
+
71
+ return result
72
+
73
+
74
class SessionContextImpl:
75
"""Concrete implementation of SessionContext.
76
@@ -81,46 +132,13 @@ class SessionContextImpl:
132
body: t.Any = None,
133
parameters: t.Optional[t.List[t.Dict[str, t.Any]]] = None,
134
) -> ProxyExecuteResponse:
84
- """Proxy API calls through Composio's auth layer.
85
-
86
- The backend resolves the connected account from the toolkit
87
- within the session.
88
- """
89
- from composio_client import omit
90
-
91
- # Transform parameters to API format
92
- api_params: t.List[t.Dict[str, t.Any]] = []
93
- if parameters:
94
- for p in parameters:
95
- api_params.append(
96
- {
97
- "name": p["name"],
98
- "type": p.get("in", p.get("type", "header")),
99
- "value": str(p["value"]),
100
- }
101
- )
102
-
103
- response = self._client.tool_router.session.proxy_execute(
104
- session_id=self._session_id,
105
- toolkit_slug=toolkit,
135
+ """Proxy API calls through Composio's auth layer."""
136
+ return proxy_execute_impl(
137
+ self._client,
138
+ self._session_id,
139
+ toolkit=toolkit,
140
endpoint=endpoint,
141
method=method,
108
- body=body if body is not None else omit,
109
- parameters=api_params if api_params else omit,
142
+ body=body,
143
+ parameters=parameters,
144
)
111
-
112
- result: ProxyExecuteResponse = {
113
- "status": int(response.status),
114
- "data": response.data,
115
- "headers": response.headers,
116
- }
117
-
118
- if response.binary_data:
119
- result["binary_data"] = {
120
- "content_type": response.binary_data.content_type,
121
- "size": int(response.binary_data.size),
122
- "url": response.binary_data.url,
123
- "expires_at": response.binary_data.expires_at,
124
- }
125
-
126
- return result
python/composio/core/models/tool_router_session.py
+7
-32
@@ -575,39 +575,14 @@ class ToolRouterSession(t.Generic[TTool, TToolCollection]):
575
:param parameters: Query/header parameters
576
:returns: Proxied API response
577
"""
578
- # Transform parameters to API format
579
- api_params: t.List[t.Dict[str, t.Any]] = []
580
- if parameters:
581
- for p in parameters:
582
- api_params.append(
583
- {
584
- "name": p["name"],
585
- "type": p.get("in", p.get("type", "header")),
586
- "value": str(p["value"]),
587
- }
588
- )
578
+ from composio.core.models.session_context import proxy_execute_impl
579
590
- response = self._client.tool_router.session.proxy_execute(
591
- session_id=self.session_id,
592
- toolkit_slug=toolkit,
580
+ return proxy_execute_impl(
581
+ self._client,
582
+ self.session_id,
583
+ toolkit=toolkit,
584
endpoint=endpoint,
585
method=method,
595
- body=body if body is not None else omit,
596
- parameters=api_params if api_params else omit,
586
+ body=body,
587
+ parameters=parameters,
588
)
598
-
599
- result: ProxyExecuteResponse = {
600
- "status": int(response.status),
601
- "data": response.data,
602
- "headers": response.headers,
603
- }
604
-
605
- if response.binary_data:
606
- result["binary_data"] = {
607
- "content_type": response.binary_data.content_type,
608
- "size": int(response.binary_data.size),
609
- "url": response.binary_data.url,
610
- "expires_at": response.binary_data.expires_at,
611
- }
612
-
613
- return result
python/tests/test_custom_tools.py
+1
-8
@@ -11,7 +11,7 @@ Covers:
11
- Multi-execute routing (all-local, all-remote, mixed, parallel)
12
"""
13
14
-from unittest.mock import MagicMock, patch
14
+from unittest.mock import MagicMock
15
16
import pytest
17
from pydantic import BaseModel, Field
@@ -27,12 +27,6 @@ from composio.core.models.custom_tool_execution import (
27
execute_custom_tool,
28
find_custom_tool,
29
)
30
-from composio.core.models.custom_tool_types import (
31
- CustomToolsMap,
32
- CustomToolsMapEntry,
33
- RegisteredCustomTool,
34
- RegisteredCustomToolkit,
35
-)
30
from composio.core.models.session_context import SessionContextImpl
31
from composio.core.models.tool_router_session import ToolRouterSession
32
from composio.exceptions import ValidationError
@@ -484,7 +478,6 @@ class TestBuildMapFromResponse:
478
mock_ctk.tools = [mock_ctk_tool]
479
mock_exp.custom_toolkits = [mock_ctk]
480
487
- set_role = role_toolkit.tools[0]
481
m = build_custom_tools_map_from_response(
482
[grep_tool, email_tool],
483
[role_toolkit],