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
bunch of fixes to native tools
Sushmithamallesh committed
Dec 15, 2025 at 23:15 UTC
b57f49ffa9ab0e8154522f9d10719c37edf0c458
9 files changed
+130
-105
fern/pages/src/tool-router/quickstart.mdx
+5
-5
@@ -38,8 +38,8 @@ npm install @composio/core @anthropic-ai/claude-agent-sdk
38
When the agent needs authentication, it will prompt the user with a link to connect their account. If you want to customise the authentication flow and have more control over the user experience, see [Manual Authentication](/tool-router/manually-authenticating-users).
39
40
<CodeGroup>
41
-<SnippetCode src="fern/snippets/tool-router/python/quickstart-claude.py" title="Python" for="python" />
42
-<SnippetCode src="fern/snippets/tool-router/typescript/quickstart-claude.ts" title="TypeScript" for="typescript" />
41
+<SnippetCode src="fern/snippets/tool-router/python/quickstart-mcp-claude.py" title="Python" for="python" />
42
+<SnippetCode src="fern/snippets/tool-router/typescript/quickstart-mcp-claude.ts" title="TypeScript" for="typescript" />
43
</CodeGroup>
44
</Step>
45
</Steps>
@@ -72,8 +72,8 @@ npm install @composio/core @openai/agents
72
When the agent needs authentication, it will prompt the user with a link to connect their account. If you want to customise the authentication flow and have more control over the user experience, see [Manual Authentication](/tool-router/manually-authenticating-users).
73
74
<CodeGroup>
75
-<SnippetCode src="fern/snippets/tool-router/python/quickstart-openai.py" title="Python" for="python" />
76
-<SnippetCode src="fern/snippets/tool-router/typescript/quickstart-openai.ts" title="TypeScript" for="typescript" />
75
+<SnippetCode src="fern/snippets/tool-router/python/quickstart-mcp-openai.py" title="Python" for="python" />
76
+<SnippetCode src="fern/snippets/tool-router/typescript/quickstart-mcp-openai.ts" title="TypeScript" for="typescript" />
77
</CodeGroup>
78
79
</Step>
@@ -101,7 +101,7 @@ npm install @composio/core ai @ai-sdk/anthropic @ai-sdk/mcp
101
102
When the agent needs authentication, it will prompt the user with a link to connect their account. If you want to customise the authentication flow and have more control over the user experience, see [Manual Authentication](/tool-router/manually-authenticating-users).
103
104
-<SnippetCode src="fern/snippets/tool-router/typescript/quickstart-vercel.ts" />
104
+<SnippetCode src="fern/snippets/tool-router/typescript/quickstart-mcp-vercel.ts" />
105
</Step>
106
</Steps>
107
fern/snippets/tool-router/python/quickstart-mcp-claude.py
renamed
fern/snippets/tool-router/python/quickstart-mcp-openai.py
renamed
fern/snippets/tool-router/python/quickstart-native-openai.py
+44
-46
@@ -7,7 +7,7 @@ from openai import OpenAI
7
# Load environment variables from .env file
8
load_dotenv()
9
10
-composio_api_key = os.environ["COMPOSIO_API_KEY"]
10
+composio_api_key = os.environ.get("COMPOSIO_API_KEY")
11
user_id = "user_123" # Your user's unique identifier
12
13
# Initialize Composio and create a Tool Router session
@@ -15,60 +15,58 @@ composio = Composio(api_key=composio_api_key)
15
session = composio.create(user_id=user_id)
16
17
# Initialize OpenAI client
18
-client = OpenAI(
19
- api_key=os.environ["OPENAI_API_KEY"]
20
-)
18
+client = OpenAI(api_key=os.environ.get("OPENAI_API_KEY"))
19
20
# Get Tool Router as a native tool
21
tool_router = session.get_tool_router()
22
25
-# Create a chat completion with the tool
26
-response = client.chat.completions.create(
27
- model="gpt-4-turbo-preview",
28
- messages=[
29
- {
30
- "role": "user",
31
- "content": (
32
- "Fetch all open issues from the composio GitHub repository "
33
- "and create a summary of the top 5 by priority"
34
- )
35
- }
36
- ],
37
- tools=[tool_router.tool],
38
- tool_choice="auto"
39
-)
23
+print("Assistant: What would you like me to do today?\n")
24
41
-print("Assistant:", response.choices[0].message.content)
42
-
43
-# Handle tool calls if the assistant wants to use Tool Router
44
-tool_calls = response.choices[0].message.tool_calls
45
-if tool_calls:
46
- tool_call = tool_calls[0]
25
+# Interactive loop
26
+messages = []
27
+while True:
28
+ user_input = input("> ")
29
+ if user_input == "exit":
30
+ break
31
48
- if tool_call.function.name == "composio_tool_router":
49
- # Execute the tool with Tool Router
50
- args = json.loads(tool_call.function.arguments)
51
- result = tool_router.execute(args)
52
-
53
- # Send the result back to OpenAI
54
- final_response = client.chat.completions.create(
55
- model="gpt-4-turbo-preview",
56
- messages=[
57
- {
58
- "role": "user",
59
- "content": (
60
- "Fetch all open issues from the composio GitHub repository "
61
- "and create a summary of the top 5 by priority"
62
- )
63
- },
64
- response.choices[0].message,
65
- {
32
+ # Add user message
33
+ messages.append({"role": "user", "content": user_input})
34
+
35
+ # Get response from OpenAI
36
+ response = client.chat.completions.create(
37
+ model="gpt-4-turbo-preview",
38
+ messages=messages,
39
+ tools=[tool_router.tool],
40
+ tool_choice="auto"
41
+ )
42
+
43
+ assistant_message = response.choices[0].message
44
+ messages.append(assistant_message)
45
+
46
+ # Handle tool calls
47
+ if assistant_message.tool_calls:
48
+ for tool_call in assistant_message.tool_calls:
49
+ if tool_call.function.name == "composio_tool_router":
50
+ # Execute the tool
51
+ args = json.loads(tool_call.function.arguments)
52
+ result = tool_router.execute(args)
53
+
54
+ # Add tool result to messages
55
+ messages.append({
56
"role": "tool",
57
"tool_call_id": tool_call.id,
58
"content": json.dumps(result)
69
- }
70
- ],
59
+ })
60
+
61
+ # Get final response after tool execution
62
+ final_response = client.chat.completions.create(
63
+ model="gpt-4-turbo-preview",
64
+ messages=messages,
65
tools=[tool_router.tool]
66
)
67
74
- print("Assistant:", final_response.choices[0].message.content)
\ No newline at end of file
68
+ final_message = final_response.choices[0].message
69
+ messages.append(final_message)
70
+ print(f"Assistant: {final_message.content}\n")
71
+ else:
72
+ print(f"Assistant: {assistant_message.content}\n")
\ No newline at end of file
fern/snippets/tool-router/typescript/quickstart-mcp-claude.ts
renamed
fern/snippets/tool-router/typescript/quickstart-mcp-openai.ts
renamed
fern/snippets/tool-router/typescript/quickstart-mcp-vercel.ts
renamed
fern/snippets/tool-router/typescript/quickstart-native-openai.ts
+47
-39
@@ -1,6 +1,7 @@
1
import "dotenv/config"; // Load environment variables from .env file
2
import { Composio } from "@composio/core";
3
import OpenAI from "openai";
4
+import { createInterface } from "readline/promises";
5
6
const composioApiKey = process.env.COMPOSIO_API_KEY;
7
const userId = "user_123"; // Your user's unique identifier
@@ -17,51 +18,58 @@ const openai = new OpenAI({
18
// Get Tool Router as a native tool
19
const toolRouter = await session.getToolRouter();
20
20
-// Create a chat completion with the tool
21
-const response = await openai.chat.completions.create({
22
- model: "gpt-4-turbo-preview",
23
- messages: [
24
- {
25
- role: "user",
26
- content: "Fetch all open issues from the composio/composio GitHub repository " +
27
- "and create a summary of the top 5 by priority",
28
- },
29
- ],
30
- tools: [toolRouter.tool],
31
- tool_choice: "auto",
32
-});
33
-
34
-console.log("Assistant:", response.choices[0].message.content);
21
+const rl = createInterface({ input: process.stdin, output: process.stdout });
22
+console.log("Assistant: What would you like me to do today?\n");
23
36
-// Handle tool calls if the assistant wants to use Tool Router
37
-const toolCalls = response.choices[0].message.tool_calls;
38
-if (toolCalls && toolCalls.length > 0) {
39
- const toolCall = toolCalls[0];
24
+// Interactive loop
25
+const messages: any[] = [];
26
+while (true) {
27
+ const userInput = await rl.question("> ");
28
+ if (userInput === "exit") break;
29
41
- if (toolCall.function.name === "composio_tool_router") {
42
- // Execute the tool with Tool Router
43
- const args = JSON.parse(toolCall.function.arguments);
44
- const result = await toolRouter.execute(args);
45
-
46
- // Send the result back to OpenAI
47
- const finalResponse = await openai.chat.completions.create({
48
- model: "gpt-4-turbo-preview",
49
- messages: [
50
- {
51
- role: "user",
52
- content: "Fetch all open issues from the composio/composio GitHub repository " +
53
- "and create a summary of the top 5 by priority",
54
- },
55
- response.choices[0].message,
56
- {
30
+ // Add user message
31
+ messages.push({ role: "user", content: userInput });
32
+
33
+ // Get response from OpenAI
34
+ const response = await openai.chat.completions.create({
35
+ model: "gpt-4-turbo-preview",
36
+ messages: messages,
37
+ tools: [toolRouter.tool],
38
+ tool_choice: "auto",
39
+ });
40
+
41
+ const assistantMessage = response.choices[0].message;
42
+ messages.push(assistantMessage);
43
+
44
+ // Handle tool calls
45
+ if (assistantMessage.tool_calls) {
46
+ for (const toolCall of assistantMessage.tool_calls) {
47
+ if (toolCall.function.name === "composio_tool_router") {
48
+ // Execute the tool
49
+ const args = JSON.parse(toolCall.function.arguments);
50
+ const result = await toolRouter.execute(args);
51
+
52
+ // Add tool result to messages
53
+ messages.push({
54
role: "tool",
55
tool_call_id: toolCall.id,
56
content: JSON.stringify(result),
60
- },
61
- ],
57
+ });
58
+ }
59
+ }
60
+
61
+ // Get final response after tool execution
62
+ const finalResponse = await openai.chat.completions.create({
63
+ model: "gpt-4-turbo-preview",
64
+ messages: messages,
65
tools: [toolRouter.tool],
66
});
67
65
- console.log("Assistant:", finalResponse.choices[0].message.content);
68
+ const finalMessage = finalResponse.choices[0].message;
69
+ messages.push(finalMessage);
70
+ console.log(`Assistant: ${finalMessage.content}\n`);
71
+ } else {
72
+ console.log(`Assistant: ${assistantMessage.content}\n`);
73
}
67
-}
\ No newline at end of file
74
+}
75
+rl.close();
\ No newline at end of file
fern/snippets/tool-router/typescript/quickstart-native-vercel.ts
+34
-15
@@ -2,6 +2,7 @@ import "dotenv/config"; // Load environment variables from .env file
2
import { Composio } from "@composio/core";
3
import { openai } from "@ai-sdk/openai";
4
import { generateText } from "ai";
5
+import { createInterface } from "readline/promises";
6
7
const composioApiKey = process.env.COMPOSIO_API_KEY;
8
const userId = "user_123"; // Your user's unique identifier
@@ -13,19 +14,37 @@ const session = await composio.create(userId);
14
// Get Tool Router as a native tool
15
const toolRouter = await session.getToolRouter();
16
16
-// Use with Vercel AI SDK
17
-const { text, toolCalls, toolResults } = await generateText({
18
- model: openai("gpt-4-turbo"),
19
- prompt: "Fetch all open issues from the composio/composio GitHub repository " +
20
- "and create a summary of the top 5 by priority",
21
- tools: {
22
- composio_tool_router: toolRouter.tool,
23
- },
24
-});
17
+const rl = createInterface({ input: process.stdin, output: process.stdout });
18
+console.log("Assistant: What would you like me to do today?\n");
19
26
-console.log("Result:", text);
27
-
28
-// If there were tool calls, they've already been executed
29
-if (toolResults && toolResults.length > 0) {
30
- console.log("Tool was called and executed successfully");
31
-}
\ No newline at end of file
20
+// Interactive loop with conversation history
21
+const messages: any[] = [];
22
+while (true) {
23
+ const userInput = await rl.question("> ");
24
+ if (userInput === "exit") break;
25
+
26
+ // Add user message to history
27
+ messages.push({ role: "user", content: userInput });
28
+
29
+ // Generate response with Vercel AI SDK
30
+ const { text, toolCalls, toolResults } = await generateText({
31
+ model: openai("gpt-4-turbo"),
32
+ messages: messages,
33
+ tools: {
34
+ composio_tool_router: toolRouter.tool,
35
+ },
36
+ });
37
+
38
+ // Add assistant response to history
39
+ messages.push({ role: "assistant", content: text });
40
+
41
+ // Show tool execution feedback
42
+ if (toolCalls && toolCalls.length > 0) {
43
+ for (const toolCall of toolCalls) {
44
+ console.log(`[Executed: ${toolCall.toolName}]`);
45
+ }
46
+ }
47
+
48
+ console.log(`Assistant: ${text}\n`);
49
+}
50
+rl.close();
\ No newline at end of file