@devries-cameron20 / composio Mirror · read-only
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, 03:37 UTC

next
mdx 111 lines 3.27 KB
Raw
1 ---
2 title: "Session reuse, update, and connected accounts as arrays"
3 description: "composio.use() rehydrates sessions for multi-turn chat, session.update() patches config in-place, and connectedAccounts now accepts arrays."
4 date: "2026-05-08"
5 ---
6
7 ### Session reuse with `composio.use()`
8
9 `composio.create()` now returns a new session ID on every call, even for identical configs, for better isolation and observability. For multi-turn conversations, store the session ID and reuse it with `composio.use()`:
10
11 <Tabs groupId="language" items={['Python', 'TypeScript']} persist>
12 <Tab value="Python">
13 ```python
14 from composio import Composio
15
16 composio = Composio()
17
18 # First request
19 session = composio.create(user_id="user_123")
20 session_id = session.session_id
21
22 # Subsequent requests
23 session = composio.use(session_id)
24 tools = session.tools()
25 ```
26 </Tab>
27 <Tab value="TypeScript">
28 ```typescript
29 // @noErrors
30 import { Composio } from '@composio/core';
31 const composio = new Composio({ apiKey: 'your_api_key' });
32 // ---cut---
33 // First request
34 const session = await composio.create("user_123");
35 const sessionId = session.sessionId;
36
37 // Subsequent requests
38 const session = await composio.use(sessionId);
39 const tools = await session.tools();
40 ```
41 </Tab>
42 </Tabs>
43
44 Custom tools can also be attached when reusing a session. See [Reusing a session](/docs/how-composio-works#how-sessions-behave) and [Custom tools](/docs/extending-sessions/local-tools-and-toolkits#reusing-a-session-with-local-tools).
45
46 ### Update session config with `session.update()`
47
48 Modify a session's toolkits, auth configs, connected accounts, and other settings without creating a new session. Only the fields you pass are changed:
49
50 <Tabs groupId="language" items={['Python', 'TypeScript']} persist>
51 <Tab value="Python">
52 ```python
53 session.update(
54 toolkits=["gmail", "slack"],
55 auth_configs={"gmail": "ac_new_config"},
56 )
57 ```
58 </Tab>
59 <Tab value="TypeScript">
60 ```typescript
61 import { Composio } from '@composio/core';
62 const composio = new Composio({ apiKey: 'your_api_key' });
63 const session = await composio.create("user_123");
64 // ---cut---
65 await session.update({
66 toolkits: ["gmail", "slack"],
67 authConfigs: { gmail: "ac_new_config" },
68 });
69 ```
70 </Tab>
71 </Tabs>
72
73 See [Updating a session](/docs/how-composio-works#how-sessions-behave).
74
75 ### `connectedAccounts` accepts arrays
76
77 `connectedAccounts` (TypeScript) and `connected_accounts` (Python) now accept an array of connected account IDs per toolkit. A single string is still accepted for backwards compatibility and is automatically coerced to an array.
78
79 <Tabs groupId="language" items={['Python', 'TypeScript']} persist>
80 <Tab value="Python">
81 ```python
82 session = composio.create(
83 user_id="user_123",
84 connected_accounts={
85 "gmail": ["ca_work_gmail"],
86 },
87 )
88 ```
89 </Tab>
90 <Tab value="TypeScript">
91 ```typescript
92 import { Composio } from '@composio/core';
93 const composio = new Composio({ apiKey: 'your_api_key' });
94 // ---cut---
95 const session = await composio.create("user_123", {
96 connectedAccounts: {
97 gmail: ["ca_work_gmail"],
98 },
99 });
100 ```
101 </Tab>
102 </Tabs>
103
104 Only one account per toolkit is allowed when [multi-account mode](/docs/authentication/managing-multiple-connected-accounts) is disabled.
105
106 ### SDK versions
107
108 | SDK | Minimum version |
109 | --- | --- |
110 | TypeScript `@composio/core` | `0.9.1` |
111 | Python `composio` | `0.13.0` |