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 21, 22:15 UTC
Tighten inline custom execute typing
Dhawal Upadhyay committed
May 6, 2026 at 18:23 UTC
490332887d7b4b97a00d5ed91d1adc59b19a7d7c
5 files changed
+53
-51
python/composio/core/models/session_context.py
+13
-9
@@ -142,18 +142,22 @@ class SessionContextImpl:
142
serialized = _serialize_arguments(arguments)
143
144
# Fall back to remote execution
145
- execute_kwargs: t.Dict[str, t.Any] = {
146
- "session_id": self._session_id,
147
- "tool_slug": tool_slug,
148
- "arguments": serialized,
149
- }
145
if self._inline_custom_tools_payload is not None:
151
- execute_kwargs["experimental"] = t.cast(
152
- session_execute_params.Experimental,
153
- self._inline_custom_tools_payload,
146
+ return self._client.tool_router.session.execute(
147
+ session_id=self._session_id,
148
+ tool_slug=tool_slug,
149
+ arguments=serialized,
150
+ experimental=t.cast(
151
+ session_execute_params.Experimental,
152
+ self._inline_custom_tools_payload,
153
+ ),
154
)
155
156
- return self._client.tool_router.session.execute(**execute_kwargs)
156
+ return self._client.tool_router.session.execute(
157
+ session_id=self._session_id,
158
+ tool_slug=tool_slug,
159
+ arguments=serialized,
160
+ )
161
162
def proxy_execute(
163
self,
python/composio/core/models/tool_router_session.py
+15
-10
@@ -703,19 +703,24 @@ class ToolRouterSession(t.Generic[TTool, TToolCollection]):
703
)
704
705
# Remote execution
706
- execute_kwargs: t.Dict[str, t.Any] = {
707
- "session_id": self.session_id,
708
- "tool_slug": tool_slug,
709
- "arguments": arguments if arguments is not None else omit,
710
- "account": account if account is not None else omit,
711
- }
706
if self._inline_custom_tools_payload is not None:
713
- execute_kwargs["experimental"] = t.cast(
714
- session_execute_params.Experimental,
715
- self._inline_custom_tools_payload,
707
+ return self._client.tool_router.session.execute(
708
+ session_id=self.session_id,
709
+ tool_slug=tool_slug,
710
+ arguments=arguments if arguments is not None else omit,
711
+ account=account if account is not None else omit,
712
+ experimental=t.cast(
713
+ session_execute_params.Experimental,
714
+ self._inline_custom_tools_payload,
715
+ ),
716
)
717
718
- return self._client.tool_router.session.execute(**execute_kwargs)
718
+ return self._client.tool_router.session.execute(
719
+ session_id=self.session_id,
720
+ tool_slug=tool_slug,
721
+ arguments=arguments if arguments is not None else omit,
722
+ account=account if account is not None else omit,
723
+ )
724
725
def custom_tools(
726
self, *, toolkit: t.Optional[str] = None
python/composio/core/models/tools.py
+20
-13
@@ -536,21 +536,28 @@ class Tools(Resource, t.Generic[TTool, TToolCollection]):
536
# Serialize any Pydantic model instances before sending to the API
537
processed_arguments = _serialize_arguments(processed_arguments)
538
539
- execute_kwargs: t.Dict[str, t.Any] = {
540
- "session_id": session_id,
541
- "tool_slug": slug,
542
- "arguments": processed_arguments,
543
- # Provider-wrapped session tools are agentic calls, so they opt into
544
- # direct tool offload when the backend session workbench allows it.
545
- "enable_auto_workbench_offload": True,
546
- }
539
if inline_custom_tools_payload is not None:
548
- execute_kwargs["experimental"] = t.cast(
549
- session_execute_params.Experimental,
550
- inline_custom_tools_payload,
540
+ response = self._client.tool_router.session.execute(
541
+ session_id=session_id,
542
+ tool_slug=slug,
543
+ arguments=processed_arguments,
544
+ # Provider-wrapped session tools are agentic calls, so they opt into
545
+ # direct tool offload when the backend session workbench allows it.
546
+ enable_auto_workbench_offload=True,
547
+ experimental=t.cast(
548
+ session_execute_params.Experimental,
549
+ inline_custom_tools_payload,
550
+ ),
551
+ )
552
+ else:
553
+ response = self._client.tool_router.session.execute(
554
+ session_id=session_id,
555
+ tool_slug=slug,
556
+ arguments=processed_arguments,
557
+ # Provider-wrapped session tools are agentic calls, so they opt into
558
+ # direct tool offload when the backend session workbench allows it.
559
+ enable_auto_workbench_offload=True,
560
)
552
-
553
- response = self._client.tool_router.session.execute(**execute_kwargs)
561
562
# Convert response to standard format
563
result: ToolExecutionResponse = {
ts/packages/core/src/models/SessionContext.ts
+3
-7
@@ -71,19 +71,15 @@ export class SessionContextImpl implements SessionContext {
71
tool_slug: toolSlug,
72
arguments: arguments_,
73
};
74
- const experimental = this.inlineExecuteExperimental();
75
- if (experimental) {
76
- executeParams.experimental = experimental;
74
+ if (this.inlineCustomToolsPayload) {
75
+ executeParams.experimental =
76
+ this.inlineCustomToolsPayload as SessionExecuteParams.Experimental;
77
}
78
79
const response = await this.client.toolRouter.session.execute(this.sessionId, executeParams);
80
return ToolRouterSessionExecuteResponseSchema.parse(transformExecuteResponse(response));
81
}
82
83
- private inlineExecuteExperimental(): SessionExecuteParams.Experimental | undefined {
84
- return this.inlineCustomToolsPayload as SessionExecuteParams.Experimental | undefined;
85
- }
86
-
83
/**
84
* Proxy API calls through Composio's auth layer.
85
* The backend resolves the connected account from the toolkit within the session.
ts/packages/core/src/models/ToolRouterSession.ts
+2
-12
@@ -473,22 +473,12 @@ export class ToolRouterSession<
473
return (this.customToolsMap?.byFinalSlug.size ?? 0) > 0;
474
}
475
476
- private withInlineCustomToolsExperimental<T extends object>(experimental?: T): T | undefined {
477
- if (!this.inlineCustomToolsPayload) {
478
- return experimental;
479
- }
480
- return {
481
- ...(experimental ?? {}),
482
- ...this.inlineCustomToolsPayload,
483
- } as T;
484
- }
485
-
476
private inlineExecuteExperimental(): SessionExecuteParams.Experimental | undefined {
487
- return this.withInlineCustomToolsExperimental<SessionExecuteParams.Experimental>();
477
+ return this.inlineCustomToolsPayload as SessionExecuteParams.Experimental | undefined;
478
}
479
480
private inlineSearchExperimental(): SessionSearchParams.Experimental | undefined {
491
- return this.withInlineCustomToolsExperimental<SessionSearchParams.Experimental>();
481
+ return this.inlineCustomToolsPayload as SessionSearchParams.Experimental | undefined;
482
}
483
484
/** Parse an individual tool item from COMPOSIO_MULTI_EXECUTE_TOOL's tools array */