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
fix(tool-router): opt agentic sessions into direct offload
Dhawal Upadhyay committed
Apr 29, 2026 at 23:18 UTC
42035c835c86618ad39520f379813016030be156
5 files changed
+33
-5
python/composio/core/models/tools.py
+3
@@ -523,6 +523,9 @@ class Tools(Resource, t.Generic[TTool, TToolCollection]):
523
session_id=session_id,
524
tool_slug=slug,
525
arguments=processed_arguments,
526
+ # Provider-wrapped session tools are agentic calls, so they opt into
527
+ # direct tool offload when the backend session workbench allows it.
528
+ extra_body={"enable_auto_workbench_offload": True},
529
)
530
531
# Convert response to standard format
python/tests/test_custom_tools.py
+10
-1
@@ -540,7 +540,11 @@ class TestSessionContextImpl:
540
client=mock_client, user_id="u", session_id="s", custom_tools_map=m
541
)
542
ctx.execute("NONEXISTENT", {"arg": "val"})
543
- mock_client.tool_router.session.execute.assert_called_once()
543
+ mock_client.tool_router.session.execute.assert_called_once_with(
544
+ session_id="s",
545
+ tool_slug="NONEXISTENT",
546
+ arguments={"arg": "val"},
547
+ )
548
549
def test_proxy_execute(self):
550
mock_client = MagicMock()
@@ -608,6 +612,11 @@ class TestToolRouterSessionCustomTools:
612
s = _session(mock_session_deps)
613
result = s.execute("GMAIL_SEND_EMAIL", arguments={"to": "a@b.com"})
614
mock_session_deps["client"].tool_router.session.execute.assert_called_once()
615
+ call_args = mock_session_deps["client"].tool_router.session.execute.call_args
616
+ assert call_args.kwargs["session_id"] == "s"
617
+ assert call_args.kwargs["tool_slug"] == "GMAIL_SEND_EMAIL"
618
+ assert call_args.kwargs["arguments"] == {"to": "a@b.com"}
619
+ assert "extra_body" not in call_args.kwargs
620
# Remote returns client model as-is (backward compat, supports attribute access)
621
assert isinstance(result, SessionExecuteResponse)
622
assert result.data == {"sent": True}
python/tests/test_tool_router.py
+7
-3
@@ -1340,8 +1340,10 @@ class TestToolRouterExecution:
1340
call_args = mock_tools_instance._wrap_execute_tool_for_tool_router.call_args
1341
assert call_args.kwargs["session_id"] == "session_123"
1342
1343
- def test_execute_endpoint_called(self, tool_router, mock_client, mock_provider):
1344
- """Test that session execute endpoint is called when executing tools."""
1343
+ def test_execute_endpoint_called_with_auto_offload_opt_in(
1344
+ self, tool_router, mock_client, mock_provider
1345
+ ):
1346
+ """Test that session execute is called for agentic tool execution."""
1347
mock_execute_response = MagicMock()
1348
mock_execute_response.data = {"result": "success"}
1349
mock_execute_response.error = None
@@ -1362,11 +1364,12 @@ class TestToolRouterExecution:
1364
# Execute the tool
1365
result = execute_fn("GMAIL_SEND_EMAIL", {"to": "test@example.com"})
1366
1365
- # Verify execute was called with correct parameters
1367
+ # Verify execute was called with direct offload opt-in for agentic calls
1368
mock_client.tool_router.session.execute.assert_called_once_with(
1369
session_id="session_123",
1370
tool_slug="GMAIL_SEND_EMAIL",
1371
arguments={"to": "test@example.com"},
1372
+ extra_body={"enable_auto_workbench_offload": True},
1373
)
1374
1375
# Verify result format
@@ -1424,6 +1427,7 @@ class TestToolRouterExecution:
1427
mock_client.tool_router.session.execute.assert_called_once()
1428
call_args = mock_client.tool_router.session.execute.call_args
1429
assert call_args.kwargs["arguments"] == {"to": "modified@example.com"}
1430
+ assert call_args.kwargs["extra_body"] == {"enable_auto_workbench_offload": True}
1431
1432
# Verify result was modified by after_execute
1433
assert result["data"] == {"modified": True}
ts/packages/core/src/models/Tools.ts
+9
-1
@@ -58,6 +58,11 @@ import { SessionExecuteParams } from '@composio/client/resources/tool-router.mjs
58
import { CONFIG_DEFAULTS } from '../utils/config-defaults';
59
import { resolveEffectiveUploadAllowlist } from '../utils/fileDirs';
60
import { schemaHasFileUploadable } from '../utils/modifiers/FileToolModifier.utils.neutral';
61
+
62
+type SessionExecuteParamsWithAutoOffload = SessionExecuteParams & {
63
+ enable_auto_workbench_offload?: boolean;
64
+};
65
+
66
/**
67
* This class is used to manage tools in the Composio SDK.
68
* It provides methods to list, get, and execute tools.
@@ -1035,9 +1040,12 @@ export class Tools<
1040
});
1041
}
1042
1038
- const executePayload: SessionExecuteParams = {
1043
+ const executePayload: SessionExecuteParamsWithAutoOffload = {
1044
tool_slug: toolSlug,
1045
arguments: modifiedParams,
1046
+ // Provider-wrapped session tools are agentic calls, so they opt into
1047
+ // direct tool offload when the backend session workbench allows it.
1048
+ enable_auto_workbench_offload: true,
1049
};
1050
1051
const response = await this.client.toolRouter.session.execute(body.sessionId, executePayload);
ts/packages/core/test/tools/tools.test.ts
+4
@@ -1038,6 +1038,7 @@ describe('Tools', () => {
1038
expect(mockClient.toolRouter.session.execute).toHaveBeenCalledWith(sessionId, {
1039
tool_slug: toolSlug,
1040
arguments: body.arguments,
1041
+ enable_auto_workbench_offload: true,
1042
});
1043
expect(result).toEqual({
1044
data: { results: true },
@@ -1110,6 +1111,7 @@ describe('Tools', () => {
1111
expect(mockClient.toolRouter.session.execute).toHaveBeenCalledWith(sessionId, {
1112
tool_slug: toolSlug,
1113
arguments: { query: 'modified' },
1114
+ enable_auto_workbench_offload: true,
1115
});
1116
});
1117
@@ -1253,6 +1255,7 @@ describe('Tools', () => {
1255
expect(mockClient.toolRouter.session.execute).toHaveBeenCalledWith(sessionId, {
1256
tool_slug: 'COMPOSIO_TOOL',
1257
arguments: { query: 'test' },
1258
+ enable_auto_workbench_offload: true,
1259
});
1260
expect(result).toEqual({
1261
data: { results: true },
@@ -1293,6 +1296,7 @@ describe('Tools', () => {
1296
expect(mockClient.toolRouter.session.execute).toHaveBeenCalledWith(sessionId, {
1297
tool_slug: 'COMPOSIO_TOOL',
1298
arguments: { query: 'test', modified: true },
1299
+ enable_auto_workbench_offload: true,
1300
});
1301
});
1302