Skip to content

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: `user_id` delegation in custom tool execution

angrybayblade63a28ccadd60
diff --git a/python/composio/core/models/custom_tools.py b/python/composio/core/models/custom_tools.py
index 7d1075279..5dc7618e7 100644
--- a/python/composio/core/models/custom_tools.py
+++ b/python/composio/core/models/custom_tools.py
@@ -131,7 +131,7 @@ class CustomTool:
def __call__(self, **kwargs: t.Any) -> t.Any:
"""Call the custom tool."""
- user_id = kwargs.pop("user_id", "default")
+ user_id = kwargs.pop("user_id", None) or "default"
request = self.request_model.model_validate(kwargs)
if self.toolkit is None:
return t.cast(CustomToolProtocol, self.f)(request=request)
@@ -196,9 +196,14 @@ class CustomTools:
self.custom_tools_registry[tool.slug] = tool
return tool
- def execute(self, slug: str, request: t.Dict) -> t.Dict:
+ def execute(
+ self,
+ slug: str,
+ request: t.Dict,
+ user_id: t.Optional[str] = None,
+ ) -> t.Dict:
"""Execute a custom tool."""
custom_tool = self.get(slug)
if custom_tool is None:
raise NotFoundError(f"Custom tool with slug {slug} not found")
- return custom_tool(**request)
+ return custom_tool(**request, user_id=user_id)
diff --git a/python/composio/core/models/tools.py b/python/composio/core/models/tools.py
index 7bf171ae6..c0a3c4d56 100644
--- a/python/composio/core/models/tools.py
+++ b/python/composio/core/models/tools.py
@@ -288,12 +288,17 @@ class Tools(Resource, t.Generic[TProvider]):
self,
slug: str,
arguments: t.Dict,
+ user_id: t.Optional[str] = None,
) -> ToolExecutionResponse:
"""Execute a custom tool"""
# TODO: Better error handling, pydantic validation eg...
try:
return {
- "data": self._custom_tools.execute(slug=slug, request=arguments),
+ "data": self._custom_tools.execute(
+ slug=slug,
+ request=arguments,
+ user_id=user_id,
+ ),
"error": None,
"successful": True,
}
@@ -408,7 +413,11 @@ class Tools(Resource, t.Generic[TProvider]):
request=arguments,
)
response = (
- self._execute_custom_tool(slug=slug, arguments=arguments)
+ self._execute_custom_tool(
+ slug=slug,
+ arguments=arguments,
+ user_id=user_id,
+ )
if self._custom_tools.get(slug) is not None
else self._execute_tool(
slug=slug,
diff --git a/python/composio/core/provider/_openai.py b/python/composio/core/provider/_openai.py
index b4188dd71..33d5413c8 100644
--- a/python/composio/core/provider/_openai.py
+++ b/python/composio/core/provider/_openai.py
@@ -87,7 +87,7 @@ class OpenAIProvider(
outputs.append(
self.execute_tool_call(
user_id=user_id,
- tool_call=tool_call,
+ tool_call=t.cast(ChatCompletionMessageToolCall, tool_call),
modifiers=modifiers,
)
)