Using as a native tool

Tool Router can be used as a single native tool with any AI framework. The tool handles search, authentication, and execution internally.

Jump to examples for:

OpenAI

Installation

$pip install composio composio-openai-agents openai-agents

Usage

Create a Tool Router session and use it as a native tool with OpenAI Agents SDK:

  • Set your COMPOSIO_API_KEY environment variable with your API key from Settings.
  • Set your OPENAI_API_KEY environment variable with your OpenAI API key.
1import os
2from dotenv import load_dotenv
3from composio import Composio
4from agents import Agent, Runner, SQLiteSession
5from composio_openai_agents import OpenAIAgentsProvider
6
7# Load environment variables from .env file
8load_dotenv()
9
10composio = Composio(api_key=os.environ.get("COMPOSIO_API_KEY"), provider=OpenAIAgentsProvider())
11session = composio.create(user_id="user_123")
12
13# Get native tools from Composio
14tools = session.tools()
15
16# Create OpenAI agent with Composio tools
17agent = Agent(
18 name="AI Assistant",
19 instructions="You are a helpful assistant with access to external tools. Always use the available tools to complete user requests instead of just explaining how to do them.",
20 model="gpt-5.2",
21 tools=tools,
22)
23
24# Create session for multi-turn conversation
25conversation_session = SQLiteSession("conversation_example")
26
27# Execute an initial task that requires GitHub access
28print("Executing initial task: Fetching GitHub issues...\n")
29result = Runner.run_sync(
30 starting_agent=agent,
31 input="Fetch all the open GitHub issues on the composio repository and group them by bugs/features/docs.",
32 session=conversation_session,
33)
34print(f"Result: {result.final_output}\n")
35
36# Continue with interactive conversation
37print("Assistant: What else would you like me to do? Type 'exit' to end the conversation.\n")
38
39while True:
40 user_input = input("> ")
41 if user_input.lower() == "exit":
42 break
43
44 # Run agent with session to maintain context
45 result = Runner.run_sync(
46 starting_agent=agent,
47 input=user_input,
48 session=conversation_session,
49 )
50
51 print(f"Assistant: {result.final_output}\n")

Vercel AI SDK

Installation

$npm install @composio/core @composio/vercel ai @ai-sdk/anthropic

Usage

Create a Tool Router session and use it as a native tool with Vercel AI SDK:

  • Set your COMPOSIO_API_KEY environment variable with your API key from Settings.
  • Set your ANTHROPIC_API_KEY environment variable with your Anthropic API key.
TypeScript
1import "dotenv/config";
2import { Composio } from "@composio/core";
3import { VercelProvider } from "@composio/vercel";
4import { generateText, stepCountIs, ModelMessage } from "ai";
5import { createInterface } from "readline/promises";
6import { anthropic } from "@ai-sdk/anthropic";
7
8const composio = new Composio({
9 apiKey: process.env.COMPOSIO_API_KEY,
10 provider: new VercelProvider(),
11});
12
13const session = await composio.create("user_123");
14const tools = await session.tools();
15
16const rl = createInterface({ input: process.stdin, output: process.stdout });
17const messages: ModelMessage[] = [];
18
19// Initial task
20const initialPrompt = "Fetch all the open GitHub issues on the composio repository and group them by bugs/features/docs.";
21console.log("Executing initial task: Fetching GitHub issues...\n");
22
23while (true) {
24 const userInput = messages.length === 0 ? initialPrompt : await rl.question("> ");
25 if (userInput.toLowerCase() === "exit") break;
26
27 messages.push({ role: "user", content: userInput });
28
29 const result = await generateText({
30 model: anthropic("claude-sonnet-4-5"),
31 messages: messages,
32 tools: tools,
33 stopWhen: stepCountIs(10),
34 });
35
36 messages.push({ role: "assistant", content: result.text });
37 console.log(`Assistant: ${result.text}\n`);
38}
39
40rl.close();

Next steps