Tools are the building blocks that give your agent abilities to perform tasks. While we’ll start with a simple calculator example below, you can build much more meaningful tools like:
Database query tools for data analysis
API integration tools for external services
File system tools for document processing
Custom business logic tools for your domain
Let’s start with a basic example:
import { Agent } from '@agenite/agent';import { Tool } from '@agenite/tool';import { BedrockProvider } from '@agenite/bedrock';import { prettyLogger } from '@agenite/pretty-logger';// Create a calculator toolconst calculatorTool = new Tool<{ expression: string }>({ name: 'calculator', description: 'Perform basic math operations', inputSchema: { type: 'object', properties: { expression: { type: 'string' }, }, required: ['expression'], }, execute: async ({ input }) => { try { const result = new Function('return ' + input.expression)(); return { isError: false, data: result.toString() }; } catch (error) { if (error instanceof Error) { return { isError: true, data: error.message }; } return { isError: true, data: 'Unknown error' }; } },});// Create an agentconst agent = new Agent({ name: 'math-buddy', provider: new BedrockProvider({ model: 'anthropic.claude-3-5-sonnet-20240620-v1:0', }), tools: [calculatorTool], instructions: 'You are a helpful math assistant.', middlewares: [prettyLogger()],});// Example usageconst result = await agent.execute({ messages: [ { role: 'user', content: [{ type: 'text', text: 'What is 1234 * 5678?' }], }, ],});