@devries-cameron20 / composio Mirror · read-only / commits / ddb52c7bd
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 22, 17:00 UTC

add

Sushmithamallesh committed Dec 10, 2025 at 20:31 UTC ddb52c7bdd07254b86a2790e0a9530c845b4608b
5 files changed +75 -156
fern/docs.yml
+3
@@ -314,6 +314,9 @@ navigation:
314 - page: Manually Authenticating Users
315 path: pages/dist/tool-router/manually-authenticating-users.mdx
316 slug: manually-authenticating-users
317 + - page: Managing Multiple Accounts for a User
318 + path: pages/dist/tool-router/managing-multiple-accounts.mdx
319 + slug: managing-multiple-accounts
320 - page: White-labeling Authentication
321 path: pages/dist/tool-router/white-labeling-authentication.mdx
322 slug: white-labeling-authentication
fern/pages/src/tool-router/managing-multiple-accounts.mdx new
+53
@@ -0,0 +1,53 @@
1 +---
2 +title: Managing multiple accounts for a user
3 +image: "https://og.composio.dev/api/og?title=Managing%20Multiple%20Accounts"
4 +description: "Handle users with multiple accounts for the same toolkit"
5 +keywords: "tool router, multiple accounts, connected accounts, account selection"
6 +---
7 +
8 +Users can connect multiple accounts for the same toolkit (e.g., personal and work Gmail). Tool Router uses the most recently connected account by default.
9 +
10 +## Selecting a specific account
11 +
12 +To use a specific account, pass it in the session config:
13 +
14 +<CodeGroup>
15 +```python
16 +session = composio.create(
17 + user_id=user_id,
18 + connected_accounts={
19 + "gmail": "ca_specific_account_id",
20 + },
21 +)
22 +```
23 +```typescript
24 +const session = await composio.create(userId, {
25 + connectedAccounts: {
26 + gmail: "ca_specific_account_id",
27 + },
28 +});
29 +```
30 +</CodeGroup>
31 +
32 +## Listing connected accounts
33 +
34 +Use `session.toolkits()` to see all connected accounts for a user:
35 +
36 +<CodeGroup>
37 +```python
38 +toolkits = session.toolkits()
39 +
40 +for toolkit in toolkits:
41 + if toolkit.connected_account:
42 + print(f"{toolkit.name}: {toolkit.connected_account.id}")
43 +```
44 +```typescript
45 +const toolkits = await session.toolkits();
46 +
47 +for (const toolkit of toolkits) {
48 + if (toolkit.connectedAccount) {
49 + console.log(`${toolkit.name}: ${toolkit.connectedAccount.id}`);
50 + }
51 +}
52 +```
53 +</CodeGroup>
fern/pages/src/tool-router/manually-authenticating-users.mdx
+9 -132
@@ -15,8 +15,8 @@ Disable the `COMPOSIO_MANAGE_CONNECTIONS` meta-tool so the agent doesn't prompt
15
16 <CodeGroup>
17 ```python
18 -session = await composio.create(
19 - user="user_123",
18 +session = composio.create(
19 + user_id="user_123",
20 manage_connections=False,
21 )
22 ```
@@ -33,7 +33,7 @@ Use `session.toolkits()` to see which apps the user has connected:
33
34 <CodeGroup>
35 ```python
36 -toolkits = await session.toolkits()
36 +toolkits = session.toolkits()
37
38 for toolkit in toolkits:
39 status = toolkit.connected_account.status if toolkit.connected_account else "Not connected"
@@ -59,7 +59,7 @@ Use filters to show relevant toolkits in your UI:
59
60 <CodeGroup>
61 ```python
62 -toolkits = await session.toolkits(
62 +toolkits = session.toolkits(
63 order_by="popularity", # Sort by most used
64 order_direction="desc",
65 category="developer-tools", # Filter by category
@@ -82,7 +82,7 @@ Use `session.authorize()` to generate a [Connect Link](/docs/authenticating-tool
82
83 <CodeGroup>
84 ```python
85 -connection_request = await session.authorize(
85 +connection_request = session.authorize(
86 "gmail",
87 callback_url="https://yourapp.com/callback"
88 )
@@ -92,7 +92,7 @@ print(connection_request.redirect_url)
92 ```
93 ```typescript
94 const connectionRequest = await session.authorize("gmail", {
95 - callbackUrl: "https://yourapp.com/callback",
95 + callbackUri: "https://yourapp.com/callback",
96 });
97
98 console.log(connectionRequest.redirectUrl);
@@ -108,7 +108,7 @@ Use `waitForConnection()` to poll until the user completes authentication:
108
109 <CodeGroup>
110 ```python
111 -connected_account = await connection_request.wait_for_connection(60000)
111 +connected_account = connection_request.wait_for_connection(60000)
112 print(f"Connected: {connected_account.id}")
113 ```
114 ```typescript
@@ -130,129 +130,6 @@ If the user closes the Connect Link without completing auth, the connection rema
130 A common pattern is to verify all required connections before starting the agent. For example, a personal assistant might need Gmail, Calendar, Linear, and Slack:
131
132 <CodeGroup>
133 -```python
134 -from composio import Composio
135 -from agents import Agent, Runner, HostedMCPTool
136 -
137 -composio = Composio()
138 -
139 -required_toolkits = ["gmail", "googlecalendar", "linear", "slack"]
140 -
141 -session = composio.create(
142 - user_id=user_id,
143 - manage_connections=False,
144 -)
145 -
146 -toolkits = session.toolkits()
147 -
148 -def is_connected(slug):
149 - toolkit = next((t for t in toolkits if t.slug == slug), None)
150 - return toolkit and toolkit.connected_account
151 -
152 -pending = [slug for slug in required_toolkits if not is_connected(slug)]
153 -
154 -if pending:
155 - for slug in pending:
156 - connection_request = session.authorize(
157 - slug,
158 - callback_url="https://yourapp.com/onboarding"
159 - )
160 - print(f"Connect {slug}: {connection_request.redirect_url}")
161 - connection_request.wait_for_connection()
162 -
163 -agent = Agent(
164 - name="Personal Assistant",
165 - instructions="You are a helpful personal assistant.",
166 - tools=[
167 - HostedMCPTool(
168 - tool_config={
169 - "type": "mcp",
170 - "server_label": "composio",
171 - "server_url": session.mcp.url,
172 - "require_approval": "never",
173 - }
174 - )
175 - ],
176 -)
177 -
178 -result = Runner.run_sync(agent, "Summarize my emails from today")
179 -print(result.final_output)
180 -```
181 -```typescript
182 -import { Composio } from "@composio/core";
183 -import { Agent, run, hostedMcpTool } from "@openai/agents";
184 -
185 -const composio = new Composio();
186 -
187 -const requiredToolkits = ["gmail", "googlecalendar", "linear", "slack"];
188 -
189 -const session = await composio.create(userId, {
190 - manageConnections: false,
191 -});
192 -
193 -const toolkits = await session.toolkits();
194 -
195 -const pending = requiredToolkits.filter((slug) => {
196 - const toolkit = toolkits.find((t) => t.slug === slug);
197 - return !toolkit?.connectedAccount;
198 -});
199 -
200 -for (const slug of pending) {
201 - const connectionRequest = await session.authorize(slug, {
202 - callbackUrl: "https://yourapp.com/onboarding",
203 - });
204 - console.log(`Connect ${slug}: ${connectionRequest.redirectUrl}`);
205 - await connectionRequest.waitForConnection();
206 -}
207 -
208 -const agent = new Agent({
209 - name: "Personal Assistant",
210 - instructions: "You are a helpful personal assistant.",
211 - tools: [
212 - hostedMcpTool({
213 - serverLabel: "composio",
214 - serverUrl: session.mcp.url,
215 - }),
216 - ],
217 -});
218 -
219 -const result = await run(agent, "Summarize my emails from today");
220 -console.log(result.finalOutput);
221 -```
133 +<SnippetCode src="fern/snippets/tool-router/python/manual-auth.py" title="Python" />
134 +<SnippetCode src="fern/snippets/tool-router/typescript/manual-auth.ts" title="TypeScript" />
135 </CodeGroup>
223 -
224 -## Multiple accounts
225 -
226 -Users can connect multiple accounts for the same toolkit (e.g., personal and work Gmail). Tool Router uses the most recently connected account by default.
227 -
228 -To use a specific account, pass it in the session config:
229 -
230 -<CodeGroup>
231 -```python
232 -session = await composio.create(
233 - user=user_id,
234 - connected_accounts={
235 - "gmail": "ca_specific_account_id",
236 - },
237 -)
238 -```
239 -```typescript
240 -const session = await composio.create(userId, {
241 - connectedAccounts: {
242 - gmail: "ca_specific_account_id",
243 - },
244 -});
245 -```
246 -</CodeGroup>
247 -
248 -## Full example
249 -
250 -<CodeGroup>
251 -<CodeGroupItem title="Python">
252 -<SnippetCode src="fern/snippets/tool-router/python/manual-auth.py" />
253 -</CodeGroupItem>
254 -<CodeGroupItem title="TypeScript">
255 -<SnippetCode src="fern/snippets/tool-router/typescript/manual-auth.ts" />
256 -</CodeGroupItem>
257 -</CodeGroup>
258 -
fern/snippets/tool-router/python/manual-auth.py
+3 -9
@@ -1,9 +1,8 @@
1 from composio import Composio
2 from agents import Agent, Runner, HostedMCPTool
3
4 -composio = Composio(api_key="your-composio-api-key")
4 +composio = Composio()
5
6 -user_id = "pg-user-550e8400-e29b-41d4"
6 required_toolkits = ["gmail", "googlecalendar", "linear", "slack"]
7
8 session = composio.create(
@@ -20,18 +19,13 @@ def is_connected(slug):
19 pending = [slug for slug in required_toolkits if not is_connected(slug)]
20
21 if pending:
23 - print("Connect these apps to continue:")
24 -
22 for slug in pending:
23 connection_request = session.authorize(
24 slug,
25 callback_url="https://yourapp.com/onboarding"
26 )
30 - print(f" {slug}: {connection_request.redirect_url}")
31 - connection_request.wait_for_connection(60000)
32 - print(f" {slug} connected")
33 -
34 -print("\nAll apps connected. Starting assistant...")
27 + print(f"Connect {slug}: {connection_request.redirect_url}")
28 + connection_request.wait_for_connection()
29
30 agent = Agent(
31 name="Personal Assistant",
fern/snippets/tool-router/typescript/manual-auth.ts
+7 -15
@@ -1,9 +1,8 @@
1 import { Composio } from "@composio/core";
2 import { Agent, run, hostedMcpTool } from "@openai/agents";
3
4 -const composio = new Composio({ apiKey: "your-composio-api-key" });
4 +const composio = new Composio();
5
6 -const userId = "pg-user-550e8400-e29b-41d4";
6 const requiredToolkits = ["gmail", "googlecalendar", "linear", "slack"];
7
8 const session = await composio.create(userId, {
@@ -17,21 +16,14 @@ const pending = requiredToolkits.filter((slug) => {
16 return !toolkit?.connectedAccount;
17 });
18
20 -if (pending.length > 0) {
21 - console.log("Connect these apps to continue:");
22 -
23 - for (const slug of pending) {
24 - const connectionRequest = await session.authorize(slug, {
25 - callbackUrl: "https://yourapp.com/onboarding",
26 - });
27 - console.log(` ${slug}: ${connectionRequest.redirectUrl}`);
28 - await connectionRequest.waitForConnection(60000);
29 - console.log(` ${slug} connected`);
30 - }
19 +for (const slug of pending) {
20 + const connectionRequest = await session.authorize(slug, {
21 + callbackUri: "https://yourapp.com/onboarding",
22 + });
23 + console.log(`Connect ${slug}: ${connectionRequest.redirectUrl}`);
24 + await connectionRequest.waitForConnection();
25 }
26
33 -console.log("\nAll apps connected. Starting assistant...");
34 -
27 const agent = new Agent({
28 name: "Personal Assistant",
29 instructions: "You are a helpful personal assistant.",