diff --git a/docs/content/cookbooks/chat-app.mdx b/docs/content/cookbooks/chat-app.mdx index 9787e04b0e..8852744fda 100644 --- a/docs/content/cookbooks/chat-app.mdx +++ b/docs/content/cookbooks/chat-app.mdx @@ -54,7 +54,7 @@ A **session** scopes tools and credentials to a specific user. Create `app/api/c ../../examples/chat-app/route.ts -That's the entire backend. `composio.create("user_123")` creates a session that lets the agent search for tools, authenticate users, and execute actions. This ID scopes all connections and credentials to this user. In production, use the user ID from your auth system. +That's the entire backend. On the first request, `composio.create("user_123")` creates a session that lets the agent search for tools, authenticate users, and execute actions. Subsequent requests reuse the same session via `composio.use(sessionId)` so tool access and connected accounts carry over. In production, store the session ID per user in your database and use the user ID from your auth system. ## Build the chat UI diff --git a/docs/content/docs/users-and-sessions.mdx b/docs/content/docs/users-and-sessions.mdx index 6e8296260f..80bfe3670b 100644 --- a/docs/content/docs/users-and-sessions.mdx +++ b/docs/content/docs/users-and-sessions.mdx @@ -131,7 +131,38 @@ const tools = await session.tools(); -This returns the same session with the same toolkits, auth configs, and connected accounts. The session's configuration is fixed at creation — to change toolkits or auth, create a new session. +This returns the same session with the same toolkits, auth configs, and connected accounts. + +### Updating a session + +Use `session.update()` to modify a session's configuration without creating a new one. Only the fields you pass are changed — everything else is preserved. + + + +```python +session.update( + toolkits=["gmail", "slack"], + auth_configs={"gmail": "ac_new_config"}, + connected_accounts={"slack": ["ca_work_slack"]}, +) +``` + + +```typescript +import { Composio } from '@composio/core'; +const composio = new Composio({ apiKey: 'your_api_key' }); +const session = await composio.create("user_123"); +// ---cut--- +await session.update({ + toolkits: ["gmail", "slack"], + authConfigs: { gmail: "ac_new_config" }, + connectedAccounts: { slack: ["ca_work_slack"] }, +}); +``` + + + +You can update toolkits, auth configs, connected accounts, workbench settings, multi-account config, manage connections, tags, tools, and preload. See [Configuring Sessions](/docs/configuring-sessions) for the full list of options. ### Connected accounts persist across sessions diff --git a/docs/examples/chat-app/route.ts b/docs/examples/chat-app/route.ts index 97cf4a44c5..60cbc1dd91 100644 --- a/docs/examples/chat-app/route.ts +++ b/docs/examples/chat-app/route.ts @@ -11,10 +11,18 @@ import { const composio = new Composio({ provider: new VercelProvider() }); +// In production, store session IDs per user in your database +let sessionId: string | null = null; + export async function POST(req: Request) { const { messages }: { messages: UIMessage[] } = await req.json(); - const session = await composio.create("user_123"); + // Reuse existing session or create a new one + const session = sessionId + ? await composio.use(sessionId) + : await composio.create("user_123"); + sessionId = session.sessionId; + const tools = await session.tools(); const result = streamText({