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, 18:15 UTC
feat(ts): update tool-router openai-agents example
jkomyno committed
Dec 10, 2025 at 11:34 UTC
379c1bd9cb1ebccb4e4627498522fb99eed5a7cb
1 file changed
+15
-30
ts/examples/tool-router/src/openai-agents.ts
+15
-30
@@ -1,37 +1,22 @@
1
-import { Agent, run, hostedMcpTool } from '@openai/agents';
2
-import { Composio } from '@composio/core';
3
-
4
-const composio = new Composio();
5
-
6
-const session = await composio.experimental.create('user_123', { toolkits: ['gmail'] });
7
-
8
-console.log(`Tool Router Session Created: ${session.sessionId}`);
9
-console.log(`Connecting to MCP server: ${session.mcp.url}`);
10
-
11
-const mcpTool = hostedMcpTool({
12
- serverLabel: 'ComposioApps',
13
- serverUrl: session.mcp.url,
14
- headers: {
15
- 'x-api-key': process.env.COMPOSIO_API_KEY!,
16
- }
17
-});
1
+import { Composio } from "@composio/core";
2
+import { Agent, run, hostedMcpTool } from "@openai/agents";
3
+import { createInterface } from "node:readline/promises";
4
5
+const { mcp } = await new Composio().toolRouter.create("default");
6
7
const agent = new Agent({
21
- name: 'Gmail Assistant',
22
- instructions: 'You are a helpful gmail assistant.',
23
- tools: [mcpTool],
24
-});
25
-
26
-const result = await run(agent, 'Summarize my last email from gmail', {
27
- stream: true,
8
+ name: "Personal Assistant",
9
+ model: "gpt-5.1",
10
+ instructions: "You are a helpful personal assistant. Use Composio tools to execute tasks.",
11
+ tools: [hostedMcpTool({ serverLabel: "composio", serverUrl: mcp.url, headers: { "x-api-key": process.env.COMPOSIO_API_KEY! } })],
12
});
13
14
+const rl = createInterface({ input: process.stdin, output: process.stdout });
15
31
-const stream = result.toStream();
16
+for (let input: any = await rl.question("You: "); input !== "exit"; ) {
17
+ const result = await run(agent, input);
18
+ console.log(`Agent: ${result.finalOutput}\n`);
19
+ input = [...result.history, { role: "user" as const, content: await rl.question("You: ") }];
20
+}
21
33
-for await (const event of stream) {
34
- if (event.type === 'raw_model_stream_event' && event.data.delta) {
35
- process.stdout.write(event.data.delta);
36
- }
37
-}
\ No newline at end of file
22
+rl.close();