Quickstart

Choose how you want to integrate Tool Router:

1

Install

$pip install composio claude-agent-sdk
2

Create session and run agent

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

  • 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.
  • 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
2import os
3from dotenv import load_dotenv
4from claude_agent_sdk.client import ClaudeSDKClient
5from claude_agent_sdk.types import (
6 ClaudeAgentOptions,
7 ResultMessage,
8 AssistantMessage,
9 TextBlock,
10 ToolUseBlock
11)
12from composio import Composio
13
14# Load environment variables from .env file
15load_dotenv()
16
17# Initialize Composio and create a Tool Router session
18composio = Composio(api_key=os.environ["COMPOSIO_API_KEY"])
19user_id = "user_123" # Your user's unique identifier
20session = composio.create(user_id=user_id)
21
22# Configure Claude with Composio MCP server
23options = ClaudeAgentOptions(
24 system_prompt=(
25 "You are a helpful assistant with access to external tools. "
26 "Always use the available tools to complete user requests instead of just explaining how to do them."
27 ),
28 mcp_servers={
29 "composio": {
30 "type": "http",
31 "url": session.mcp.url,
32 "headers": {"x-api-key": os.environ["COMPOSIO_API_KEY"]},
33 }
34 },
35 permission_mode="bypassPermissions",
36)
37
38
39async def main():
40 async with ClaudeSDKClient(options) as client:
41 while True:
42 user_input = input("You: ").strip()
43 if user_input.lower() in ("quit", "exit"):
44 break
45
46 await client.query(user_input)
47 async for msg in client.receive_response():
48 if isinstance(msg, AssistantMessage):
49 for block in msg.content:
50 if isinstance(block, ToolUseBlock):
51 print(f"[Using tool: {block.name}]")
52 elif isinstance(block, TextBlock):
53 print(block.text, end="")
54 elif isinstance(msg, ResultMessage) and msg.result:
55 print(f"\n{msg.result}\n")
56
57
58if __name__ == "__main__":
59 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 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 your COMPOSIO_API_KEY environment variable with your API key from Settings.
  • Set your OPENAI_API_KEY environment variable with your OpenAI API key.
  • userId is your user’s unique identifier. See User Management for details.
1import os
2from dotenv import load_dotenv
3from composio import Composio
4from agents import Agent, Runner, SQLiteSession
5from composio_openai_agents import OpenAIAgentsProvider
6
7load_dotenv()
8
9composio = Composio(api_key=os.environ.get("COMPOSIO_API_KEY"), provider=OpenAIAgentsProvider())
10session = composio.create(user_id="user_123")
11
12# Get native tools from Composio
13tools = session.tools()
14
15# Create OpenAI agent with Composio tools
16agent = Agent(
17 name="AI Assistant",
18 instructions="You are a helpful assistant with access to external tools. Use the available tools to complete user requests.",
19 model="gpt-5.2",
20 tools=tools,
21)
22
23# Create session for multi-turn conversation
24conversation_session = SQLiteSession("conversation_example")
25
26print("Assistant: What would you like me to do today? Type 'exit' to end the conversation.\n")
27
28while True:
29 user_input = input("> ")
30 if user_input.lower() == "exit":
31 break
32
33 # Run agent with session to maintain context
34 result = Runner.run_sync(
35 starting_agent=agent,
36 input=user_input,
37 session=conversation_session,
38 )
39
40 print(f"Assistant: {result.final_output}\n")

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