import { OfficeLLM } from 'officellm';
import { z } from 'zod';
// Define a worker agent
const mathWorker = {
name: 'Math Solver',
description: 'Specialized in mathematical calculations',
provider: {
type: 'openai' as const,
apiKey: process.env.OPENAI_API_KEY!,
model: 'gpt-4',
temperature: 0.1,
},
systemPrompt: 'You are a mathematical expert. Solve problems step by step.',
tools: [
{
name: 'calculate',
description: 'Perform mathematical calculations',
parameters: z.object({
expression: z.string().describe('Math expression to evaluate'),
}),
},
],
};
// Manager configuration
const manager = {
name: 'Project Manager',
description: 'Coordinates AI worker agents',
provider: {
type: 'anthropic' as const,
apiKey: process.env.ANTHROPIC_API_KEY!,
model: 'claude-3-sonnet-20240229',
temperature: 0.7,
},
systemPrompt: 'You coordinate specialized AI agents to complete tasks.',
tools: [
{
name: 'math_solver',
description: 'Delegate math tasks to the math expert',
parameters: z.object({
task: z.string().describe('Math task to solve'),
priority: z.enum(['low', 'medium', 'high']).default('medium'),
}),
},
],
};
// Initialize and use
const office = new OfficeLLM({
manager,
workers: [mathWorker],
});
const result = await office.executeTask({
title: 'Calculate compound interest',
description: 'What is the compound interest on $1000 at 5% for 3 years?',
priority: 'high',
});
console.log('Result:', result.content);