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
| 1 | import { OpenAIAgentsProvider } from '@composio/openai-agents'; |
| 2 | import { Composio } from '@composio/core'; |
| 3 | import { Agent, run } from '@openai/agents'; |
| 4 | |
| 5 | const composio = new Composio({ |
| 6 | provider: new OpenAIAgentsProvider({ |
| 7 | strict: true, |
| 8 | }), |
| 9 | }); |
| 10 | |
| 11 | console.log(`🔄 Fetching tools from composio...`); |
| 12 | const tools = await composio.tools.get('default', 'HACKERNEWS_GET_USER', { |
| 13 | beforeExecute: async ({ toolSlug, toolkitSlug, params }) => { |
| 14 | console.log(`🔄 Executing tool ${toolSlug} from toolkit ${toolkitSlug}...`); |
| 15 | return params; |
| 16 | }, |
| 17 | afterExecute: async ({ toolSlug, toolkitSlug, result }) => { |
| 18 | console.log(`✅ Tool ${toolSlug} executed`); |
| 19 | return result; |
| 20 | }, |
| 21 | }); |
| 22 | |
| 23 | console.log(`✅ Tools fetched from composio`); |
| 24 | |
| 25 | const agent = new Agent({ |
| 26 | name: 'Hackernews assistant', |
| 27 | tools: tools, |
| 28 | }); |
| 29 | |
| 30 | console.log(`🔄 Running agent...`); |
| 31 | const result = await run(agent, 'Tell me about the user `pg` in hackernews'); |
| 32 | console.log(`✅ Received response from agent`); |
| 33 | if (result.finalOutput) { |
| 34 | console.log(JSON.stringify(result.finalOutput, null, 2)); |
| 35 | } |