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.

docs: add session.update() examples for TypeScript and Python

Abir Taheera9977af2c1e2
diff --git a/python/examples/tool_router/session_update.py b/python/examples/tool_router/session_update.py
new file mode 100644
index 000000000..366a6cb54
--- /dev/null
+++ b/python/examples/tool_router/session_update.py
@@ -0,0 +1,45 @@
+"""
+Tool Router - Session Update Example
+
+Demonstrates using session.update() to modify a session's configuration
+after creation — e.g. adding toolkits, changing workbench settings, or
+updating preload config without creating a new session.
+"""
+
+from composio import Composio
+
+composio = Composio()
+
+# Create a session with gmail only
+session = composio.create(
+ user_id="session-update-demo",
+ toolkits=["gmail"],
+ manage_connections=False,
+)
+
+print(f"Session created: {session.session_id}")
+print(f"Preload: {session.preload}")
+
+# Update: add github toolkit, enable workbench, and preload a tool
+session.update(
+ toolkits={"enable": ["gmail", "github"]},
+ workbench={"enable": True, "sandbox_size": "medium"},
+ preload={"tools": ["GITHUB_CREATE_ISSUE"]},
+)
+
+print(f"\nAfter update:")
+print(f"Preload: {session.preload}")
+
+# Update: disable workbench entirely
+session.update(
+ workbench={"enable": False},
+)
+
+print(f"\nAfter disabling workbench: done")
+
+# Update: clear manage_connections by passing None
+session.update(
+ manage_connections=None,
+)
+
+print(f"\nAfter clearing manage_connections: done")
diff --git a/ts/examples/tool-router/src/session-update.ts b/ts/examples/tool-router/src/session-update.ts
new file mode 100644
index 000000000..a33757d8f
--- /dev/null
+++ b/ts/examples/tool-router/src/session-update.ts
@@ -0,0 +1,54 @@
+/**
+ * Session Update Example
+ *
+ * Demonstrates using session.update() to modify a session's configuration
+ * after creation — e.g. adding toolkits, changing workbench settings, or
+ * updating preload config without creating a new session.
+ *
+ * Usage:
+ * COMPOSIO_API_KEY=... bun src/session-update.ts
+ */
+import { Composio } from "@composio/core";
+
+const composio = new Composio({
+ apiKey: process.env.COMPOSIO_API_KEY,
+ baseURL: process.env.COMPOSIO_BASE_URL || undefined,
+});
+
+// Create a session with gmail only
+const session = await composio.create("session-update-demo", {
+ toolkits: ["gmail"],
+ manageConnections: false,
+});
+
+console.log(`Session created: ${session.sessionId}`);
+console.log(`Config version: ${session.configVersion}`);
+console.log(`Preload: ${JSON.stringify(session.preload)}`);
+
+// Update: add github toolkit, enable workbench, and preload a tool
+await session.update({
+ toolkits: { enable: ["gmail", "github"] },
+ workbench: { enable: true, sandboxSize: "medium" },
+ preload: { tools: ["GITHUB_CREATE_ISSUE"] },
+});
+
+console.log(`\nAfter update:`);
+console.log(`Config version: ${session.configVersion}`);
+console.log(`Preload: ${JSON.stringify(session.preload)}`);
+
+// Update: disable workbench entirely
+await session.update({
+ workbench: { enable: false },
+});
+
+console.log(`\nAfter disabling workbench:`);
+console.log(`Config version: ${session.configVersion}`);
+
+// Update: clear manage_connections by passing null
+await session.update({
+ manageConnections: null,
+});
+
+console.log(`\nAfter clearing manageConnections:`);
+console.log(`Config version: ${session.configVersion}`);
+console.log(`Warnings: ${JSON.stringify(session.warnings)}`);