A simplified AI agent library based on Crush
npm install @destroyerdarkness/easy-agentbash
npm install easy-agent
`
Usage
`typescript
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`.