@destroyerdarkness/easy-agent
v0.1.9
Published
A simplified AI agent library based on Crush
Readme
EasyAgent
A simplified TypeScript library for building AI agents, inspired by Crush.
Features
- Easy to use: Define tools with Zod schemas and functions.
- Autonomous: The agent plans and executes tasks using the provided tools.
- Context Management: Automatically summarizes conversation history when it gets too long.
- Flexible Provider: Comes with an OpenAI provider, but you can implement your own.
Installation
npm install easy-agentUsage
import { z } from 'zod';
import { EasyAgent, createFunction, OpenAIProvider } from 'easy-agent';
// 1. Define tools
const mathTool = {
name: 'math',
functions: [
createFunction(
'add',
'Add numbers',
z.object({ numbers: z.array(z.number()) }),
async ({ numbers }) => numbers.reduce((a, b) => a + b, 0)
)
]
};
// 2. Initialize provider
const provider = new OpenAIProvider('your-api-key');
// 3. Create agent
const agent = new EasyAgent({
tools: [mathTool],
provider: provider
});
// 4. Run agent
const response = await agent.run("What is 2 + 2?");
console.log(response);Architecture
- Agent: The core class that manages the conversation loop and tool execution.
- Provider: Abstraction for LLM providers.
- Tools: Helper to create strongly-typed tools.
- Pruning: The agent automatically summarizes the conversation history when it exceeds
maxHistoryMessages.
