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(tool-router): opt agentic sessions into direct offload

Dhawal Upadhyay42035c835c86
diff --git a/python/composio/core/models/tools.py b/python/composio/core/models/tools.py
index a4165e550..a5bf6ce5f 100644
--- a/python/composio/core/models/tools.py
+++ b/python/composio/core/models/tools.py
@@ -523,6 +523,9 @@ class Tools(Resource, t.Generic[TTool, TToolCollection]):
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.
+ extra_body={"enable_auto_workbench_offload": True},
)
# Convert response to standard format
diff --git a/python/tests/test_custom_tools.py b/python/tests/test_custom_tools.py
index eebb42432..04b91fa7c 100644
--- a/python/tests/test_custom_tools.py
+++ b/python/tests/test_custom_tools.py
@@ -540,7 +540,11 @@ class TestSessionContextImpl:
client=mock_client, user_id="u", session_id="s", custom_tools_map=m
)
ctx.execute("NONEXISTENT", {"arg": "val"})
- mock_client.tool_router.session.execute.assert_called_once()
+ mock_client.tool_router.session.execute.assert_called_once_with(
+ session_id="s",
+ tool_slug="NONEXISTENT",
+ arguments={"arg": "val"},
+ )
def test_proxy_execute(self):
mock_client = MagicMock()
@@ -608,6 +612,11 @@ class TestToolRouterSessionCustomTools:
s = _session(mock_session_deps)
result = s.execute("GMAIL_SEND_EMAIL", arguments={"to": "[email protected]"})
mock_session_deps["client"].tool_router.session.execute.assert_called_once()
+ call_args = mock_session_deps["client"].tool_router.session.execute.call_args
+ assert call_args.kwargs["session_id"] == "s"
+ assert call_args.kwargs["tool_slug"] == "GMAIL_SEND_EMAIL"
+ assert call_args.kwargs["arguments"] == {"to": "[email protected]"}
+ assert "extra_body" not in call_args.kwargs
# Remote returns client model as-is (backward compat, supports attribute access)
assert isinstance(result, SessionExecuteResponse)
assert result.data == {"sent": True}
diff --git a/python/tests/test_tool_router.py b/python/tests/test_tool_router.py
index d0f6744f5..8689adac2 100644
--- a/python/tests/test_tool_router.py
+++ b/python/tests/test_tool_router.py
@@ -1340,8 +1340,10 @@ class TestToolRouterExecution:
call_args = mock_tools_instance._wrap_execute_tool_for_tool_router.call_args
assert call_args.kwargs["session_id"] == "session_123"
- def test_execute_endpoint_called(self, tool_router, mock_client, mock_provider):
- """Test that session execute endpoint is called when executing tools."""
+ def test_execute_endpoint_called_with_auto_offload_opt_in(
+ self, tool_router, mock_client, mock_provider
+ ):
+ """Test that session execute is called for agentic tool execution."""
mock_execute_response = MagicMock()
mock_execute_response.data = {"result": "success"}
mock_execute_response.error = None
@@ -1362,11 +1364,12 @@ class TestToolRouterExecution:
# Execute the tool
result = execute_fn("GMAIL_SEND_EMAIL", {"to": "[email protected]"})
- # Verify execute was called with correct parameters
+ # Verify execute was called with direct offload opt-in for agentic calls
mock_client.tool_router.session.execute.assert_called_once_with(
session_id="session_123",
tool_slug="GMAIL_SEND_EMAIL",
arguments={"to": "[email protected]"},
+ extra_body={"enable_auto_workbench_offload": True},
)
# Verify result format
@@ -1424,6 +1427,7 @@ class TestToolRouterExecution:
mock_client.tool_router.session.execute.assert_called_once()
call_args = mock_client.tool_router.session.execute.call_args
assert call_args.kwargs["arguments"] == {"to": "[email protected]"}
+ assert call_args.kwargs["extra_body"] == {"enable_auto_workbench_offload": True}
# Verify result was modified by after_execute
assert result["data"] == {"modified": True}
diff --git a/ts/packages/core/src/models/Tools.ts b/ts/packages/core/src/models/Tools.ts
index 01ddbf6ad..7e502f839 100644
--- a/ts/packages/core/src/models/Tools.ts
+++ b/ts/packages/core/src/models/Tools.ts
@@ -58,6 +58,11 @@ import { SessionExecuteParams } from '@composio/client/resources/tool-router.mjs
import { CONFIG_DEFAULTS } from '../utils/config-defaults';
import { resolveEffectiveUploadAllowlist } from '../utils/fileDirs';
import { schemaHasFileUploadable } from '../utils/modifiers/FileToolModifier.utils.neutral';
+
+type SessionExecuteParamsWithAutoOffload = SessionExecuteParams & {
+ enable_auto_workbench_offload?: boolean;
+};
+
/**
* This class is used to manage tools in the Composio SDK.
* It provides methods to list, get, and execute tools.
@@ -1035,9 +1040,12 @@ export class Tools<
});
}
- const executePayload: SessionExecuteParams = {
+ const executePayload: SessionExecuteParamsWithAutoOffload = {
tool_slug: toolSlug,
arguments: modifiedParams,
+ // 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,
};
const response = await this.client.toolRouter.session.execute(body.sessionId, executePayload);
diff --git a/ts/packages/core/test/tools/tools.test.ts b/ts/packages/core/test/tools/tools.test.ts
index 15fb7e705..476fd98d1 100644
--- a/ts/packages/core/test/tools/tools.test.ts
+++ b/ts/packages/core/test/tools/tools.test.ts
@@ -1038,6 +1038,7 @@ describe('Tools', () => {
expect(mockClient.toolRouter.session.execute).toHaveBeenCalledWith(sessionId, {
tool_slug: toolSlug,
arguments: body.arguments,
+ enable_auto_workbench_offload: true,
});
expect(result).toEqual({
data: { results: true },
@@ -1110,6 +1111,7 @@ describe('Tools', () => {
expect(mockClient.toolRouter.session.execute).toHaveBeenCalledWith(sessionId, {
tool_slug: toolSlug,
arguments: { query: 'modified' },
+ enable_auto_workbench_offload: true,
});
});
@@ -1253,6 +1255,7 @@ describe('Tools', () => {
expect(mockClient.toolRouter.session.execute).toHaveBeenCalledWith(sessionId, {
tool_slug: 'COMPOSIO_TOOL',
arguments: { query: 'test' },
+ enable_auto_workbench_offload: true,
});
expect(result).toEqual({
data: { results: true },
@@ -1293,6 +1296,7 @@ describe('Tools', () => {
expect(mockClient.toolRouter.session.execute).toHaveBeenCalledWith(sessionId, {
tool_slug: 'COMPOSIO_TOOL',
arguments: { query: 'test', modified: true },
+ enable_auto_workbench_offload: true,
});
});