@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 50 lines 1.71 KB
Raw
1 import { openai } from '@ai-sdk/openai';
2 import { ToolLoopAgent } from 'ai';
3 import { Composio } from '@composio/core';
4 import { VercelProvider } from '@composio/vercel';
5
6 /**
7 * This example demonstrates the new ToolLoopAgent class introduced in AI SDK v6,
8 * which provides a production-ready implementation that handles the complete
9 * tool execution loop automatically.
10 *
11 * See: https://vercel.com/blog/ai-sdk-6#toolloopagent.
12 */
13
14 // 1. Initialize Composio with the Vercel provider
15 const composio = new Composio({
16 provider: new VercelProvider(),
17 });
18
19 // 2. Get Composio tools for the agent
20 console.log('🔄 Fetching Composio tools...');
21 const tools = await composio.tools.get('test-user-id', 'HACKERNEWS_GET_USER', {
22 beforeExecute: ({ params, toolSlug }) => {
23 console.log(`🔧 Executing ${toolSlug}...`);
24 return params;
25 },
26 afterExecute: ({ result, toolSlug }) => {
27 console.log(`✅ ${toolSlug} completed`);
28 return result;
29 },
30 });
31 console.log(`✅ Tools loaded: ${Object.keys(tools).join(', ')}`);
32
33 // 3. Create a ToolLoopAgent with Composio tools
34 const hackerNewsAgent = new ToolLoopAgent({
35 model: openai('gpt-4o-mini'),
36 instructions: `You are a helpful assistant that can look up information about Hacker News users.
37 When asked about a user, use the available tools to fetch their profile information.
38 Provide a concise summary of the user's profile including their karma, about section, and any other relevant details.`,
39 tools,
40 });
41
42 // 4. Run the agent
43 console.log('🤖 Running agent...\n');
44 const result = await hackerNewsAgent.generate({
45 prompt: 'Who is the user "pg" on Hacker News? Tell me about their profile.',
46 });
47
48 // 5. Display the result
49 console.log('📝 Agent Response:');
50 console.log(result.text);