Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
TypeScript agentic-aiagentsaiai-agentsaiagentsdeveloper-toolsfunction-callinggpt-4javascriptjsllmllmopsmcppythonremote-mcp-serverssetypescript
bunch of fixes to native tools
Sushmithamalleshb57f49ffa9ab
diff --git a/fern/pages/src/tool-router/quickstart.mdx b/fern/pages/src/tool-router/quickstart.mdxindex b3fcd38a5..952174f04 100644--- a/fern/pages/src/tool-router/quickstart.mdx+++ b/fern/pages/src/tool-router/quickstart.mdx@@ -38,8 +38,8 @@ npm install @composio/core @anthropic-ai/claude-agent-sdkWhen 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](/tool-router/manually-authenticating-users).<CodeGroup>-<SnippetCode src="fern/snippets/tool-router/python/quickstart-claude.py" title="Python" for="python" />-<SnippetCode src="fern/snippets/tool-router/typescript/quickstart-claude.ts" title="TypeScript" for="typescript" />+<SnippetCode src="fern/snippets/tool-router/python/quickstart-mcp-claude.py" title="Python" for="python" />+<SnippetCode src="fern/snippets/tool-router/typescript/quickstart-mcp-claude.ts" title="TypeScript" for="typescript" /></CodeGroup></Step></Steps>@@ -72,8 +72,8 @@ npm install @composio/core @openai/agentsWhen 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](/tool-router/manually-authenticating-users).<CodeGroup>-<SnippetCode src="fern/snippets/tool-router/python/quickstart-openai.py" title="Python" for="python" />-<SnippetCode src="fern/snippets/tool-router/typescript/quickstart-openai.ts" title="TypeScript" for="typescript" />+<SnippetCode src="fern/snippets/tool-router/python/quickstart-mcp-openai.py" title="Python" for="python" />+<SnippetCode src="fern/snippets/tool-router/typescript/quickstart-mcp-openai.ts" title="TypeScript" for="typescript" /></CodeGroup></Step>@@ -101,7 +101,7 @@ npm install @composio/core ai @ai-sdk/anthropic @ai-sdk/mcpWhen 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](/tool-router/manually-authenticating-users).-<SnippetCode src="fern/snippets/tool-router/typescript/quickstart-vercel.ts" />+<SnippetCode src="fern/snippets/tool-router/typescript/quickstart-mcp-vercel.ts" /></Step></Steps>diff --git a/fern/snippets/tool-router/python/quickstart-claude.py b/fern/snippets/tool-router/python/quickstart-mcp-claude.pysimilarity index 100%rename from fern/snippets/tool-router/python/quickstart-claude.pyrename to fern/snippets/tool-router/python/quickstart-mcp-claude.pydiff --git a/fern/snippets/tool-router/python/quickstart-openai.py b/fern/snippets/tool-router/python/quickstart-mcp-openai.pysimilarity index 100%rename from fern/snippets/tool-router/python/quickstart-openai.pyrename to fern/snippets/tool-router/python/quickstart-mcp-openai.pydiff --git a/fern/snippets/tool-router/python/quickstart-native-openai.py b/fern/snippets/tool-router/python/quickstart-native-openai.pyindex 9791eb9de..dc953a576 100644--- a/fern/snippets/tool-router/python/quickstart-native-openai.py+++ b/fern/snippets/tool-router/python/quickstart-native-openai.py@@ -7,7 +7,7 @@ from openai import OpenAI# Load environment variables from .env fileload_dotenv()-composio_api_key = os.environ["COMPOSIO_API_KEY"]+composio_api_key = os.environ.get("COMPOSIO_API_KEY")user_id = "user_123" # Your user's unique identifier# Initialize Composio and create a Tool Router session@@ -15,60 +15,58 @@ composio = Composio(api_key=composio_api_key)session = composio.create(user_id=user_id)# Initialize OpenAI client-client = OpenAI(- api_key=os.environ["OPENAI_API_KEY"]-)+client = OpenAI(api_key=os.environ.get("OPENAI_API_KEY"))# Get Tool Router as a native tooltool_router = session.get_tool_router()-# Create a chat completion with the tool-response = client.chat.completions.create(- model="gpt-4-turbo-preview",- messages=[- {- "role": "user",- "content": (- "Fetch all open issues from the composio GitHub repository "- "and create a summary of the top 5 by priority"- )- }- ],- tools=[tool_router.tool],- tool_choice="auto"-)+print("Assistant: What would you like me to do today?\n")-print("Assistant:", response.choices[0].message.content)--# Handle tool calls if the assistant wants to use Tool Router-tool_calls = response.choices[0].message.tool_calls-if tool_calls:- tool_call = tool_calls[0]+# Interactive loop+messages = []+while True:+ user_input = input("> ")+ if user_input == "exit":+ break- if tool_call.function.name == "composio_tool_router":- # Execute the tool with Tool Router- args = json.loads(tool_call.function.arguments)- result = tool_router.execute(args)-- # Send the result back to OpenAI- final_response = client.chat.completions.create(- model="gpt-4-turbo-preview",- messages=[- {- "role": "user",- "content": (- "Fetch all open issues from the composio GitHub repository "- "and create a summary of the top 5 by priority"- )- },- response.choices[0].message,- {+ # Add user message+ messages.append({"role": "user", "content": user_input})++ # Get response from OpenAI+ response = client.chat.completions.create(+ model="gpt-4-turbo-preview",+ messages=messages,+ tools=[tool_router.tool],+ tool_choice="auto"+ )++ assistant_message = response.choices[0].message+ messages.append(assistant_message)++ # Handle tool calls+ if assistant_message.tool_calls:+ for tool_call in assistant_message.tool_calls:+ if tool_call.function.name == "composio_tool_router":+ # Execute the tool+ args = json.loads(tool_call.function.arguments)+ result = tool_router.execute(args)++ # Add tool result to messages+ messages.append({"role": "tool","tool_call_id": tool_call.id,"content": json.dumps(result)- }- ],+ })++ # Get final response after tool execution+ final_response = client.chat.completions.create(+ model="gpt-4-turbo-preview",+ messages=messages,tools=[tool_router.tool])- print("Assistant:", final_response.choices[0].message.content)\ No newline at end of file+ final_message = final_response.choices[0].message+ messages.append(final_message)+ print(f"Assistant: {final_message.content}\n")+ else:+ print(f"Assistant: {assistant_message.content}\n")\ No newline at end of filediff --git a/fern/snippets/tool-router/typescript/quickstart-claude.ts b/fern/snippets/tool-router/typescript/quickstart-mcp-claude.tssimilarity index 100%rename from fern/snippets/tool-router/typescript/quickstart-claude.tsrename to fern/snippets/tool-router/typescript/quickstart-mcp-claude.tsdiff --git a/fern/snippets/tool-router/typescript/quickstart-openai.ts b/fern/snippets/tool-router/typescript/quickstart-mcp-openai.tssimilarity index 100%rename from fern/snippets/tool-router/typescript/quickstart-openai.tsrename to fern/snippets/tool-router/typescript/quickstart-mcp-openai.tsdiff --git a/fern/snippets/tool-router/typescript/quickstart-vercel.ts b/fern/snippets/tool-router/typescript/quickstart-mcp-vercel.tssimilarity index 100%rename from fern/snippets/tool-router/typescript/quickstart-vercel.tsrename to fern/snippets/tool-router/typescript/quickstart-mcp-vercel.tsdiff --git a/fern/snippets/tool-router/typescript/quickstart-native-openai.ts b/fern/snippets/tool-router/typescript/quickstart-native-openai.tsindex d8f1afc49..e74bb8130 100644--- a/fern/snippets/tool-router/typescript/quickstart-native-openai.ts+++ b/fern/snippets/tool-router/typescript/quickstart-native-openai.ts@@ -1,6 +1,7 @@import "dotenv/config"; // Load environment variables from .env fileimport { Composio } from "@composio/core";import OpenAI from "openai";+import { createInterface } from "readline/promises";const composioApiKey = process.env.COMPOSIO_API_KEY;const userId = "user_123"; // Your user's unique identifier@@ -17,51 +18,58 @@ const openai = new OpenAI({// Get Tool Router as a native toolconst toolRouter = await session.getToolRouter();-// Create a chat completion with the tool-const response = await openai.chat.completions.create({- model: "gpt-4-turbo-preview",- messages: [- {- role: "user",- content: "Fetch all open issues from the composio/composio GitHub repository " +- "and create a summary of the top 5 by priority",- },- ],- tools: [toolRouter.tool],- tool_choice: "auto",-});--console.log("Assistant:", response.choices[0].message.content);+const rl = createInterface({ input: process.stdin, output: process.stdout });+console.log("Assistant: What would you like me to do today?\n");-// Handle tool calls if the assistant wants to use Tool Router-const toolCalls = response.choices[0].message.tool_calls;-if (toolCalls && toolCalls.length > 0) {- const toolCall = toolCalls[0];+// Interactive loop+const messages: any[] = [];+while (true) {+ const userInput = await rl.question("> ");+ if (userInput === "exit") break;- if (toolCall.function.name === "composio_tool_router") {- // Execute the tool with Tool Router- const args = JSON.parse(toolCall.function.arguments);- const result = await toolRouter.execute(args);-- // Send the result back to OpenAI- const finalResponse = await openai.chat.completions.create({- model: "gpt-4-turbo-preview",- messages: [- {- role: "user",- content: "Fetch all open issues from the composio/composio GitHub repository " +- "and create a summary of the top 5 by priority",- },- response.choices[0].message,- {+ // Add user message+ messages.push({ role: "user", content: userInput });++ // Get response from OpenAI+ const response = await openai.chat.completions.create({+ model: "gpt-4-turbo-preview",+ messages: messages,+ tools: [toolRouter.tool],+ tool_choice: "auto",+ });++ const assistantMessage = response.choices[0].message;+ messages.push(assistantMessage);++ // Handle tool calls+ if (assistantMessage.tool_calls) {+ for (const toolCall of assistantMessage.tool_calls) {+ if (toolCall.function.name === "composio_tool_router") {+ // Execute the tool+ const args = JSON.parse(toolCall.function.arguments);+ const result = await toolRouter.execute(args);++ // Add tool result to messages+ messages.push({role: "tool",tool_call_id: toolCall.id,content: JSON.stringify(result),- },- ],+ });+ }+ }++ // Get final response after tool execution+ const finalResponse = await openai.chat.completions.create({+ model: "gpt-4-turbo-preview",+ messages: messages,tools: [toolRouter.tool],});- console.log("Assistant:", finalResponse.choices[0].message.content);+ const finalMessage = finalResponse.choices[0].message;+ messages.push(finalMessage);+ console.log(`Assistant: ${finalMessage.content}\n`);+ } else {+ console.log(`Assistant: ${assistantMessage.content}\n`);}-}\ No newline at end of file+}+rl.close();\ No newline at end of filediff --git a/fern/snippets/tool-router/typescript/quickstart-native-vercel.ts b/fern/snippets/tool-router/typescript/quickstart-native-vercel.tsindex 4eb3abd70..8949063dd 100644--- a/fern/snippets/tool-router/typescript/quickstart-native-vercel.ts+++ b/fern/snippets/tool-router/typescript/quickstart-native-vercel.ts@@ -2,6 +2,7 @@ import "dotenv/config"; // Load environment variables from .env fileimport { Composio } from "@composio/core";import { openai } from "@ai-sdk/openai";import { generateText } from "ai";+import { createInterface } from "readline/promises";const composioApiKey = process.env.COMPOSIO_API_KEY;const userId = "user_123"; // Your user's unique identifier@@ -13,19 +14,37 @@ const session = await composio.create(userId);// Get Tool Router as a native toolconst toolRouter = await session.getToolRouter();-// Use with Vercel AI SDK-const { text, toolCalls, toolResults } = await generateText({- model: openai("gpt-4-turbo"),- prompt: "Fetch all open issues from the composio/composio GitHub repository " +- "and create a summary of the top 5 by priority",- tools: {- composio_tool_router: toolRouter.tool,- },-});+const rl = createInterface({ input: process.stdin, output: process.stdout });+console.log("Assistant: What would you like me to do today?\n");-console.log("Result:", text);--// If there were tool calls, they've already been executed-if (toolResults && toolResults.length > 0) {- console.log("Tool was called and executed successfully");-}\ No newline at end of file+// Interactive loop with conversation history+const messages: any[] = [];+while (true) {+ const userInput = await rl.question("> ");+ if (userInput === "exit") break;++ // Add user message to history+ messages.push({ role: "user", content: userInput });++ // Generate response with Vercel AI SDK+ const { text, toolCalls, toolResults } = await generateText({+ model: openai("gpt-4-turbo"),+ messages: messages,+ tools: {+ composio_tool_router: toolRouter.tool,+ },+ });++ // Add assistant response to history+ messages.push({ role: "assistant", content: text });++ // Show tool execution feedback+ if (toolCalls && toolCalls.length > 0) {+ for (const toolCall of toolCalls) {+ console.log(`[Executed: ${toolCall.toolName}]`);+ }+ }++ console.log(`Assistant: ${text}\n`);+}+rl.close();\ No newline at end of file