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.

native tools

Sushmithamalleshfef7a1517d04
diff --git a/fern/docs.yml b/fern/docs.yml
index b6b5a5130..aa782cf36 100644
--- a/fern/docs.yml
+++ b/fern/docs.yml
@@ -317,6 +317,9 @@ navigation:
- page: Using with MCP Clients
path: pages/dist/tool-router/using-with-mcp-clients.mdx
slug: using-with-mcp-clients
+ - page: Using as a native tool
+ path: pages/dist/tool-router/using-as-a-native-tool.mdx
+ slug: using-as-a-native-tool
- tab: providers
layout:
- section: Supported Providers
diff --git a/fern/pages/src/tool-router/overview.mdx b/fern/pages/src/tool-router/overview.mdx
index 13c9f1dcb..4e904637e 100644
--- a/fern/pages/src/tool-router/overview.mdx
+++ b/fern/pages/src/tool-router/overview.mdx
@@ -20,5 +20,5 @@ This is what powers complex agentic products like [Rube](https://rube.app).
## Quick links
- [Quickstart](/tool-router/quickstart): Build your first AI agent with Tool Router.
-- [Using with MCP clients](/tool-router/using-with-mcp-clients): Guides on how to use Tool Router MCP with popular MCP clients.
-{/* - [Using as native tools](/tool-router/using-as-native-tools): Guides on how to use Tool router as a tool with popular Agentic Providers. */}
+- [Using with MCP clients](/tool-router/using-with-mcp-clients): Guides on how to use Tool Router MCP with popular MCP clients.
+- [Using as a native tool](/tool-router/using-as-a-native-tool): Guide on how to use Tool Router as a native tool with any AI framework.
diff --git a/fern/pages/src/tool-router/quickstart.mdx b/fern/pages/src/tool-router/quickstart.mdx
index a3468ec96..b3fcd38a5 100644
--- a/fern/pages/src/tool-router/quickstart.mdx
+++ b/fern/pages/src/tool-router/quickstart.mdx
@@ -6,7 +6,10 @@ keywords: "tool router quickstart, quickstart"
hide-nav-links: false
---
-Build an interactive agent with access to 1000+ tools.
+Choose how you want to integrate Tool Router:
+
+<AccordionGroup>
+<Accordion title="Using Tool Router MCP">
<Tabs>
<Tab title="Claude Agent SDK">
@@ -105,15 +108,86 @@ When the agent needs authentication, it will prompt the user with a link to conn
</Tab>
</Tabs>
-## What just happened?
+### What just happened?
+
+When you run this agent, Tool Router:
+1. **Creates an MCP server** with your session configuration
+2. **Searches** for the right tools based on your request
+3. **Handles authentication** if needed
+4. **Executes tools** and uses a workbench for processing large responses
+
+</Accordion>
+
+<Accordion title="Using Tool router as a native tool">
+
+<Tabs>
+<Tab title="OpenAI">
+
+<Steps>
+<Step title="Install">
+<CodeGroup>
+```bash title="Python" for="python"
+pip install composio openai
+```
+```bash title="TypeScript" for="typescript"
+npm install @composio/core openai
+```
+</CodeGroup>
+</Step>
-When you ran this agent, Tool Router handled everything behind the scenes:
+<Step title="Create session and use as native tool">
+Tool Router can be added as a single native tool to your agent. This provides a meta-tool that handles search, authentication, and execution across all 1000+ Composio tools.
-1. **[Search](/tool-router/tool-search)** - Found the right Gmail tools from 1000+ available tools
-2. **[Authentication](/tool-router/authentication)** - Prompted you to connect your Gmail account
-3. **[Execution](/tool-router/tool-execution)** - Fetched your emails and processed results efficiently
+<Info>
+- Set your `COMPOSIO_API_KEY` environment variable with your API key from [Settings](https://platform.composio.dev/?next_page=/settings).
+- Set your `OPENAI_API_KEY` environment variable with your [OpenAI API key](https://platform.openai.com/api-keys).
+- `userId` is your user's unique identifier. See [User Management](/docs/user-management) for details.
+</Info>
-All you wrote was a prompt. Tool Router handled the rest!
+<CodeGroup>
+<SnippetCode src="fern/snippets/tool-router/python/quickstart-native-openai.py" title="Python" for="python" />
+<SnippetCode src="fern/snippets/tool-router/typescript/quickstart-native-openai.ts" title="TypeScript" for="typescript" />
+</CodeGroup>
+</Step>
+</Steps>
+
+</Tab>
+
+<Tab title="Vercel AI SDK">
+
+<Steps>
+<Step title="Install">
+```bash title="TypeScript"
+npm install @composio/core ai @ai-sdk/openai
+```
+</Step>
+
+<Step title="Create session and use as native tool">
+Tool Router can be added as a single native tool to your agent. This provides a meta-tool that handles search, authentication, and execution across all 1000+ Composio tools.
+
+<Info>
+- Set your `COMPOSIO_API_KEY` environment variable with your API key from [Settings](https://platform.composio.dev/?next_page=/settings).
+- Set your `OPENAI_API_KEY` environment variable with your [OpenAI API key](https://platform.openai.com/api-keys).
+- `userId` is your user's unique identifier. See [User Management](/docs/user-management) for details.
+</Info>
+
+<SnippetCode src="fern/snippets/tool-router/typescript/quickstart-native-vercel.ts" title="TypeScript" />
+</Step>
+</Steps>
+
+</Tab>
+</Tabs>
+
+### What just happened?
+
+When you run this agent, Tool Router:
+1. **Provides a single tool** to your agent framework
+2. **Interprets requests** and **searches** for the right tools internally
+3. **Handles authentication** if needed
+4. **Executes tools** and uses a workbench for processing large responses
+
+</Accordion>
+</AccordionGroup>
## Next steps
@@ -130,4 +204,7 @@ All you wrote was a prompt. Tool Router handled the rest!
<Card title="Using MCP" href="/tool-router/using-with-mcp-clients">
Connect Tool Router to any MCP-compatible client.
</Card>
+ <Card title="Using as a native tool" href="/tool-router/using-as-a-native-tool">
+ Use Tool Router as a native tool with any AI framework.
+ </Card>
</CardGroup>
diff --git a/fern/pages/src/tool-router/users-and-sessions.mdx b/fern/pages/src/tool-router/users-and-sessions.mdx
index d21fad36e..962109751 100644
--- a/fern/pages/src/tool-router/users-and-sessions.mdx
+++ b/fern/pages/src/tool-router/users-and-sessions.mdx
@@ -33,16 +33,29 @@ Restrict the session to specific toolkits:
<CodeGroup>
```python Python
+# Using array format
session = composio.create(
user_id="user_123",
toolkits=["github", "gmail", "slack"]
)
+
+# Using object format with enable key
+session = composio.create(
+ user_id="user_123",
+ toolkits={"enable": ["github", "gmail", "slack"]}
+)
```
```typescript TypeScript
+// Using array format
const session = await composio.create("user_123", {
toolkits: ["github", "gmail", "slack"],
});
+
+// Using object format with enable key
+const session = await composio.create("user_123", {
+ toolkits: { enable: ["github", "gmail", "slack"] },
+});
```
</CodeGroup>
@@ -54,13 +67,13 @@ Keep all toolkits enabled except specific ones:
```python Python
session = composio.create(
user_id="user_123",
- toolkits={"disabled": ["exa", "firecrawl"]}
+ toolkits={"disable": ["exa", "firecrawl"]}
)
```
```typescript TypeScript
const session = await composio.create("user_123", {
- toolkits: { disabled: ["exa", "firecrawl"] },
+ toolkits: { disable: ["exa", "firecrawl"] },
});
```
</CodeGroup>
@@ -150,7 +163,7 @@ console.log(mcp.url);
```
</CodeGroup>
-For framework examples, see [Using with MCP clients](/tool-router/using-with-mcp-clients).
+For framework examples, see [Using with MCP clients](/tool-router/using-with-mcp-clients) or [Using as a native tool](/tool-router/using-as-a-native-tool).
### authorize()
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
new file mode 100644
index 000000000..3ad0a7ee2
--- /dev/null
+++ b/fern/pages/src/tool-router/using-as-a-native-tool.mdx
@@ -0,0 +1,77 @@
+---
+title: Using as a native tool
+image: "https://og.composio.dev/api/og?title=Using%20as%20a%20Native%20Tool"
+description: "Use Tool Router as a native tool with any AI framework"
+keywords: "native tool, tool router, meta-tool"
+---
+
+Tool Router can be used as a single native tool with any AI framework. The tool handles search, authentication, and execution internally.
+
+## Examples for popular frameworks
+
+Jump to examples for:
+- [OpenAI](#openai) - Python, TypeScript
+- [Vercel AI SDK](#vercel-ai-sdk) - TypeScript
+
+## OpenAI
+
+### Installation
+
+<CodeGroup>
+```bash title="Python" for="python"
+pip install composio openai
+```
+```bash title="TypeScript" for="typescript"
+npm install @composio/core openai
+```
+</CodeGroup>
+
+### Usage
+
+Create a Tool Router session and use it as a native tool:
+
+<Info>
+- Set your `COMPOSIO_API_KEY` environment variable with your API key from [Settings](https://platform.composio.dev/?next_page=/settings).
+- Set your `OPENAI_API_KEY` environment variable with your [OpenAI API key](https://platform.openai.com/api-keys).
+</Info>
+
+<CodeGroup>
+<SnippetCode src="fern/snippets/tool-router/python/native-tools-openai.py" title="Python" />
+<SnippetCode src="fern/snippets/tool-router/typescript/native-tools-openai.ts" title="TypeScript" />
+</CodeGroup>
+
+## Vercel AI SDK
+
+### Installation
+
+```bash
+npm install @composio/core ai @ai-sdk/openai
+```
+
+### Usage
+
+Create a Tool Router session and use it as a native tool:
+
+<Info>
+- Set your `COMPOSIO_API_KEY` environment variable with your API key from [Settings](https://platform.composio.dev/?next_page=/settings).
+- Set your `OPENAI_API_KEY` environment variable with your [OpenAI API key](https://platform.openai.com/api-keys).
+</Info>
+
+<SnippetCode src="fern/snippets/tool-router/typescript/native-tools-vercel.ts" />
+
+## Next steps
+
+<CardGroup cols={2}>
+ <Card title="Quickstart" href="/tool-router/quickstart">
+ See both MCP and native tool in action
+ </Card>
+ <Card title="Using with MCP" href="/tool-router/using-with-mcp-clients">
+ Use Tool Router with MCP-compatible clients
+ </Card>
+ <Card title="Authentication" href="/tool-router/authentication">
+ Learn about authentication options
+ </Card>
+ <Card title="Session management" href="/tool-router/users-and-sessions">
+ Configure sessions for your users
+ </Card>
+</CardGroup>
\ No newline at end of file
diff --git a/fern/pages/src/tool-router/using-as-native-tools.mdx b/fern/pages/src/tool-router/using-as-native-tools.mdx
deleted file mode 100644
index 11a730dcb..000000000
--- a/fern/pages/src/tool-router/using-as-native-tools.mdx
+++ /dev/null
@@ -1,7 +0,0 @@
----
-title: Using as Native Tools
-image: "https://og.composio.dev/api/og?title=Using%20as%20Native%20Tools"
-description: "Use Tool Router tools directly with any agent framework"
-keywords: "tool router"
----
-
diff --git a/fern/snippets/tool-router/python/native-tools-openai.py b/fern/snippets/tool-router/python/native-tools-openai.py
new file mode 100644
index 000000000..b51f045ed
--- /dev/null
+++ b/fern/snippets/tool-router/python/native-tools-openai.py
@@ -0,0 +1,74 @@
+import os
+import json
+from dotenv import load_dotenv
+from composio import Composio
+from openai import OpenAI
+
+# 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
+
+# Initialize Composio and create a Tool Router session
+composio = Composio(api_key=composio_api_key)
+session = composio.create(user_id=user_id)
+
+# Initialize OpenAI client
+client = OpenAI(
+ api_key=os.environ["OPENAI_API_KEY"]
+)
+
+# 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/composio GitHub repository "
+ "and create a summary of the top 5 by priority"
+ )
+ }
+ ],
+ tools=[tool_router.tool],
+ tool_choice="auto"
+)
+
+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/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
diff --git a/fern/snippets/tool-router/python/quickstart-native-openai.py b/fern/snippets/tool-router/python/quickstart-native-openai.py
new file mode 100644
index 000000000..b51f045ed
--- /dev/null
+++ b/fern/snippets/tool-router/python/quickstart-native-openai.py
@@ -0,0 +1,74 @@
+import os
+import json
+from dotenv import load_dotenv
+from composio import Composio
+from openai import OpenAI
+
+# 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
+
+# Initialize Composio and create a Tool Router session
+composio = Composio(api_key=composio_api_key)
+session = composio.create(user_id=user_id)
+
+# Initialize OpenAI client
+client = OpenAI(
+ api_key=os.environ["OPENAI_API_KEY"]
+)
+
+# 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/composio GitHub repository "
+ "and create a summary of the top 5 by priority"
+ )
+ }
+ ],
+ tools=[tool_router.tool],
+ tool_choice="auto"
+)
+
+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/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
diff --git a/fern/snippets/tool-router/typescript/native-tools-openai.ts b/fern/snippets/tool-router/typescript/native-tools-openai.ts
new file mode 100644
index 000000000..d8f1afc49
--- /dev/null
+++ b/fern/snippets/tool-router/typescript/native-tools-openai.ts
@@ -0,0 +1,67 @@
+import "dotenv/config"; // Load environment variables from .env file
+import { Composio } from "@composio/core";
+import OpenAI from "openai";
+
+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 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();
+
+// 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/composio GitHub repository " +
+ "and create a summary of the top 5 by priority",
+ },
+ ],
+ tools: [toolRouter.tool],
+ tool_choice: "auto",
+});
+
+console.log("Assistant:", response.choices[0].message.content);
+
+// 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/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
diff --git a/fern/snippets/tool-router/typescript/native-tools-vercel.ts b/fern/snippets/tool-router/typescript/native-tools-vercel.ts
new file mode 100644
index 000000000..4eb3abd70
--- /dev/null
+++ b/fern/snippets/tool-router/typescript/native-tools-vercel.ts
@@ -0,0 +1,31 @@
+import "dotenv/config"; // Load environment variables from .env file
+import { Composio } from "@composio/core";
+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
+
+// 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();
+
+// Use with Vercel AI SDK
+const { text, toolCalls, toolResults } = await generateText({
+ model: openai("gpt-4-turbo"),
+ prompt: "Fetch all open issues from the composio/composio GitHub repository " +
+ "and create a summary of the top 5 by priority",
+ tools: {
+ composio_tool_router: toolRouter.tool,
+ },
+});
+
+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
diff --git a/fern/snippets/tool-router/typescript/quickstart-native-openai.ts b/fern/snippets/tool-router/typescript/quickstart-native-openai.ts
new file mode 100644
index 000000000..d8f1afc49
--- /dev/null
+++ b/fern/snippets/tool-router/typescript/quickstart-native-openai.ts
@@ -0,0 +1,67 @@
+import "dotenv/config"; // Load environment variables from .env file
+import { Composio } from "@composio/core";
+import OpenAI from "openai";
+
+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 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();
+
+// 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/composio GitHub repository " +
+ "and create a summary of the top 5 by priority",
+ },
+ ],
+ tools: [toolRouter.tool],
+ tool_choice: "auto",
+});
+
+console.log("Assistant:", response.choices[0].message.content);
+
+// 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/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
diff --git a/fern/snippets/tool-router/typescript/quickstart-native-vercel.ts b/fern/snippets/tool-router/typescript/quickstart-native-vercel.ts
new file mode 100644
index 000000000..4eb3abd70
--- /dev/null
+++ b/fern/snippets/tool-router/typescript/quickstart-native-vercel.ts
@@ -0,0 +1,31 @@
+import "dotenv/config"; // Load environment variables from .env file
+import { Composio } from "@composio/core";
+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
+
+// 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();
+
+// Use with Vercel AI SDK
+const { text, toolCalls, toolResults } = await generateText({
+ model: openai("gpt-4-turbo"),
+ prompt: "Fetch all open issues from the composio/composio GitHub repository " +
+ "and create a summary of the top 5 by priority",
+ tools: {
+ composio_tool_router: toolRouter.tool,
+ },
+});
+
+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