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.

fixes

Sushmithamalleshdea7e4d75794
diff --git a/fern/pages/src/tool-router/quickstart.mdx b/fern/pages/src/tool-router/quickstart.mdx
index 836e6fb54..c11bd62d7 100644
--- a/fern/pages/src/tool-router/quickstart.mdx
+++ b/fern/pages/src/tool-router/quickstart.mdx
@@ -158,7 +158,7 @@ Tool Router can be added as a single native tool to your agent. This provides a
<Steps>
<Step title="Install">
```bash title="TypeScript"
-npm install @composio/core ai @ai-sdk/openai
+npm install @composio/core @composio/vercel ai @ai-sdk/openai
```
</Step>
diff --git a/fern/pages/src/tool-router/using-as-a-native-tool.mdx b/fern/pages/src/tool-router/using-as-a-native-tool.mdx
index 3ad0a7ee2..c40d35292 100644
--- a/fern/pages/src/tool-router/using-as-a-native-tool.mdx
+++ b/fern/pages/src/tool-router/using-as-a-native-tool.mdx
@@ -19,16 +19,16 @@ Jump to examples for:
<CodeGroup>
```bash title="Python" for="python"
-pip install composio openai
+pip install composio composio-openai-agents openai-agents
```
```bash title="TypeScript" for="typescript"
-npm install @composio/core openai
+npm install @composio/core @composio/openai-agents @openai/agents
```
</CodeGroup>
### Usage
-Create a Tool Router session and use it as a native tool:
+Create a Tool Router session and use it as a native tool with OpenAI Agents SDK:
<Info>
- 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:
### Installation
```bash
-npm install @composio/core ai @ai-sdk/openai
+npm install @composio/core @composio/vercel ai @ai-sdk/openai
```
### Usage
-Create a Tool Router session and use it as a native tool:
+Create a Tool Router session and use it as a native tool with Vercel AI SDK:
<Info>
- Set your `COMPOSIO_API_KEY` environment variable with your API key from [Settings](https://platform.composio.dev/?next_page=/settings).
diff --git a/fern/snippets/tool-router/python/native-tools-openai.py b/fern/snippets/tool-router/python/native-tools-openai.py
index 9791eb9de..014f16a32 100644
--- a/fern/snippets/tool-router/python/native-tools-openai.py
+++ b/fern/snippets/tool-router/python/native-tools-openai.py
@@ -1,74 +1,30 @@
import os
-import json
from dotenv import load_dotenv
from composio import Composio
-from openai import OpenAI
+from agents import Agent, Runner
+from composio_openai_agents import OpenAIAgentsProvider
# Load environment variables from .env file
load_dotenv()
-composio_api_key = os.environ["COMPOSIO_API_KEY"]
-user_id = "user_123" # Your user's unique identifier
+composio = Composio(api_key=os.environ.get("COMPOSIO_API_KEY"), provider=OpenAIAgentsProvider())
+session = composio.create(user_id="user_123")
-# Initialize Composio and create a Tool Router session
-composio = Composio(api_key=composio_api_key)
-session = composio.create(user_id=user_id)
+# Get native tools from Composio
+tools = session.tools()
-# Initialize OpenAI client
-client = OpenAI(
- api_key=os.environ["OPENAI_API_KEY"]
+# Create OpenAI agent with Composio tools
+agent = Agent(
+ name="AI Assistant",
+ instructions="You are a helpful assistant with access to external tools. Use the available tools to complete user requests.",
+ model="gpt-5.2",
+ tools=tools,
)
-# Get Tool Router as a native tool
-tool_router = session.get_tool_router()
-
-# Create a chat completion with the tool
-response = client.chat.completions.create(
- model="gpt-4-turbo-preview",
- messages=[
- {
- "role": "user",
- "content": (
- "Fetch all open issues from the composio GitHub repository "
- "and create a summary of the top 5 by priority"
- )
- }
- ],
- tools=[tool_router.tool],
- tool_choice="auto"
+# Run the agent with a specific task
+result = Runner.run_sync(
+ starting_agent=agent,
+ input="Fetch all open issues from the composio/composio GitHub repository and create a summary of the top 5 by priority"
)
-print("Assistant:", response.choices[0].message.content)
-
-# Handle tool calls if the assistant wants to use Tool Router
-tool_calls = response.choices[0].message.tool_calls
-if tool_calls:
- tool_call = tool_calls[0]
-
- if tool_call.function.name == "composio_tool_router":
- # Execute the tool with Tool Router
- args = json.loads(tool_call.function.arguments)
- result = tool_router.execute(args)
-
- # Send the result back to OpenAI
- final_response = client.chat.completions.create(
- model="gpt-4-turbo-preview",
- messages=[
- {
- "role": "user",
- "content": (
- "Fetch all open issues from the composio GitHub repository "
- "and create a summary of the top 5 by priority"
- )
- },
- response.choices[0].message,
- {
- "role": "tool",
- "tool_call_id": tool_call.id,
- "content": json.dumps(result)
- }
- ],
- tools=[tool_router.tool]
- )
-
- print("Assistant:", final_response.choices[0].message.content)
\ No newline at end of file
+print(f"Assistant: {result.final_output}")
\ No newline at end of file
diff --git a/fern/snippets/tool-router/typescript/native-tools-openai.ts b/fern/snippets/tool-router/typescript/native-tools-openai.ts
index be7896203..8f4d91108 100644
--- a/fern/snippets/tool-router/typescript/native-tools-openai.ts
+++ b/fern/snippets/tool-router/typescript/native-tools-openai.ts
@@ -1,67 +1,29 @@
import "dotenv/config"; // Load environment variables from .env file
import { Composio } from "@composio/core";
-import OpenAI from "openai";
+import { Agent, run } from "@openai/agents";
+import { OpenAIAgentsProvider } from "@composio/openai-agents";
const composioApiKey = process.env.COMPOSIO_API_KEY;
const userId = "user_123"; // Your user's unique identifier
-// Initialize Composio and create a Tool Router session
-const composio = new Composio({ apiKey: composioApiKey });
+const composio = new Composio({ apiKey: composioApiKey, provider: new OpenAIAgentsProvider() });
const session = await composio.create(userId);
-// Initialize OpenAI client
-const openai = new OpenAI({
- apiKey: process.env.OPENAI_API_KEY,
-});
-
-// Get Tool Router as a native tool
-const toolRouter = await session.getToolRouter();
+// Get native tools from Composio
+const tools = await session.tools();
-// Create a chat completion with the tool
-const response = await openai.chat.completions.create({
- model: "gpt-4-turbo-preview",
- messages: [
- {
- role: "user",
- content: "Fetch all open issues from the composio GitHub repository " +
- "and create a summary of the top 5 by priority",
- },
- ],
- tools: [toolRouter.tool],
- tool_choice: "auto",
+// Create OpenAI agent with Composio tools
+const agent = new Agent({
+ name: "AI Assistant",
+ instructions: "You are a helpful assistant with access to external tools. Use the available tools to complete user requests.",
+ model: "gpt-5.2",
+ tools: tools,
});
-console.log("Assistant:", response.choices[0].message.content);
+// Run the agent with a specific task
+const result = await run(
+ agent,
+ "Fetch all open issues from the composio/composio GitHub repository and create a summary of the top 5 by priority"
+);
-// Handle tool calls if the assistant wants to use Tool Router
-const toolCalls = response.choices[0].message.tool_calls;
-if (toolCalls && toolCalls.length > 0) {
- const toolCall = toolCalls[0];
-
- if (toolCall.function.name === "composio_tool_router") {
- // Execute the tool with Tool Router
- const args = JSON.parse(toolCall.function.arguments);
- const result = await toolRouter.execute(args);
-
- // Send the result back to OpenAI
- const finalResponse = await openai.chat.completions.create({
- model: "gpt-4-turbo-preview",
- messages: [
- {
- role: "user",
- content: "Fetch all open issues from the composio GitHub repository " +
- "and create a summary of the top 5 by priority",
- },
- response.choices[0].message,
- {
- role: "tool",
- tool_call_id: toolCall.id,
- content: JSON.stringify(result),
- },
- ],
- tools: [toolRouter.tool],
- });
-
- console.log("Assistant:", finalResponse.choices[0].message.content);
- }
-}
\ No newline at end of file
+console.log(`Assistant: ${result.finalOutput}`);
\ No newline at end of file
diff --git a/fern/snippets/tool-router/typescript/native-tools-vercel.ts b/fern/snippets/tool-router/typescript/native-tools-vercel.ts
index b575015b6..2eb1f4c23 100644
--- a/fern/snippets/tool-router/typescript/native-tools-vercel.ts
+++ b/fern/snippets/tool-router/typescript/native-tools-vercel.ts
@@ -1,31 +1,24 @@
import "dotenv/config"; // Load environment variables from .env file
import { Composio } from "@composio/core";
+import { VercelProvider } from "@composio/vercel";
import { openai } from "@ai-sdk/openai";
import { generateText } from "ai";
-const composioApiKey = process.env.COMPOSIO_API_KEY;
-const userId = "user_123"; // Your user's unique identifier
+const composio = new Composio({
+ apiKey: process.env.COMPOSIO_API_KEY,
+ provider: new VercelProvider(),
+});
-// Initialize Composio and create a Tool Router session
-const composio = new Composio({ apiKey: composioApiKey });
-const session = await composio.create(userId);
+const session = await composio.create("user_123");
-// Get Tool Router as a native tool
-const toolRouter = await session.getToolRouter();
+// Get native tools from Composio
+const tools = await session.tools();
// Use with Vercel AI SDK
-const { text, toolCalls, toolResults } = await generateText({
+const result = await generateText({
model: openai("gpt-4-turbo"),
- prompt: "Fetch all open issues from the composio GitHub repository " +
- "and create a summary of the top 5 by priority",
- tools: {
- composio_tool_router: toolRouter.tool,
- },
+ prompt: "Fetch all open issues from the composio/composio GitHub repository and create a summary of the top 5 by priority",
+ tools: tools,
});
-console.log("Result:", text);
-
-// If there were tool calls, they've already been executed
-if (toolResults && toolResults.length > 0) {
- console.log("Tool was called and executed successfully");
-}
\ No newline at end of file
+console.log(`Assistant: ${result.text}`);
\ No newline at end of file
diff --git a/fern/snippets/tool-router/typescript/quickstart-native-vercel.ts b/fern/snippets/tool-router/typescript/quickstart-native-vercel.ts
index 8949063dd..bf4b7be4b 100644
--- a/fern/snippets/tool-router/typescript/quickstart-native-vercel.ts
+++ b/fern/snippets/tool-router/typescript/quickstart-native-vercel.ts
@@ -1,50 +1,37 @@
-import "dotenv/config"; // Load environment variables from .env file
+import "dotenv/config";
import { Composio } from "@composio/core";
+import { VercelProvider } from "@composio/vercel";
import { openai } from "@ai-sdk/openai";
import { generateText } from "ai";
import { createInterface } from "readline/promises";
-const composioApiKey = process.env.COMPOSIO_API_KEY;
-const userId = "user_123"; // Your user's unique identifier
+const composio = new Composio({
+ apiKey: process.env.COMPOSIO_API_KEY,
+ provider: new VercelProvider(),
+});
-// Initialize Composio and create a Tool Router session
-const composio = new Composio({ apiKey: composioApiKey });
-const session = await composio.create(userId);
-
-// Get Tool Router as a native tool
-const toolRouter = await session.getToolRouter();
+const session = await composio.create("user_123");
+const tools = await session.tools();
const rl = createInterface({ input: process.stdin, output: process.stdout });
+const messages: any[] = [];
+
console.log("Assistant: What would you like me to do today?\n");
-// Interactive loop with conversation history
-const messages: any[] = [];
while (true) {
const userInput = await rl.question("> ");
if (userInput === "exit") break;
- // Add user message to history
messages.push({ role: "user", content: userInput });
- // Generate response with Vercel AI SDK
- const { text, toolCalls, toolResults } = await generateText({
+ const result = await generateText({
model: openai("gpt-4-turbo"),
messages: messages,
- tools: {
- composio_tool_router: toolRouter.tool,
- },
+ tools: tools,
});
- // Add assistant response to history
- messages.push({ role: "assistant", content: text });
-
- // Show tool execution feedback
- if (toolCalls && toolCalls.length > 0) {
- for (const toolCall of toolCalls) {
- console.log(`[Executed: ${toolCall.toolName}]`);
- }
- }
-
- console.log(`Assistant: ${text}\n`);
+ messages.push({ role: "assistant", content: result.text });
+ console.log(`Assistant: ${result.text}\n`);
}
+
rl.close();
\ No newline at end of file