Skip to content

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

Abir Taheer63535afc4de6
diff --git a/docs/content/cookbooks/chat-app.mdx b/docs/content/cookbooks/chat-app.mdx
index 9787e04b0..7c79aaa6c 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
<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 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.
## Build the chat UI
diff --git a/docs/examples/chat-app/route.ts b/docs/examples/chat-app/route.ts
index 97cf4a44c..60cbc1dd9 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({