Use Cases
/

Multi-Agent Orchestration

Multi-Agent Orchestration

Compose multiple specialised agents that hand off tasks, share context, and collaborate on complex workflows.

Agent SDK
Agent Server

Overview

Complex tasks often benefit from multiple specialised agents working together. Cognipeer's Agent SDK supports multi-agent patterns where agents can delegate, hand off, and collaborate — all while maintaining deterministic control and full tracing.

This guide builds a content pipeline with Researcher, Writer, and Reviewer agents.

Architecture

Agent SDK handles each agent's runtime independently with its own tools, system prompt, and constraints. Agents communicate through the serving layer.

Agent Server registers all agents, manages their conversations, and provides the API surface for orchestration.

1. Create Specialised Agents

Define each agent with its own tools and expertise.

import { createSmartAgent, createTool } from "@cognipeer/agent-sdk";
import { z } from "zod";

// Researcher agent — gathers information
const researcher = createSmartAgent({
  name: "Researcher",
  model,
  tools: [searchWeb, extractData],
  systemPrompt: "You are a research specialist. Gather comprehensive information on the given topic. Output structured findings.",
  useTodoList: true,
  limits: { maxToolCalls: 8 },
  tracing: { enabled: true },
});

// Writer agent — creates content
const writer = createSmartAgent({
  name: "Writer",
  model,
  tools: [formatMarkdown, generateOutline],
  systemPrompt: "You are a technical writer. Take research findings and produce well-structured, clear content.",
  limits: { maxToolCalls: 5 },
  tracing: { enabled: true },
});

// Reviewer agent — quality check
const reviewer = createSmartAgent({
  name: "Reviewer",
  model,
  tools: [checkFacts, scoringTool],
  systemPrompt: "You are a content reviewer. Check accuracy, clarity, and completeness. Provide actionable feedback.",
  limits: { maxToolCalls: 5 },
  tracing: { enabled: true },
});

2. Register All Agents

Expose each agent through Agent Server, each with its own endpoint.

import {
  createAgentServer,
  createPostgresProvider,
} from "@cognipeer/agent-server";

const server = createAgentServer({
  basePath: "/api/agents",
  storage: createPostgresProvider({
    connectionString: process.env.DATABASE_URL!,
  }),
  swagger: { enabled: true, path: "/docs" },
});

server.registerSDKAgent("researcher", researcher, {
  description: "Gathers and structures research data",
});

server.registerSDKAgent("writer", writer, {
  description: "Produces written content from research",
});

server.registerSDKAgent("reviewer", reviewer, {
  description: "Reviews content for quality",
});

3. Orchestrate the Pipeline

Create an orchestrator that drives the pipeline: research → write → review.

async function contentPipeline(topic: string) {
  // Step 1: Research
  const researchResult = await researcher.invoke({
    messages: [{ role: "user", content: `Research: ${topic}` }],
    toolHistory: [],
  });
  const findings = researchResult.messages.at(-1)?.content;

  // Step 2: Write
  const writeResult = await writer.invoke({
    messages: [
      { role: "user", content: `Write an article based on:\n${findings}` },
    ],
    toolHistory: [],
  });
  const draft = writeResult.messages.at(-1)?.content;

  // Step 3: Review
  const reviewResult = await reviewer.invoke({
    messages: [
      { role: "user", content: `Review this article:\n${draft}` },
    ],
    toolHistory: [],
  });

  return {
    research: findings,
    article: draft,
    review: reviewResult.messages.at(-1)?.content,
  };
}

const result = await contentPipeline("AI agent architectures in 2025");

Result

You now have a multi-agent content pipeline that:

- Specialises each agent for its task (research, writing, review) - Orchestrates agents in a defined pipeline sequence - Traces every agent's execution independently - Serves each agent as its own REST endpoint - Persists all conversations and outputs in the database - Scales — add more agents to the pipeline as needed