import { OfficeLLM } from 'officellm';
Constructor
new OfficeLLM(config: OfficeLLMConfig)
Creates a new officeLLM instance with manager and worker agents.
Configuration object containing manager and workers
Example
const office = new OfficeLLM({
manager: managerConfig,
workers: [workerConfig1, workerConfig2],
});
Methods
executeTask
executeTask(task: Task): Promise<TaskResult>
Execute a task through the manager agent.
Task object with title, description, and priority
Returns: Promise resolving to task result
callWorker
callWorker(workerName: string, params: Record<string, any>): Promise<TaskResult>
Call a specific worker agent directly.
Name of the worker agent to call
Parameters to pass to the worker
Returns: Promise resolving to task result
getWorkers
Get list of available worker agent names.
Returns: Array of worker names
getManager
getManager(): { name: string; description?: string }
Get manager agent information.
Returns: Object with manager name and description
Types
OfficeLLMConfig
interface OfficeLLMConfig {
manager: ManagerConfig;
workers: WorkerConfig[];
}
ManagerConfig
interface ManagerConfig {
name: string;
description?: string;
provider: ProviderConfig;
systemPrompt: string;
tools: ToolDefinition[];
}
WorkerConfig
interface WorkerConfig {
name: string;
description?: string;
provider: ProviderConfig;
systemPrompt: string;
tools: ToolDefinition[];
}
Task
interface Task {
title: string;
description: string;
priority?: 'low' | 'medium' | 'high';
[key: string]: any; // Additional parameters
}
TaskResult
interface TaskResult {
success: boolean;
content: string;
toolCalls?: ToolCall[];
usage?: {
promptTokens: number;
completionTokens: number;
totalTokens: number;
};
error?: string;
}
Usage Examples
Basic Task Execution
const office = new OfficeLLM({
manager: {
name: 'Project Manager',
provider: { type: 'openai', apiKey: '...', model: 'gpt-4' },
systemPrompt: 'You coordinate AI agents...',
tools: [
{
name: 'math_solver',
description: 'Solve math problems',
parameters: z.object({
task: z.string(),
}),
},
],
},
workers: [
{
name: 'Math Solver',
provider: { type: 'anthropic', apiKey: '...', model: 'claude-3-sonnet' },
systemPrompt: 'You are a math expert...',
tools: [
{
name: 'calculate',
description: 'Calculate expressions',
parameters: z.object({
expression: z.string(),
}),
},
],
},
],
});
// Execute task
const result = await office.executeTask({
title: 'Calculate area',
description: 'What is the area of a circle with radius 5?',
priority: 'medium',
});
console.log(result.content); // "The area is approximately 78.54 square units..."
Direct Worker Call
// Call worker directly
const workerResult = await office.callWorker('Math Solver', {
task: 'Solve for x: 2x + 3 = 7',
});
console.log(workerResult.content);
Getting Available Workers
const workers = office.getWorkers();
console.log(workers); // ['Math Solver', 'Research Assistant', ...]
const manager = office.getManager();
console.log(manager.name); // 'Project Manager'