Skip to main content

Quick Start

Get started with officeLLM by building a simple multi-agent system in just a few steps.

Prerequisites

  • Node.js 18+
  • TypeScript
  • API keys for your preferred LLM providers

1. Installation

npm install officellm zod@^4.0.0

2. Set up environment variables

Create a .env file with your API keys:
# Required - At least one provider
OPENAI_API_KEY=your_openai_key_here
ANTHROPIC_API_KEY=your_anthropic_key_here
GEMINI_API_KEY=your_gemini_key_here
OPENROUTER_API_KEY=your_openrouter_key_here

3. Create your first agents

import { OfficeLLM } from 'officellm';
import { z } from 'zod';

// Define a specialized worker agent
const mathWorker = {
  name: 'Math Solver',
  description: 'Specialized in mathematical calculations and problem solving',
  provider: {
    type: 'openai' as const,
    apiKey: process.env.OPENAI_API_KEY || '',
    model: 'gpt-4',
    temperature: 0.1, // Low temperature for precise calculations
  },
  systemPrompt: `You are a mathematical expert. Solve problems step by step and provide clear explanations.
  Always show your work and double-check calculations.`,
  tools: [
    {
      name: 'calculate',
      description: 'Perform mathematical calculations',
      parameters: z.object({
        expression: z.string().describe('The mathematical expression to evaluate'),
      }),
    },
    {
      name: 'analyze_equation',
      description: 'Analyze and solve equations',
      parameters: z.object({
        equation: z.string().describe('The equation to analyze'),
        variables: z.array(z.string()).optional().describe('Variables in the equation'),
      }),
    },
  ],
};

// Define the manager agent
const manager = {
  name: 'Project Manager',
  description: 'Coordinates and delegates tasks to specialized AI worker agents',
  provider: {
    type: 'anthropic' as const,
    apiKey: process.env.ANTHROPIC_API_KEY || '',
    model: 'claude-3-sonnet-20240229',
    temperature: 0.7,
  },
  systemPrompt: `You are a project manager coordinating a team of specialized AI agents.

Available workers:
- math_solver: For mathematical problems and calculations

When given a task, analyze it and delegate to the appropriate worker agent.
Always provide clear instructions and coordinate between workers when needed.`
};

4. Initialize and run

// Initialize the office with manager and workers
const office = new OfficeLLM({
  manager,
  workers: [mathWorker],
});

// Execute a task
async function runTask() {
  const result = await office.executeTask({
    title: 'Calculate compound interest',
    description: 'What is the compound interest on $1000 at 5% annual interest for 3 years?',
    priority: 'high',
  });

  console.log('Task Result:', result.content);
  console.log('Success:', result.success);
  console.log('Usage:', result.usage);
}

runTask().catch(console.error);

5. Expected output

Task Result: The compound interest on $1000 at 5% annual interest for 3 years would be calculated as follows:

Principal (P) = $1000
Annual interest rate (r) = 5% = 0.05
Time (t) = 3 years
Number of times interest is compounded per year (n) = 1 (assuming annual compounding)

Compound Interest = P(1 + r/n)^(nt) - P
= $1000(1 + 0.05/1)^(1*3) - $1000
= $1000(1.05)^3 - $1000
= $1000(1.157625) - $1000
= $1157.63 - $1000
= $157.63

So the compound interest would be $157.63.
Success: true
Usage: { promptTokens: 150, completionTokens: 200, totalTokens: 350 }

Next Steps

Common Issues

“Provider type not registered”
  • Use supported types: 'openai' | 'anthropic' | 'gemini' | 'openrouter'
  • Check API key is set
“Task execution failed”
  • Verify API keys are valid
  • Check the model name is correct
  • Review system prompts
TypeScript errors
  • Use as const for provider types: type: 'openai' as const