Quickstart

Choose how you want to integrate Tool Router:

1

Install

$pip install python-dotenv composio claude-agent-sdk
2

Create session and run agent

Sessions are ephemeral, user-scoped and manage connections and tools for that user.

  • Set COMPOSIO_API_KEY environment variable with your API key from Settings.
  • Set ANTHROPIC_API_KEY environment variable with your Anthropic API key.
  • userId is your user’s unique identifier. See User Management for details.

When the agent needs authentication, it will prompt the user with a link to connect their account. If you want to customise the authentication flow and have more control over the user experience, see Manual Authentication.

1import asyncio
2from dotenv import load_dotenv
3from claude_agent_sdk.client import ClaudeSDKClient
4from claude_agent_sdk.types import (
5 ClaudeAgentOptions,
6 AssistantMessage,
7 TextBlock,
8 ToolUseBlock,
9)
10from composio import Composio
11
12load_dotenv()
13
14# Initialize Composio (API key from env var COMPOSIO_API_KEY)
15composio = Composio()
16
17# Unique identifier of the user
18user_id = "user_123"
19
20# Create a tool router session for the user
21session = composio.create(user_id=user_id)
22
23# Configure Claude with Composio MCP server
24options = ClaudeAgentOptions(
25 system_prompt=(
26 "You are a helpful assistant with access to external tools. "
27 "Always use the available tools to complete user requests."
28 ),
29 mcp_servers={
30 "composio": {
31 "type": "http",
32 "url": session.mcp.url,
33 "headers": session.mcp.headers,
34 }
35 },
36 permission_mode="bypassPermissions",
37)
38
39
40async def main():
41 print("""
42What task would you like me to help you with?
43I can use tools like Gmail, GitHub, Linear, Notion, and more.
44(Type 'exit' to exit)
45Example tasks:
46 • 'Summarize my emails from today'
47 • 'List all open issues on the composio github repository and create a notion page with the issues'
48""")
49
50 async with ClaudeSDKClient(options) as client:
51 # Multi-turn conversation with agentic tool calling
52 while True:
53 user_input = input("You: ").strip()
54 if user_input.lower() == "exit":
55 break
56
57 print("\nClaude: ", end="", flush=True)
58 try:
59 await client.query(user_input)
60 async for msg in client.receive_response():
61 if isinstance(msg, AssistantMessage):
62 for block in msg.content:
63 if isinstance(block, ToolUseBlock):
64 print(f"\n[Using tool: {block.name}]", end="")
65 elif isinstance(block, TextBlock):
66 print(block.text, end="", flush=True)
67 print()
68 except Exception as e:
69 print(f"\n[Error]: {e}")
70
71
72if __name__ == "__main__":
73 asyncio.run(main())

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
1

Install

$pip install python-dotenv composio composio-openai-agents openai-agents
2

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.

  • Set COMPOSIO_API_KEY environment variable with your API key from Settings.
  • Set OPENAI_API_KEY environment variable with your OpenAI API key.
  • userId is your user’s unique identifier. See User Management for details.
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
29print("""
30What task would you like me to help you with?
31I can use tools like Gmail, GitHub, Linear, Notion, and more.
32(Type 'exit' to exit)
33Example tasks:
34 • 'Summarize my emails from today'
35 • 'List all open issues on the composio github repository'
36""")
37
38while True:
39 user_input = input("You: ").strip()
40 if user_input.lower() == "exit":
41 break
42
43 print("Assistant: ", end="", flush=True)
44 try:
45 result = Runner.run_sync(starting_agent=agent, input=user_input, session=memory)
46 print(f"{result.final_output}\n")
47 except Exception as e:
48 print(f"\n[Error]: {e}")

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

Next steps