Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
fixes
Sushmithamallesh committed
Dec 16, 2025 at 00:32 UTC
dea7e4d75794ebab8e0428dd820b67997bb9c7db
6 files changed
+67
-169
fern/pages/src/tool-router/quickstart.mdx
+1
-1
@@ -158,7 +158,7 @@ Tool Router can be added as a single native tool to your agent. This provides a
158
<Steps>
159
<Step title="Install">
160
```bash title="TypeScript"
161
-npm install @composio/core ai @ai-sdk/openai
161
+npm install @composio/core @composio/vercel ai @ai-sdk/openai
162
```
163
</Step>
164
fern/pages/src/tool-router/using-as-a-native-tool.mdx
+5
-5
@@ -19,16 +19,16 @@ Jump to examples for:
19
20
<CodeGroup>
21
```bash title="Python" for="python"
22
-pip install composio openai
22
+pip install composio composio-openai-agents openai-agents
23
```
24
```bash title="TypeScript" for="typescript"
25
-npm install @composio/core openai
25
+npm install @composio/core @composio/openai-agents @openai/agents
26
```
27
</CodeGroup>
28
29
### Usage
30
31
-Create a Tool Router session and use it as a native tool:
31
+Create a Tool Router session and use it as a native tool with OpenAI Agents SDK:
32
33
<Info>
34
- Set your `COMPOSIO_API_KEY` environment variable with your API key from [Settings](https://platform.composio.dev/?next_page=/settings).
@@ -45,12 +45,12 @@ Create a Tool Router session and use it as a native tool:
45
### Installation
46
47
```bash
48
-npm install @composio/core ai @ai-sdk/openai
48
+npm install @composio/core @composio/vercel ai @ai-sdk/openai
49
```
50
51
### Usage
52
53
-Create a Tool Router session and use it as a native tool:
53
+Create a Tool Router session and use it as a native tool with Vercel AI SDK:
54
55
<Info>
56
- Set your `COMPOSIO_API_KEY` environment variable with your API key from [Settings](https://platform.composio.dev/?next_page=/settings).
fern/snippets/tool-router/python/native-tools-openai.py
+17
-61
@@ -1,74 +1,30 @@
1
import os
2
-import json
2
from dotenv import load_dotenv
3
from composio import Composio
5
-from openai import OpenAI
4
+from agents import Agent, Runner
5
+from composio_openai_agents import OpenAIAgentsProvider
6
7
# Load environment variables from .env file
8
load_dotenv()
9
10
-composio_api_key = os.environ["COMPOSIO_API_KEY"]
11
-user_id = "user_123" # Your user's unique identifier
10
+composio = Composio(api_key=os.environ.get("COMPOSIO_API_KEY"), provider=OpenAIAgentsProvider())
11
+session = composio.create(user_id="user_123")
12
13
-# Initialize Composio and create a Tool Router session
14
-composio = Composio(api_key=composio_api_key)
15
-session = composio.create(user_id=user_id)
13
+# Get native tools from Composio
14
+tools = session.tools()
15
17
-# Initialize OpenAI client
18
-client = OpenAI(
19
- api_key=os.environ["OPENAI_API_KEY"]
16
+# Create OpenAI agent with Composio tools
17
+agent = Agent(
18
+ name="AI Assistant",
19
+ instructions="You are a helpful assistant with access to external tools. Use the available tools to complete user requests.",
20
+ model="gpt-5.2",
21
+ tools=tools,
22
)
23
22
-# Get Tool Router as a native tool
23
-tool_router = session.get_tool_router()
24
-
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"
24
+# Run the agent with a specific task
25
+result = Runner.run_sync(
26
+ starting_agent=agent,
27
+ input="Fetch all open issues from the composio/composio GitHub repository and create a summary of the top 5 by priority"
28
)
29
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]
47
-
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
- {
66
- "role": "tool",
67
- "tool_call_id": tool_call.id,
68
- "content": json.dumps(result)
69
- }
70
- ],
71
- tools=[tool_router.tool]
72
- )
73
-
74
- print("Assistant:", final_response.choices[0].message.content)
\ No newline at end of file
30
+print(f"Assistant: {result.final_output}")
\ No newline at end of file
fern/snippets/tool-router/typescript/native-tools-openai.ts
+17
-55
@@ -1,67 +1,29 @@
1
import "dotenv/config"; // Load environment variables from .env file
2
import { Composio } from "@composio/core";
3
-import OpenAI from "openai";
3
+import { Agent, run } from "@openai/agents";
4
+import { OpenAIAgentsProvider } from "@composio/openai-agents";
5
6
const composioApiKey = process.env.COMPOSIO_API_KEY;
7
const userId = "user_123"; // Your user's unique identifier
8
8
-// Initialize Composio and create a Tool Router session
9
-const composio = new Composio({ apiKey: composioApiKey });
9
+const composio = new Composio({ apiKey: composioApiKey, provider: new OpenAIAgentsProvider() });
10
const session = await composio.create(userId);
11
12
-// Initialize OpenAI client
13
-const openai = new OpenAI({
14
- apiKey: process.env.OPENAI_API_KEY,
15
-});
16
-
17
-// Get Tool Router as a native tool
18
-const toolRouter = await session.getToolRouter();
12
+// Get native tools from Composio
13
+const tools = await session.tools();
14
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 GitHub repository " +
27
- "and create a summary of the top 5 by priority",
28
- },
29
- ],
30
- tools: [toolRouter.tool],
31
- tool_choice: "auto",
15
+// Create OpenAI agent with Composio tools
16
+const agent = new Agent({
17
+ name: "AI Assistant",
18
+ instructions: "You are a helpful assistant with access to external tools. Use the available tools to complete user requests.",
19
+ model: "gpt-5.2",
20
+ tools: tools,
21
});
22
34
-console.log("Assistant:", response.choices[0].message.content);
23
+// Run the agent with a specific task
24
+const result = await run(
25
+ agent,
26
+ "Fetch all open issues from the composio/composio GitHub repository and create a summary of the top 5 by priority"
27
+);
28
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];
40
-
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 GitHub repository " +
53
- "and create a summary of the top 5 by priority",
54
- },
55
- response.choices[0].message,
56
- {
57
- role: "tool",
58
- tool_call_id: toolCall.id,
59
- content: JSON.stringify(result),
60
- },
61
- ],
62
- tools: [toolRouter.tool],
63
- });
64
-
65
- console.log("Assistant:", finalResponse.choices[0].message.content);
66
- }
67
-}
\ No newline at end of file
29
+console.log(`Assistant: ${result.finalOutput}`);
\ No newline at end of file
fern/snippets/tool-router/typescript/native-tools-vercel.ts
+12
-19
@@ -1,31 +1,24 @@
1
import "dotenv/config"; // Load environment variables from .env file
2
import { Composio } from "@composio/core";
3
+import { VercelProvider } from "@composio/vercel";
4
import { openai } from "@ai-sdk/openai";
5
import { generateText } from "ai";
6
6
-const composioApiKey = process.env.COMPOSIO_API_KEY;
7
-const userId = "user_123"; // Your user's unique identifier
7
+const composio = new Composio({
8
+ apiKey: process.env.COMPOSIO_API_KEY,
9
+ provider: new VercelProvider(),
10
+});
11
9
-// Initialize Composio and create a Tool Router session
10
-const composio = new Composio({ apiKey: composioApiKey });
11
-const session = await composio.create(userId);
12
+const session = await composio.create("user_123");
13
13
-// Get Tool Router as a native tool
14
-const toolRouter = await session.getToolRouter();
14
+// Get native tools from Composio
15
+const tools = await session.tools();
16
17
// Use with Vercel AI SDK
17
-const { text, toolCalls, toolResults } = await generateText({
18
+const result = await generateText({
19
model: openai("gpt-4-turbo"),
19
- prompt: "Fetch all open issues from the composio GitHub repository " +
20
- "and create a summary of the top 5 by priority",
21
- tools: {
22
- composio_tool_router: toolRouter.tool,
23
- },
20
+ prompt: "Fetch all open issues from the composio/composio GitHub repository and create a summary of the top 5 by priority",
21
+ tools: tools,
22
});
23
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
24
+console.log(`Assistant: ${result.text}`);
\ No newline at end of file
fern/snippets/tool-router/typescript/quickstart-native-vercel.ts
+15
-28
@@ -1,50 +1,37 @@
1
-import "dotenv/config"; // Load environment variables from .env file
1
+import "dotenv/config";
2
import { Composio } from "@composio/core";
3
+import { VercelProvider } from "@composio/vercel";
4
import { openai } from "@ai-sdk/openai";
5
import { generateText } from "ai";
6
import { createInterface } from "readline/promises";
7
7
-const composioApiKey = process.env.COMPOSIO_API_KEY;
8
-const userId = "user_123"; // Your user's unique identifier
8
+const composio = new Composio({
9
+ apiKey: process.env.COMPOSIO_API_KEY,
10
+ provider: new VercelProvider(),
11
+});
12
10
-// Initialize Composio and create a Tool Router session
11
-const composio = new Composio({ apiKey: composioApiKey });
12
-const session = await composio.create(userId);
13
-
14
-// Get Tool Router as a native tool
15
-const toolRouter = await session.getToolRouter();
13
+const session = await composio.create("user_123");
14
+const tools = await session.tools();
15
16
const rl = createInterface({ input: process.stdin, output: process.stdout });
17
+const messages: any[] = [];
18
+
19
console.log("Assistant: What would you like me to do today?\n");
20
20
-// Interactive loop with conversation history
21
-const messages: any[] = [];
21
while (true) {
22
const userInput = await rl.question("> ");
23
if (userInput === "exit") break;
24
26
- // Add user message to history
25
messages.push({ role: "user", content: userInput });
26
29
- // Generate response with Vercel AI SDK
30
- const { text, toolCalls, toolResults } = await generateText({
27
+ const result = await generateText({
28
model: openai("gpt-4-turbo"),
29
messages: messages,
33
- tools: {
34
- composio_tool_router: toolRouter.tool,
35
- },
30
+ tools: tools,
31
});
32
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`);
33
+ messages.push({ role: "assistant", content: result.text });
34
+ console.log(`Assistant: ${result.text}\n`);
35
}
36
+
37
rl.close();
\ No newline at end of file