Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
TypeScript agentic-aiagentsaiai-agentsaiagentsdeveloper-toolsfunction-callinggpt-4javascriptjsllmllmopsmcppythonremote-mcp-serverssetypescript
Tighten inline custom execute typing
Dhawal Upadhyay490332887d7b
diff --git a/python/composio/core/models/session_context.py b/python/composio/core/models/session_context.pyindex a23c5591a..18bbf4631 100644--- a/python/composio/core/models/session_context.py+++ b/python/composio/core/models/session_context.py@@ -142,18 +142,22 @@ class SessionContextImpl:serialized = _serialize_arguments(arguments)# Fall back to remote execution- execute_kwargs: t.Dict[str, t.Any] = {- "session_id": self._session_id,- "tool_slug": tool_slug,- "arguments": serialized,- }if self._inline_custom_tools_payload is not None:- execute_kwargs["experimental"] = t.cast(- session_execute_params.Experimental,- self._inline_custom_tools_payload,+ return self._client.tool_router.session.execute(+ session_id=self._session_id,+ tool_slug=tool_slug,+ arguments=serialized,+ experimental=t.cast(+ session_execute_params.Experimental,+ self._inline_custom_tools_payload,+ ),)- return self._client.tool_router.session.execute(**execute_kwargs)+ return self._client.tool_router.session.execute(+ session_id=self._session_id,+ tool_slug=tool_slug,+ arguments=serialized,+ )def proxy_execute(self,diff --git a/python/composio/core/models/tool_router_session.py b/python/composio/core/models/tool_router_session.pyindex 36a3395c8..d259dd1a1 100644--- a/python/composio/core/models/tool_router_session.py+++ b/python/composio/core/models/tool_router_session.py@@ -703,19 +703,24 @@ class ToolRouterSession(t.Generic[TTool, TToolCollection]):)# Remote execution- execute_kwargs: t.Dict[str, t.Any] = {- "session_id": self.session_id,- "tool_slug": tool_slug,- "arguments": arguments if arguments is not None else omit,- "account": account if account is not None else omit,- }if self._inline_custom_tools_payload is not None:- execute_kwargs["experimental"] = t.cast(- session_execute_params.Experimental,- self._inline_custom_tools_payload,+ return self._client.tool_router.session.execute(+ session_id=self.session_id,+ tool_slug=tool_slug,+ arguments=arguments if arguments is not None else omit,+ account=account if account is not None else omit,+ experimental=t.cast(+ session_execute_params.Experimental,+ self._inline_custom_tools_payload,+ ),)- return self._client.tool_router.session.execute(**execute_kwargs)+ return self._client.tool_router.session.execute(+ session_id=self.session_id,+ tool_slug=tool_slug,+ arguments=arguments if arguments is not None else omit,+ account=account if account is not None else omit,+ )def custom_tools(self, *, toolkit: t.Optional[str] = Nonediff --git a/python/composio/core/models/tools.py b/python/composio/core/models/tools.pyindex d9808b434..a1045ef42 100644--- a/python/composio/core/models/tools.py+++ b/python/composio/core/models/tools.py@@ -536,21 +536,28 @@ class Tools(Resource, t.Generic[TTool, TToolCollection]):# Serialize any Pydantic model instances before sending to the APIprocessed_arguments = _serialize_arguments(processed_arguments)- execute_kwargs: t.Dict[str, t.Any] = {- "session_id": session_id,- "tool_slug": slug,- "arguments": processed_arguments,- # Provider-wrapped session tools are agentic calls, so they opt into- # direct tool offload when the backend session workbench allows it.- "enable_auto_workbench_offload": True,- }if inline_custom_tools_payload is not None:- execute_kwargs["experimental"] = t.cast(- session_execute_params.Experimental,- inline_custom_tools_payload,+ response = self._client.tool_router.session.execute(+ session_id=session_id,+ tool_slug=slug,+ arguments=processed_arguments,+ # Provider-wrapped session tools are agentic calls, so they opt into+ # direct tool offload when the backend session workbench allows it.+ enable_auto_workbench_offload=True,+ experimental=t.cast(+ session_execute_params.Experimental,+ inline_custom_tools_payload,+ ),+ )+ else:+ response = self._client.tool_router.session.execute(+ session_id=session_id,+ tool_slug=slug,+ arguments=processed_arguments,+ # Provider-wrapped session tools are agentic calls, so they opt into+ # direct tool offload when the backend session workbench allows it.+ enable_auto_workbench_offload=True,)-- response = self._client.tool_router.session.execute(**execute_kwargs)# Convert response to standard formatresult: ToolExecutionResponse = {diff --git a/ts/packages/core/src/models/SessionContext.ts b/ts/packages/core/src/models/SessionContext.tsindex 92bbca1fe..f59b135fe 100644--- a/ts/packages/core/src/models/SessionContext.ts+++ b/ts/packages/core/src/models/SessionContext.ts@@ -71,19 +71,15 @@ export class SessionContextImpl implements SessionContext {tool_slug: toolSlug,arguments: arguments_,};- const experimental = this.inlineExecuteExperimental();- if (experimental) {- executeParams.experimental = experimental;+ if (this.inlineCustomToolsPayload) {+ executeParams.experimental =+ this.inlineCustomToolsPayload as SessionExecuteParams.Experimental;}const response = await this.client.toolRouter.session.execute(this.sessionId, executeParams);return ToolRouterSessionExecuteResponseSchema.parse(transformExecuteResponse(response));}- private inlineExecuteExperimental(): SessionExecuteParams.Experimental | undefined {- return this.inlineCustomToolsPayload as SessionExecuteParams.Experimental | undefined;- }-/*** Proxy API calls through Composio's auth layer.* The backend resolves the connected account from the toolkit within the session.diff --git a/ts/packages/core/src/models/ToolRouterSession.ts b/ts/packages/core/src/models/ToolRouterSession.tsindex 93b0b71cf..28f9df677 100644--- a/ts/packages/core/src/models/ToolRouterSession.ts+++ b/ts/packages/core/src/models/ToolRouterSession.ts@@ -473,22 +473,12 @@ export class ToolRouterSession<return (this.customToolsMap?.byFinalSlug.size ?? 0) > 0;}- private withInlineCustomToolsExperimental<T extends object>(experimental?: T): T | undefined {- if (!this.inlineCustomToolsPayload) {- return experimental;- }- return {- ...(experimental ?? {}),- ...this.inlineCustomToolsPayload,- } as T;- }-private inlineExecuteExperimental(): SessionExecuteParams.Experimental | undefined {- return this.withInlineCustomToolsExperimental<SessionExecuteParams.Experimental>();+ return this.inlineCustomToolsPayload as SessionExecuteParams.Experimental | undefined;}private inlineSearchExperimental(): SessionSearchParams.Experimental | undefined {- return this.withInlineCustomToolsExperimental<SessionSearchParams.Experimental>();+ return this.inlineCustomToolsPayload as SessionSearchParams.Experimental | undefined;}/** Parse an individual tool item from COMPOSIO_MULTI_EXECUTE_TOOL's tools array */