@devries-cameron20 / composio Mirror · read-only
Fork 0

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 21, 04:45 UTC

next
ts 49 lines 1.17 KB
Raw
1 import { Composio } from '@composio/core';
2 import { MultiServerMCPClient } from '@langchain/mcp-adapters';
3 import { ChatOpenAI } from '@langchain/openai';
4 import { createAgent } from 'langchain';
5
6 const composio = new Composio({
7 apiKey: process.env.COMPOSIO_API_KEY,
8 });
9
10 const llm = new ChatOpenAI({
11 model: 'gpt-4o',
12 });
13
14 async function main() {
15 const userId = process.env.COMPOSIO_EXAMPLES_USER_ID; // a user with a connected Gmail account
16 if (!userId) {
17 throw new Error('Set COMPOSIO_EXAMPLES_USER_ID');
18 }
19
20 const session = await composio.create(userId, { toolkits: ['gmail'], mcp: true });
21
22 const client = new MultiServerMCPClient({
23 servers: {
24 composio: {
25 transport: 'http',
26 url: session.mcp.url,
27 headers: session.mcp.headers,
28 },
29 },
30 prefixToolNameWithServerName: false,
31 });
32
33 const tools = await client.getTools();
34
35 const agent = createAgent({
36 name: 'gmail-assistant',
37 systemPrompt: 'You are a helpful gmail assistant.',
38 model: llm,
39 tools,
40 });
41
42 const result = await agent.invoke({
43 messages: [{ role: 'user', content: 'Fetch my last email from gmail' }],
44 });
45
46 console.log(result);
47 }
48
49 main();