Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
refactor: simplify inline custom tools payload construction
Remove conditional spreads/checks — undefined properties are stripped during JSON serialization anyway. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Abir Taheer committed
May 6, 2026 at 22:00 UTC
b336a089eeb93b3fbf14594d19332c57f1ea209b
2 files changed
+5
-20
python/composio/core/models/tool_router.py
+2
-10
@@ -1042,21 +1042,13 @@ class ToolRouter(Resource, t.Generic[TTool, TToolCollection]):
1042
custom_toolkits
1043
)
1044
1045
- inline_custom_tools_payload = {}
1046
- if "custom_tools" in experimental_payload:
1047
- inline_custom_tools_payload["custom_tools"] = experimental_payload[
1048
- "custom_tools"
1049
- ]
1050
- if "custom_toolkits" in experimental_payload:
1051
- inline_custom_tools_payload["custom_toolkits"] = experimental_payload[
1052
- "custom_toolkits"
1053
- ]
1045
+ inline_custom_tools_payload = experimental_payload
1046
1047
from urllib.parse import quote
1048
1049
session = self._client.post(
1050
f"/api/v3.1/tool_router/session/{quote(session_id, safe='')}/attach",
1059
- body={"experimental": experimental_payload},
1051
+ body={"experimental": inline_custom_tools_payload},
1052
cast_to=SessionRetrieveResponse,
1053
)
1054
else:
ts/packages/core/src/models/ToolRouter.ts
+3
-10
@@ -261,21 +261,14 @@ export class ToolRouter<
261
? serializeCustomToolkits(customToolkits)
262
: undefined;
263
264
- const experimentalPayload: {
265
- custom_tools?: SessionCreateParams.Experimental.CustomTool[];
266
- custom_toolkits?: SessionCreateParams.Experimental.CustomToolkit[];
267
- } = {};
268
- if (serializedTools) experimentalPayload.custom_tools = serializedTools;
269
- if (serializedToolkits) experimentalPayload.custom_toolkits = serializedToolkits;
270
-
264
inlineCustomToolsPayload = {
272
- ...(serializedTools ? { custom_tools: serializedTools } : {}),
273
- ...(serializedToolkits ? { custom_toolkits: serializedToolkits } : {}),
265
+ custom_tools: serializedTools,
266
+ custom_toolkits: serializedToolkits,
267
};
268
269
session = await this.client.post<SessionRetrieveResponse>(
270
`/api/v3.1/tool_router/session/${encodeURIComponent(id)}/attach`,
278
- { body: { experimental: experimentalPayload } }
271
+ { body: { experimental: inlineCustomToolsPayload } }
272
);
273
} else {
274
session = await this.client.toolRouter.session.retrieve(id);