@devries-cameron20 / composio Mirror · read-only / commits / b4e8ff4d8
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, 18:15 UTC

in chat auth

Sushmithamallesh committed Nov 30, 2025 at 00:25 UTC b4e8ff4d85e9c30d78a1bcff63805118a33c0d5d
3 files changed +173 -3
fern/pages/src/tool-router/using-in-chat-authentication.mdx
+80 -3
@@ -1,7 +1,84 @@
1 ---
2 -title: Using In-chat Authentication
2 +title: Using in-chat authentication
3 image: "https://og.composio.dev/api/og?title=Using%20In-chat%20Authentication"
4 -description: "Let your agent authenticate users via MANAGE_CONNECTIONS_TOOL"
5 -keywords: "tool router"
4 +description: "Let your agent prompt users to connect accounts during conversation"
5 +keywords: "tool router, authentication, in-chat, MANAGE_CONNECTIONS"
6 ---
7
8 +In-chat authentication lets your agent prompt users to connect accounts during chat. When a tool requires authentication, the agent returns a Connect Link URL. The user authenticates, confirms in chat, and the agent retries.
9 +
10 +## How it works
11 +
12 +1. User asks agent to do something (e.g., "star my repos")
13 +2. Agent tries to execute but user hasn't connected GitHub
14 +3. `COMPOSIO_MANAGE_CONNECTIONS` returns a Connect Link URL
15 +4. Agent shares the URL with the user
16 +5. User clicks, authenticates, returns to chat
17 +6. User confirms ("done") and agent retries successfully
18 +
19 +## Configuration
20 +
21 +In-chat auth is enabled by default. The `COMPOSIO_MANAGE_CONNECTIONS` meta-tool is included automatically.
22 +
23 +```typescript
24 +const session = await composio.createSession({
25 + user: "pg-user-550e8400-e29b-41d4",
26 + toolkits: ["github", "gmail"],
27 +});
28 +```
29 +
30 +### Custom callback URL
31 +
32 +Redirect users to a specific page after authentication:
33 +
34 +```typescript
35 +const session = await composio.createSession({
36 + user: "pg-user-550e8400-e29b-41d4",
37 + toolkits: ["github", "gmail"],
38 + manageConnections: {
39 + callbackUrl: "https://yourapp.com/chat",
40 + },
41 +});
42 +```
43 +
44 +### Disabling in-chat auth
45 +
46 +To manage authentication outside of chat, disable the `COMPOSIO_MANAGE_CONNECTIONS` tool:
47 +
48 +```typescript
49 +const session = await composio.createSession({
50 + user: "pg-user-550e8400-e29b-41d4",
51 + toolkits: ["github", "gmail"],
52 + manageConnections: false,
53 +});
54 +```
55 +
56 +See [Manually authenticating users](/tool-router/manually-authenticating-users) for the alternative approach.
57 +
58 +## Examples
59 +
60 +<CodeGroup>
61 +<CodeGroupItem title="Vercel AI SDK (TypeScript)">
62 +<SnippetCode src="fern/snippets/tool-router/typescript/in-chat-auth.ts" />
63 +</CodeGroupItem>
64 +<CodeGroupItem title="OpenAI Agents SDK (Python)">
65 +<SnippetCode src="fern/snippets/tool-router/python/in-chat-auth.py" />
66 +</CodeGroupItem>
67 +</CodeGroup>
68 +
69 +### Example conversation
70 +
71 +```
72 +You: Star the composio repo on GitHub
73 +
74 +Agent: I'll help you star the Composio repo. Let me search for the right tools.
75 +
76 +I found the tool to star repositories, but I need you to connect your GitHub
77 +account first. Please click the link below to authorize:
78 +https://connect.composio.dev/link/ln_abc123
79 +
80 +You: Done
81 +
82 +Agent: Done! I've starred ComposioHQ/composio.
83 +```
84 +
fern/snippets/tool-router/python/in-chat-auth.py new
+41
@@ -0,0 +1,41 @@
1 +import asyncio
2 +from composio import Composio
3 +from agents import Agent, Runner, HostedMCPTool
4 +
5 +composio = Composio()
6 +
7 +async def chat():
8 + session = await composio.create_session(
9 + user="pg-user-550e8400-e29b-41d4",
10 + )
11 +
12 + agent = Agent(
13 + name="GitHub Assistant",
14 + instructions="Help users with their GitHub repositories.",
15 + tools=[
16 + HostedMCPTool(
17 + tool_config={
18 + "type": "mcp",
19 + "server_label": "composio",
20 + "server_url": session.mcp.url,
21 + "require_approval": "never",
22 + }
23 + )
24 + ],
25 + )
26 +
27 + print("Chat with your agent. Type 'exit' to quit.\n")
28 +
29 + while True:
30 + user_input = input("You: ")
31 + if user_input.lower() == "exit":
32 + break
33 +
34 + result = await Runner.run(
35 + agent,
36 + user_input,
37 + )
38 +
39 + print(f"Agent: {result.final_output}\n")
40 +
41 +asyncio.run(chat())
fern/snippets/tool-router/typescript/in-chat-auth.ts new
+52
@@ -0,0 +1,52 @@
1 +import { Composio } from "@composio/core";
2 +import { VercelProvider } from "@composio/vercel";
3 +import { openai } from "@ai-sdk/openai";
4 +import { generateText } from "ai";
5 +import * as readline from "readline";
6 +
7 +const composio = new Composio({
8 + provider: new VercelProvider(),
9 +});
10 +
11 +async function chat() {
12 + const session = await composio.createSession({
13 + user: "pg-user-550e8400-e29b-41d4",
14 + });
15 +
16 + const tools = await session.tools();
17 + const messages: { role: "user" | "assistant"; content: string }[] = [];
18 +
19 + const rl = readline.createInterface({
20 + input: process.stdin,
21 + output: process.stdout,
22 + });
23 +
24 + console.log("Chat with your agent. Type 'exit' to quit.\n");
25 +
26 + const prompt = () => {
27 + rl.question("You: ", async (input) => {
28 + if (input.toLowerCase() === "exit") {
29 + rl.close();
30 + return;
31 + }
32 +
33 + messages.push({ role: "user", content: input });
34 +
35 + const { text } = await generateText({
36 + model: openai("gpt-4o"),
37 + tools,
38 + messages,
39 + maxSteps: 5,
40 + });
41 +
42 + console.log(`Agent: ${text}\n`);
43 + messages.push({ role: "assistant", content: text });
44 +
45 + prompt();
46 + });
47 + };
48 +
49 + prompt();
50 +}
51 +
52 +chat();