Installation
First, install Agenite’s core packages:
npm install @agenite/agent @agenite/tool
Then install your preferred LLM provider:
npm install @agenite/bedrock
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 tool
const 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 agent
const 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 usage
const result = await agent.execute({
messages: [
{
role: 'user',
content: [{ type: 'text', text: 'What is 1234 * 5678?' }],
},
],
});
Sample output
When you run the code above, you’ll see nicely formatted output in your console thanks to the prettyLogger:
The pretty logger is handy for debugging, but you can use any logger you want and or not use it at all.
Next steps