Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/content/cookbooks/chat-app.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ A **session** scopes tools and credentials to a specific user. Create `app/api/c

<include meta='title="app/api/chat/route.ts"'>../../examples/chat-app/route.ts</include>

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

Expand Down
33 changes: 32 additions & 1 deletion docs/content/docs/users-and-sessions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,38 @@ const tools = await session.tools();
</Tab>
</Tabs>

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.

<Tabs groupId="language" items={['Python', 'TypeScript']} persist>
<Tab value="Python">
```python
session.update(
toolkits=["gmail", "slack"],
auth_configs={"gmail": "ac_new_config"},
connected_accounts={"slack": ["ca_work_slack"]},
)
```
</Tab>
<Tab value="TypeScript">
```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"] },
});
```
</Tab>
</Tabs>

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

Expand Down
10 changes: 9 additions & 1 deletion docs/examples/chat-app/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Comment thread
abir-taheer marked this conversation as resolved.
Comment thread
abir-taheer marked this conversation as resolved.

const tools = await session.tools();

const result = streamText({
Expand Down
Loading