Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
Mirrored from https://github.com/Camo67/composio.git
Synced Nov 22, 17:00 UTC
quickstart updates
Sushmithamallesh committed
Dec 16, 2025 at 00:10 UTC
6a10c68d5e3d324f7cf41eb870740eae41a9728f
3 files changed
+44
-113
fern/pages/src/tool-router/quickstart.mdx
+2
-2
@@ -127,10 +127,10 @@ When you run this agent, Tool Router:
127
<Step title="Install">
128
<CodeGroup>
129
```bash title="Python" for="python"
130
-pip install composio openai
130
+pip install composio composio-openai-agents openai-agents
131
```
132
```bash title="TypeScript" for="typescript"
133
-npm install @composio/core openai
133
+npm install @composio/core @composio/openai-agents @openai/agents
134
```
135
</CodeGroup>
136
</Step>
fern/snippets/tool-router/python/quickstart-native-openai.py
+23
-55
@@ -1,72 +1,40 @@
1
import os
2
-import json
2
from dotenv import load_dotenv
3
from composio import Composio
5
-from openai import OpenAI
4
+from agents import Agent, Runner, SQLiteSession
5
+from composio_openai_agents import OpenAIAgentsProvider
6
7
-# Load environment variables from .env file
7
load_dotenv()
8
10
-composio_api_key = os.environ.get("COMPOSIO_API_KEY")
11
-user_id = "user_123" # Your user's unique identifier
9
+composio = Composio(api_key=os.environ.get("COMPOSIO_API_KEY"), provider=OpenAIAgentsProvider())
10
+session = composio.create(user_id="user_123")
11
13
-# Initialize Composio and create a Tool Router session
14
-composio = Composio(api_key=composio_api_key)
15
-session = composio.create(user_id=user_id)
12
+# Get native tools from Composio
13
+tools = session.tools()
14
17
-# Initialize OpenAI client
18
-client = OpenAI(api_key=os.environ.get("OPENAI_API_KEY"))
15
+# Create OpenAI agent with Composio tools
16
+agent = 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
20
-# Get Tool Router as a native tool
21
-tool_router = session.get_tool_router()
23
+# Create session for multi-turn conversation
24
+conversation_session = SQLiteSession("conversation_example")
25
23
-print("Assistant: What would you like me to do today?\n")
26
+print("Assistant: What would you like me to do today? Type 'exit' to end the conversation.\n")
27
25
-# Interactive loop
26
-messages = []
28
while True:
29
user_input = input("> ")
29
- if user_input == "exit":
30
+ if user_input.lower() == "exit":
31
break
32
32
- # Add user message
33
- messages.append({"role": "user", "content": user_input})
34
-
35
- # Get response from OpenAI
36
- response = client.chat.completions.create(
37
- model="gpt-4-turbo-preview",
38
- messages=messages,
39
- tools=[tool_router.tool],
40
- tool_choice="auto"
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
43
- assistant_message = response.choices[0].message
44
- messages.append(assistant_message)
45
-
46
- # Handle tool calls
47
- if assistant_message.tool_calls:
48
- for tool_call in assistant_message.tool_calls:
49
- if tool_call.function.name == "composio_tool_router":
50
- # Execute the tool
51
- args = json.loads(tool_call.function.arguments)
52
- result = tool_router.execute(args)
53
-
54
- # Add tool result to messages
55
- messages.append({
56
- "role": "tool",
57
- "tool_call_id": tool_call.id,
58
- "content": json.dumps(result)
59
- })
60
-
61
- # Get final response after tool execution
62
- final_response = client.chat.completions.create(
63
- model="gpt-4-turbo-preview",
64
- messages=messages,
65
- tools=[tool_router.tool]
66
- )
67
-
68
- final_message = final_response.choices[0].message
69
- messages.append(final_message)
70
- print(f"Assistant: {final_message.content}\n")
71
- else:
72
- print(f"Assistant: {assistant_message.content}\n")
\ No newline at end of file
40
+ print(f"Assistant: {result.final_output}\n")
\ No newline at end of file
fern/snippets/tool-router/typescript/quickstart-native-openai.ts
+19
-56
@@ -1,75 +1,38 @@
1
import "dotenv/config"; // Load environment variables from .env file
2
import { Composio } from "@composio/core";
3
-import OpenAI from "openai";
3
+import { Agent, run, MemorySession } from "@openai/agents";
4
+import { OpenAIAgentsProvider } from "@composio/openai-agents";
5
import { createInterface } from "readline/promises";
6
7
const composioApiKey = process.env.COMPOSIO_API_KEY;
8
const userId = "user_123"; // Your user's unique identifier
9
9
-// Initialize Composio and create a Tool Router session
10
-const composio = new Composio({ apiKey: composioApiKey });
10
+const composio = new Composio({ apiKey: composioApiKey, provider: new OpenAIAgentsProvider() });
11
const session = await composio.create(userId);
12
13
-// Initialize OpenAI client
14
-const openai = new OpenAI({
15
- apiKey: process.env.OPENAI_API_KEY,
13
+// Get native tools from Composio
14
+const tools = await session.tools();
15
+
16
+// Create OpenAI agent with Composio tools
17
+const agent = new Agent({
18
+ name: "AI Assistant",
19
+ instructions: "You are a helpful assistant with access to external tools. Use the available tools to complete user requests.",
20
+ model: "gpt-5.2",
21
+ tools: tools,
22
});
23
18
-// Get Tool Router as a native tool
19
-const toolRouter = await session.getToolRouter();
24
+// Create session for multi-turn conversation
25
+const conversationSession = new MemorySession();
26
27
const rl = createInterface({ input: process.stdin, output: process.stdout });
22
-console.log("Assistant: What would you like me to do today?\n");
28
+console.log("Assistant: What would you like me to do today? Type 'exit' to end the conversation.\n");
29
24
-// Interactive loop
25
-const messages: any[] = [];
30
while (true) {
31
const userInput = await rl.question("> ");
28
- if (userInput === "exit") break;
29
-
30
- // Add user message
31
- messages.push({ role: "user", content: userInput });
32
-
33
- // Get response from OpenAI
34
- const response = await openai.chat.completions.create({
35
- model: "gpt-4-turbo-preview",
36
- messages: messages,
37
- tools: [toolRouter.tool],
38
- tool_choice: "auto",
39
- });
40
-
41
- const assistantMessage = response.choices[0].message;
42
- messages.push(assistantMessage);
32
+ if (userInput.toLowerCase() === "exit") break;
33
44
- // Handle tool calls
45
- if (assistantMessage.tool_calls) {
46
- for (const toolCall of assistantMessage.tool_calls) {
47
- if (toolCall.function.name === "composio_tool_router") {
48
- // Execute the tool
49
- const args = JSON.parse(toolCall.function.arguments);
50
- const result = await toolRouter.execute(args);
51
-
52
- // Add tool result to messages
53
- messages.push({
54
- role: "tool",
55
- tool_call_id: toolCall.id,
56
- content: JSON.stringify(result),
57
- });
58
- }
59
- }
60
-
61
- // Get final response after tool execution
62
- const finalResponse = await openai.chat.completions.create({
63
- model: "gpt-4-turbo-preview",
64
- messages: messages,
65
- tools: [toolRouter.tool],
66
- });
67
-
68
- const finalMessage = finalResponse.choices[0].message;
69
- messages.push(finalMessage);
70
- console.log(`Assistant: ${finalMessage.content}\n`);
71
- } else {
72
- console.log(`Assistant: ${assistantMessage.content}\n`);
73
- }
34
+ // Run agent with session to maintain context
35
+ const result = await run(agent, userInput, { session: conversationSession });
36
+ console.log(`Assistant: ${result.finalOutput}\n`);
37
}
38
rl.close();
\ No newline at end of file