Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
docs: update chat-app cookbook to use composio.use() for multi-turn
The chat app now creates the session once and reuses it across requests via composio.use(sessionId), which is the correct pattern for multi-turn chat apps. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Abir Taheer committed
May 8, 2026 at 03:11 UTC
63535afc4de6d55e0ceb455105650ab4af9573d9
2 files changed
+10
-2
docs/content/cookbooks/chat-app.mdx
+1
-1
@@ -54,7 +54,7 @@ A **session** scopes tools and credentials to a specific user. Create `app/api/c
54
55
<include meta='title="app/api/chat/route.ts"'>../../examples/chat-app/route.ts</include>
56
57
-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.
57
+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 the agent keeps its context across messages. In production, store the session ID per user in your database and use the user ID from your auth system.
58
59
## Build the chat UI
60
docs/examples/chat-app/route.ts
+9
-1
@@ -11,10 +11,18 @@ import {
11
12
const composio = new Composio({ provider: new VercelProvider() });
13
14
+// In production, store session IDs per user in your database
15
+let sessionId: string | null = null;
16
+
17
export async function POST(req: Request) {
18
const { messages }: { messages: UIMessage[] } = await req.json();
19
17
- const session = await composio.create("user_123");
20
+ // Reuse existing session or create a new one
21
+ const session = sessionId
22
+ ? await composio.use(sessionId)
23
+ : await composio.create("user_123");
24
+ sessionId = session.sessionId;
25
+
26
const tools = await session.tools();
27
28
const result = streamText({