@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 47 lines 1.16 KB
Raw
1 import { Composio } from '@composio/core';
2 import { generateText, ModelMessage, stepCountIs } from 'ai';
3 import { openai } from '@ai-sdk/openai';
4 import { VercelProvider } from '@composio/vercel';
5 import { MessageRoles } from './types';
6
7 /**
8 * Initialize the Composio SDK with the Vercel provider
9 */
10 const composio = new Composio({
11 provider: new VercelProvider(),
12 });
13
14 /**
15 * Get the hacker news tool
16 * Alternatively, you can use the `composio.getToolBySlug` method
17 */
18 async function run() {
19 const tools = await composio.tools.get('test-user-id', 'HACKERNEWS_GET_USER', {
20 beforeExecute: ({ params, toolSlug }) => {
21 console.log(`🔄 Executing ${toolSlug} with params:`, { params });
22 return params;
23 },
24 afterExecute: ({ result, toolSlug }) => {
25 console.log(`✅ Executed ${toolSlug} with result:`, { result });
26 return result;
27 },
28 });
29
30 const messages: ModelMessage[] = [
31 {
32 role: MessageRoles.USER,
33 content: 'Who is the user "pg" on hackernews?',
34 },
35 ];
36
37 const { text } = await generateText({
38 model: openai('gpt-4o-mini'),
39 tools,
40 messages,
41 stopWhen: stepCountIs(5),
42 });
43
44 console.log(text);
45 }
46
47 run();