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, 20:45 UTC
fix: `user_id` delegation in custom tool execution
angrybayblade committed
Aug 26, 2025 at 11:11 UTC
63a28ccadd60f98f9ba70fe06ea84f66359c0555
3 files changed
+20
-6
python/composio/core/models/custom_tools.py
+8
-3
@@ -131,7 +131,7 @@ class CustomTool:
131
132
def __call__(self, **kwargs: t.Any) -> t.Any:
133
"""Call the custom tool."""
134
- user_id = kwargs.pop("user_id", "default")
134
+ user_id = kwargs.pop("user_id", None) or "default"
135
request = self.request_model.model_validate(kwargs)
136
if self.toolkit is None:
137
return t.cast(CustomToolProtocol, self.f)(request=request)
@@ -196,9 +196,14 @@ class CustomTools:
196
self.custom_tools_registry[tool.slug] = tool
197
return tool
198
199
- def execute(self, slug: str, request: t.Dict) -> t.Dict:
199
+ def execute(
200
+ self,
201
+ slug: str,
202
+ request: t.Dict,
203
+ user_id: t.Optional[str] = None,
204
+ ) -> t.Dict:
205
"""Execute a custom tool."""
206
custom_tool = self.get(slug)
207
if custom_tool is None:
208
raise NotFoundError(f"Custom tool with slug {slug} not found")
204
- return custom_tool(**request)
209
+ return custom_tool(**request, user_id=user_id)
python/composio/core/models/tools.py
+11
-2
@@ -288,12 +288,17 @@ class Tools(Resource, t.Generic[TProvider]):
288
self,
289
slug: str,
290
arguments: t.Dict,
291
+ user_id: t.Optional[str] = None,
292
) -> ToolExecutionResponse:
293
"""Execute a custom tool"""
294
# TODO: Better error handling, pydantic validation eg...
295
try:
296
return {
296
- "data": self._custom_tools.execute(slug=slug, request=arguments),
297
+ "data": self._custom_tools.execute(
298
+ slug=slug,
299
+ request=arguments,
300
+ user_id=user_id,
301
+ ),
302
"error": None,
303
"successful": True,
304
}
@@ -408,7 +413,11 @@ class Tools(Resource, t.Generic[TProvider]):
413
request=arguments,
414
)
415
response = (
411
- self._execute_custom_tool(slug=slug, arguments=arguments)
416
+ self._execute_custom_tool(
417
+ slug=slug,
418
+ arguments=arguments,
419
+ user_id=user_id,
420
+ )
421
if self._custom_tools.get(slug) is not None
422
else self._execute_tool(
423
slug=slug,
python/composio/core/provider/_openai.py
+1
-1
@@ -87,7 +87,7 @@ class OpenAIProvider(
87
outputs.append(
88
self.execute_tool_call(
89
user_id=user_id,
90
- tool_call=tool_call,
90
+ tool_call=t.cast(ChatCompletionMessageToolCall, tool_call),
91
modifiers=modifiers,
92
)
93
)