AgentForge

Example: Multi-Agent Pipeline

Build a research → write → review pipeline with the Coordinator.

Overview

Three agents work sequentially: a researcher gathers information, a writer creates content, and a reviewer provides feedback.

Implementation

import {
  defineAgent, defineTool, createLLM, pipeline,
} from '@ahzan-agentforge/core';
import { z } from 'zod';

const llm = createLLM({ provider: 'anthropic', model: 'claude-sonnet-4-20250514' });

const researcher = defineAgent({
  name: 'researcher',
  description: 'Researches topics thoroughly',
  tools: [searchTool],
  llm,
  systemPrompt: 'Research the given topic. Provide detailed findings with sources.',
  maxSteps: 10,
});

const writer = defineAgent({
  name: 'writer',
  description: 'Writes polished content from research',
  tools: [],
  llm,
  systemPrompt: 'Write clear, engaging content based on the research provided.',
  maxSteps: 5,
});

const reviewer = defineAgent({
  name: 'reviewer',
  description: 'Reviews content for accuracy and quality',
  tools: [],
  llm,
  systemPrompt: 'Review the content for accuracy, clarity, and completeness. Provide specific feedback.',
  maxSteps: 5,
});

// Sequential pipeline
const result = await pipeline(
  [researcher, writer, reviewer],
  { task: 'Create a comprehensive guide to AI agent frameworks' },
);

console.log(result.status);       // 'completed'
console.log(result.output);       // Reviewer's feedback on the article
console.log(result.handoffs);     // Record of each handoff

With Coordinator (Custom Trust)

import { Coordinator, InMemoryWorkspaceStore } from '@ahzan-agentforge/core';

const coordinator = new Coordinator({
  agents: { researcher, writer, reviewer },
  workspace: new InMemoryWorkspaceStore(),
  trustModel: {
    allowedHandoffs: {
      researcher: ['writer'],
      writer: ['reviewer'],
      reviewer: ['writer'],  // Can send back for revisions
    },
    requireExplicitRoutes: true,
  },
  budget: {
    maxTotalCostUsd: 2.00,
    maxCostPerAgent: 1.00,
  },
});

const result = await coordinator.run('researcher', {
  task: 'Research and write about quantum computing applications',
});

Next Steps