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 python-dotenv 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.
1from dotenv import load_dotenv
2from composio import Composio
3from agents import Agent, Runner, SQLiteSession
4from composio_openai_agents import OpenAIAgentsProvider
5
6load_dotenv()
7
8# Initialize Composio with OpenAI Agents provider (API key from env var COMPOSIO_API_KEY)
9composio = Composio(provider=OpenAIAgentsProvider())
10
11# Unique identifier of the user
12user_id = "user_123"
13
14# Create a session and get native tools for the user
15session = composio.create(user_id=user_id)
16tools = session.tools()
17
18# Configure OpenAI agent with Composio tools
19agent = Agent(
20 name="Personal Assistant",
21 instructions="You are a helpful personal assistant. Use Composio tools to take action.",
22 model="gpt-5.2",
23 tools=tools,
24)
25
26# Memory for multi-turn conversation
27memory = SQLiteSession("conversation")
28
29# Execute an initial task
30print("Fetching GitHub issues from the Composio repository...\n")
31try:
32 result = Runner.run_sync(
33 starting_agent=agent,
34 input="Fetch all the open GitHub issues on the @ComposioHQ/composio repository and group them by bugs/features/docs.",
35 session=memory,
36 )
37 print(f"{result.final_output}\n")
38except Exception as e:
39 print(f"[Error]: {e}")
40
41# Continue with interactive conversation
42print("\nWhat else would you like me to do? (Type 'exit' to exit)")
43
44while True:
45 user_input = input("You: ").strip()
46 if user_input.lower() == "exit":
47 break
48
49 print("Assistant: ", end="", flush=True)
50 try:
51 result = Runner.run_sync(starting_agent=agent, input=user_input, session=memory)
52 print(f"{result.final_output}\n")
53 except Exception as e:
54 print(f"\n[Error]: {e}")

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 { anthropic } from "@ai-sdk/anthropic";
3import { Composio } from "@composio/core";
4import { VercelProvider } from "@composio/vercel";
5import { stepCountIs, streamText } from "ai";
6
7// Initialize Composio with Vercel provider (API key from env var COMPOSIO_API_KEY)
8const composio = new Composio({ provider: new VercelProvider() });
9
10// Unique identifier of the user
11const userId = "user_123";
12
13// Create a session and get native tools for the user
14const session = await composio.create(userId);
15const tools = await session.tools();
16
17console.log("Fetching GitHub issues from the Composio repository...");
18
19// Stream the response with tool calling
20const stream = await streamText({
21 system: "You are a helpful personal assistant. Use Composio tools to take action.",
22 model: anthropic("claude-sonnet-4-5"),
23 prompt: "Fetch all the open GitHub issues on the composio repository and group them by bugs/features/docs.",
24 stopWhen: stepCountIs(10),
25 onStepFinish: (step) => {
26 for (const toolCall of step.toolCalls) {
27 console.log(`[Using tool: ${toolCall.toolName}]`);
28 }
29 },
30 tools,
31});
32
33for await (const textPart of stream.textStream) {
34 process.stdout.write(textPart);
35}
36
37console.log("\n\n---");
38console.log("Tip: If prompted to authenticate, complete the auth flow and run again.");

Next steps