@devries-cameron20 / composio Mirror · read-only / commits / d9edb90bd
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, 17:00 UTC

in chat

Sushmithamallesh committed Dec 10, 2025 at 19:27 UTC d9edb90bd6895041694087fa8e1395df3b299304
3 files changed +80 -140
fern/pages/src/tool-router/using-in-chat-authentication.mdx
+13 -44
@@ -1,5 +1,5 @@
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 prompt users to connect accounts during conversation"
5 keywords: "tool router, authentication, in-chat, MANAGE_CONNECTIONS"
@@ -9,22 +9,25 @@ In-chat authentication lets your agent prompt users to connect accounts during c
9
10 ## How it works
11
12 -1. Agent searches for tools via `COMPOSIO_SEARCH_TOOLS`
13 -2. `COMPOSIO_MANAGE_CONNECTIONS` checks connection status, returns Connect Link URL if needed
12 +1. Agent searches for tools via the `COMPOSIO_SEARCH_TOOLS` meta-tool
13 +2. The `COMPOSIO_MANAGE_CONNECTIONS` meta-tool checks connection status, returns Connect Link URL if needed
14 3. User authenticates, confirms in chat, agent continues
15
16 ## Configuration
17
18 -In-chat auth is enabled by default. The `COMPOSIO_MANAGE_CONNECTIONS` meta-tool is included automatically.
18 +By just creating a session with default configs, you are enabling in-chat auth. The `manage_connections` parameter defaults to `True`, which includes the `COMPOSIO_MANAGE_CONNECTIONS` meta-tool automatically:
19
20 <CodeGroup>
21 ```python
22 session = await composio.create(
23 user="user_123",
24 + manage_connections=True, # default
25 )
26 ```
27 ```typescript
27 -const { mcp } = await composio.create("user_123");
28 +const session = await composio.create("user_123", {
29 + manageConnections: true, // default
30 +});
31 ```
32 </CodeGroup>
33
@@ -50,50 +53,16 @@ const { mcp } = await composio.create("user_123", {
53 ```
54 </CodeGroup>
55
53 -### Disabling in-chat auth
54 -
55 -To manage authentication outside of chat, disable the `COMPOSIO_MANAGE_CONNECTIONS` tool:
56 -
57 -<CodeGroup>
58 -```python
59 -session = await composio.create(
60 - user="user_123",
61 - manage_connections=False,
62 -)
63 -```
64 -```typescript
65 -const { mcp } = await composio.create("user_123", {
66 - manageConnections: false,
67 -});
68 -```
69 -</CodeGroup>
70 -
71 -See [Manually authenticating users](/tool-router/manually-authenticating-users) for the alternative approach.
72 -
56 ## Examples
57
58 <CodeGroup>
76 -<CodeGroupItem title="OpenAI Agents SDK (Python)">
77 -<SnippetCode src="fern/snippets/tool-router/python/in-chat-auth.py" />
78 -</CodeGroupItem>
79 -<CodeGroupItem title="Vercel AI SDK (TypeScript)">
80 -<SnippetCode src="fern/snippets/tool-router/typescript/in-chat-auth.ts" />
81 -</CodeGroupItem>
59 +<SnippetCode src="fern/snippets/tool-router/python/quickstart-openai.py" title="Python" />
60 +<SnippetCode src="fern/snippets/tool-router/typescript/quickstart-openai.ts" title="TypeScript" />
61 </CodeGroup>
62
84 -### Example conversation
85 -
86 -```
87 -You: Star the composio repo on GitHub
88 -
89 -Agent: I'll help you star the Composio repo. Let me search for the right tools.
90 -
91 -I found the tool to star repositories, but I need you to connect your GitHub
92 -account first. Please click the link below to authorize:
93 -https://connect.composio.dev/link/ln_abc123
94 -
95 -You: Done
63 +What this looks like when you run the code:
64
97 -Agent: Done! I've starred ComposioHQ/composio.
65 ```
66 +Assistant: What would you like me to do today?
67
68 +> Star the composio repo on GitHub
\ No newline at end of file
fern/snippets/tool-router/python/in-chat-auth.py
+34 -40
@@ -1,44 +1,38 @@
1 -import asyncio
1 +import os
2 from composio import Composio
3 -from agents import Agent, Runner, HostedMCPTool
4 -
5 -composio = Composio(api_key="your-composio-api-key")
6 -
7 -async def chat():
8 - print("Creating Tool Router session...")
9 - session = await composio.create("pg-user-550e8400-e29b-41d4")
10 - print(f"Tool Router session created: {session.mcp.url}")
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 - "headers": {
23 - "x-api-key": "your-composio-api-key",
24 - },
25 - }
26 - )
27 - ],
28 - )
29 -
30 - print("Chat with your agent. Type 'exit' to quit.\n")
31 -
32 - while True:
33 - user_input = input("You: ")
34 - if user_input.lower() == "exit":
35 - break
36 -
37 - result = await Runner.run(
38 - agent,
39 - user_input,
3 +from agents import Agent, Runner, HostedMCPTool, ModelSettings
4 +
5 +composio_api_key = os.environ.get("COMPOSIO_API_KEY")
6 +user_id = "user_123" # Your user's unique identifier
7 +
8 +composio = Composio()
9 +session = composio.create(user_id=user_id)
10 +
11 +agent = Agent(
12 + name="Personal Assistant",
13 + instructions="You are a helpful personal assistant. Use Composio tools to take action.",
14 + model="gpt-5.1",
15 + model_settings= ModelSettings(
16 + reasoning={"effort": "low"},
17 + ),
18 + tools=[
19 + HostedMCPTool(
20 + tool_config={
21 + "type": "mcp",
22 + "server_label": "composio",
23 + "server_url": session.mcp.url,
24 + "require_approval": "never",
25 + "headers": {"x-api-key": composio_api_key},
26 + }
27 )
28 + ],
29 +)
30
42 - print(f"Agent: {result.final_output}\n")
31 +print("Assistant: What would you like me to do today?\n")
32
44 -asyncio.run(chat())
33 +while True:
34 + user_input = input("> ")
35 + if user_input == "exit":
36 + break
37 + result = Runner.run_sync(starting_agent=agent, input=user_input)
38 + print(f"Assistant: {result.final_output}\n")
fern/snippets/tool-router/typescript/in-chat-auth.ts
+33 -56
@@ -1,60 +1,37 @@
1 -import { openai } from "@ai-sdk/openai";
2 -import { experimental_createMCPClient as createMCPClient } from "@ai-sdk/mcp";
1 import { Composio } from "@composio/core";
4 -import { generateText } from "ai";
5 -import * as readline from "readline";
6 -
7 -const composio = new Composio({ apiKey: "your-composio-api-key" });
8 -
9 -async function chat() {
10 - console.log("Creating Tool Router session...");
11 - const { mcp } = await composio.create("pg-user-550e8400-e29b-41d4");
12 - console.log(`Tool Router session created: ${mcp.url}`);
13 -
14 - const client = await createMCPClient({
15 - transport: {
16 - type: "http",
17 - url: mcp.url,
2 +import { Agent, run, hostedMcpTool } from "@openai/agents";
3 +import { createInterface } from "readline/promises";
4 +
5 +const composioApiKey = process.env.COMPOSIO_API_KEY;
6 +const userId = "user-1234"; // Your user's unique identifier
7 +
8 +const composio = new Composio({ apiKey: composioApiKey });
9 +const { mcp } = await composio.create(userId);
10 +
11 +const agent = new Agent({
12 + name: "Personal Assistant",
13 + instructions: "You are a helpful personal assistant. Use Composio tools to take action.",
14 + model: "gpt-5.1",
15 + modelSettings: {
16 + reasoning: { effort: "low" },
17 + },
18 + tools: [
19 + hostedMcpTool({
20 + serverLabel: "composio",
21 + serverUrl: mcp.url,
22 headers: {
19 - "x-api-key": "your-composio-api-key",
23 + "x-api-key": composioApiKey,
24 },
21 - },
22 - });
23 -
24 - const tools = await client.tools();
25 - const messages: { role: "user" | "assistant"; content: string }[] = [];
26 -
27 - const rl = readline.createInterface({
28 - input: process.stdin,
29 - output: process.stdout,
30 - });
31 -
32 - console.log("Chat with your agent. Type 'exit' to quit.\n");
33 -
34 - const prompt = () => {
35 - rl.question("You: ", async (input) => {
36 - if (input.toLowerCase() === "exit") {
37 - rl.close();
38 - return;
39 - }
40 -
41 - messages.push({ role: "user", content: input });
42 -
43 - const { text } = await generateText({
44 - model: openai("gpt-4o"),
45 - tools,
46 - messages,
47 - maxSteps: 5,
48 - });
49 -
50 - console.log(`Agent: ${text}\n`);
51 - messages.push({ role: "assistant", content: text });
52 -
53 - prompt();
54 - });
55 - };
56 -
57 - prompt();
25 + }),
26 + ],
27 +});
28 +
29 +const rl = createInterface({ input: process.stdin, output: process.stdout });
30 +console.log("Assistant: What would you like me to do today?\n");
31 +while (true) {
32 + const input = await rl.question("> ");
33 + if (input === "exit") break;
34 + const result = await run(agent, input);
35 + console.log(`Assistant: ${result.finalOutput}\n`);
36 }
59 -
60 -chat();
37 +rl.close();