Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
using snippet fixes
Sushmithamallesh committed
Dec 16, 2025 at 00:57 UTC
2b267d9fa945a1e38f6f0c4a75b380a55c3fda0e
3 files changed
+89
-16
fern/snippets/tool-router/python/native-tools-openai.py
+26
-5
@@ -1,7 +1,7 @@
1
import os
2
from dotenv import load_dotenv
3
from composio import Composio
4
-from agents import Agent, Runner
4
+from agents import Agent, Runner, SQLiteSession
5
from composio_openai_agents import OpenAIAgentsProvider
6
7
# Load environment variables from .env file
@@ -16,15 +16,36 @@ tools = session.tools()
16
# Create OpenAI agent with Composio tools
17
agent = 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.",
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
-# Run the agent with a specific task
24
+# Create session for multi-turn conversation
25
+conversation_session = SQLiteSession("conversation_example")
26
+
27
+# Execute an initial task that requires GitHub access
28
+print("Executing initial task: Fetching GitHub issues...\n")
29
result = Runner.run_sync(
30
starting_agent=agent,
27
- input="Fetch all open issues from the composio/composio GitHub repository and create a summary of the top 5 by priority"
31
+ input="Fetch all the open GitHub issues on the composio repository and group them by bugs/features/docs.",
32
+ session=conversation_session,
33
)
34
+print(f"Result: {result.final_output}\n")
35
+
36
+# Continue with interactive conversation
37
+print("Assistant: What else would you like me to do? Type 'exit' to end the conversation.\n")
38
30
-print(f"Assistant: {result.final_output}")
\ No newline at end of file
39
+while 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")
\ No newline at end of file
fern/snippets/tool-router/typescript/native-tools-openai.ts
+27
-6
@@ -1,7 +1,8 @@
1
import "dotenv/config"; // Load environment variables from .env file
2
import { Composio } from "@composio/core";
3
-import { Agent, run } from "@openai/agents";
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
@@ -15,15 +16,35 @@ const tools = await session.tools();
16
// Create OpenAI agent with Composio tools
17
const agent = new Agent({
18
name: "AI Assistant",
18
- instructions: "You are a helpful assistant with access to external tools. Use the available tools to complete user requests.",
19
+ instructions:
20
+ "You are a helpful assistant with access to external tools. " +
21
+ "Always use the available tools to complete user requests instead of just explaining how to do them.",
22
model: "gpt-5.2",
23
tools: tools,
24
});
25
23
-// Run the agent with a specific task
24
-const result = await run(
26
+// Create session for multi-turn conversation
27
+const conversationSession = new MemorySession();
28
+
29
+// Execute an initial task that requires GitHub access
30
+console.log("Executing initial task: Fetching GitHub issues...\n");
31
+const initialResult = await run(
32
agent,
26
- "Fetch all open issues from the composio/composio GitHub repository and create a summary of the top 5 by priority"
33
+ "Fetch all the open GitHub issues on the composio repository and group them by bugs/features/docs.",
34
+ { session: conversationSession }
35
);
36
+console.log(`Result: ${initialResult.finalOutput}\n`);
37
+
38
+// Continue with interactive conversation
39
+const rl = createInterface({ input: process.stdin, output: process.stdout });
40
+console.log("Assistant: What else would you like me to do? Type 'exit' to end the conversation.\n");
41
29
-console.log(`Assistant: ${result.finalOutput}`);
\ No newline at end of file
42
+while (true) {
43
+ const userInput = await rl.question("> ");
44
+ if (userInput.toLowerCase() === "exit") break;
45
+
46
+ // Run agent with session to maintain context
47
+ const result = await run(agent, userInput, { session: conversationSession });
48
+ console.log(`Assistant: ${result.finalOutput}\n`);
49
+}
50
+rl.close();
\ No newline at end of file
fern/snippets/tool-router/typescript/native-tools-vercel.ts
+36
-5
@@ -1,8 +1,9 @@
1
-import "dotenv/config"; // Load environment variables from .env file
1
+import "dotenv/config";
2
import { Composio } from "@composio/core";
3
import { VercelProvider } from "@composio/vercel";
4
import { openai } from "@ai-sdk/openai";
5
import { generateText } from "ai";
6
+import { createInterface } from "readline/promises";
7
8
const composio = new Composio({
9
apiKey: process.env.COMPOSIO_API_KEY,
@@ -14,11 +15,41 @@ const session = await composio.create("user_123");
15
// Get native tools from Composio
16
const tools = await session.tools();
17
17
-// Use with Vercel AI SDK
18
-const result = await generateText({
18
+const messages: any[] = [];
19
+
20
+// Execute an initial task that requires GitHub access
21
+console.log("Executing initial task: Fetching GitHub issues...\n");
22
+const initialResult = await generateText({
23
model: openai("gpt-4-turbo"),
20
- prompt: "Fetch all open issues from the composio/composio GitHub repository and create a summary of the top 5 by priority",
24
+ prompt: "Fetch all the open GitHub issues on the composio repository and group them by bugs/features/docs.",
25
tools: tools,
26
});
27
+console.log(`Result: ${initialResult.text}\n`);
28
+
29
+// Add initial conversation to history
30
+messages.push(
31
+ { role: "user", content: "Fetch all the open GitHub issues on the composio repository and group them by bugs/features/docs." },
32
+ { role: "assistant", content: initialResult.text }
33
+);
34
+
35
+// Continue with interactive conversation
36
+const rl = createInterface({ input: process.stdin, output: process.stdout });
37
+console.log("Assistant: What else would you like me to do? Type 'exit' to end the conversation.\n");
38
+
39
+while (true) {
40
+ const userInput = await rl.question("> ");
41
+ if (userInput.toLowerCase() === "exit") break;
42
+
43
+ messages.push({ role: "user", content: userInput });
44
+
45
+ const result = await generateText({
46
+ model: openai("gpt-4-turbo"),
47
+ messages: messages,
48
+ tools: tools,
49
+ });
50
+
51
+ messages.push({ role: "assistant", content: result.text });
52
+ console.log(`Assistant: ${result.text}\n`);
53
+}
54
24
-console.log(`Assistant: ${result.text}`);
\ No newline at end of file
55
+rl.close();
\ No newline at end of file