@devries-cameron20 / composio Mirror · read-only / commits / a17ecef33
Fork 0

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

docs: add custom tool session reuse examples

Abir Taheer committed May 7, 2026 at 02:29 UTC a17ecef33a74c9b4bce74f413ddb8278bd7f7c5d
2 files changed +32 -12
ts/examples/tool-router/src/custom-tools-agent.ts
+17 -10
@@ -12,6 +12,7 @@
12 *
13 * Usage:
14 * COMPOSIO_API_KEY=... OPENAI_API_KEY=... bun src/custom-tools-agent.ts
15 + * COMPOSIO_SESSION_ID=... bun src/custom-tools-agent.ts # reuse a session
16 */
17 import "dotenv/config";
18 import { Composio, experimental_createTool, experimental_createToolkit } from "@composio/core";
@@ -161,6 +162,9 @@ const userManagement = experimental_createToolkit("USER_MANAGEMENT", {
162 tools: [setUserRole, updateUserStatus],
163 });
164
165 +const customTools = [getUserDetails, listUserKeys, formatGmailEmail];
166 +const customToolkits = [userManagement];
167 +
168 // ── Agent ─────────────────────────────────────────────────────────
169
170 const composio = new Composio({
@@ -169,16 +173,19 @@ const composio = new Composio({
173 provider: new OpenAIAgentsProvider(),
174 });
175
172 -const session = await composio.create("custom-tools-agent-user", {
173 - toolkits: ["weathermap", "gmail"],
174 - manageConnections: false,
175 - experimental: {
176 - customTools: [getUserDetails, listUserKeys, formatGmailEmail],
177 - customToolkits: [userManagement],
178 - },
179 -});
180 -
181 -console.log(`Session: ${session.sessionId}\n`);
176 +const existingSessionId = process.env.COMPOSIO_SESSION_ID;
177 +const session = existingSessionId
178 + ? await composio.use(existingSessionId, { customTools, customToolkits })
179 + : await composio.create("custom-tools-agent-user", {
180 + toolkits: ["weathermap", "gmail"],
181 + manageConnections: false,
182 + experimental: {
183 + customTools,
184 + customToolkits,
185 + },
186 + });
187 +
188 +console.log(`${existingSessionId ? "Reused" : "Created"} session: ${session.sessionId}\n`);
189 const tools = await session.tools();
190
191 const agent = new Agent({
ts/examples/tool-router/src/custom-tools-e2e.ts
+15 -2
@@ -139,6 +139,9 @@ const userManagement = experimental_createToolkit("USER_MANAGEMENT", {
139 tools: [setUserRole, updateUserStatus],
140 });
141
142 +const customTools = [getUserDetails, listUserKeys, formatGmailEmail];
143 +const customToolkits = [userManagement];
144 +
145 // ────────────────────────────────────────────────────────────────
146 // Run tests
147 // ────────────────────────────────────────────────────────────────
@@ -157,8 +160,8 @@ async function main() {
160 toolkits: ["weathermap", "gmail"],
161 manageConnections: false,
162 experimental: {
160 - customTools: [getUserDetails, listUserKeys, formatGmailEmail],
161 - customToolkits: [userManagement],
163 + customTools,
164 + customToolkits,
165 },
166 });
167 ok(`Session created: ${session.sessionId}`);
@@ -168,6 +171,16 @@ async function main() {
171 process.exit(1);
172 }
173
174 + // ── Existing session reuse with local custom definitions ──
175 + try {
176 + const reusedSession = await composio.use(session.sessionId, { customTools, customToolkits });
177 + const result = await reusedSession.execute("GET_USER_DETAILS", { user_id: "user-1" });
178 + if (result.data?.name !== "Alice Johnson") throw new Error(`Unexpected: ${JSON.stringify(result.data)}`);
179 + ok("Use: existing session binds custom tools for local execution");
180 + } catch (err) {
181 + fail("Use: existing session with custom tools", err);
182 + }
183 +
184 // ════════════════════════════════════════════════════════════════
185 // Standalone tools (LOCAL_GET_USER_DETAILS, LOCAL_LIST_USER_KEYS)
186 // ════════════════════════════════════════════════════════════════