AgentSea

Concept

Workflows

Workflows coordinate multiple agents to solve a task together, through sequential, parallel or supervisor patterns.

01What are workflows?

A workflow runs a list of agents over one input. AgentSea has three patterns:

sequential
Agents run one after another. Each agent's output becomes the next agent's input.
parallel
All agents run at the same time on the same input. Their results are combined.
supervisor
Agents run in a routed loop. Each response decides which agent runs next.

02Sequential workflows

The result is the last agent's response. Token counts and iterations are summed across all agents.

TS
import {
  WorkflowFactory,
  AnthropicProvider,
  ToolRegistry,
  httpRequestTool,
} from '@lov3kaizen/agentsea-core';

const provider = new AnthropicProvider();
const toolRegistry = new ToolRegistry();
toolRegistry.register(httpRequestTool);

const workflow = WorkflowFactory.create(
  {
    name: 'content-pipeline',
    type: 'sequential',
    agents: [
      {
        name: 'researcher',
        description: 'Gathers information on the topic',
        model: 'claude-sonnet-4-6',
        provider: 'anthropic',
        systemPrompt: 'Research the topic and gather information.',
        tools: [httpRequestTool],
      },
      {
        name: 'writer',
        description: 'Drafts the article',
        model: 'claude-sonnet-4-6',
        provider: 'anthropic',
        systemPrompt: 'Write a comprehensive article based on the research.',
      },
      {
        name: 'editor',
        description: 'Polishes the article',
        model: 'claude-sonnet-4-6',
        provider: 'anthropic',
        systemPrompt: 'Edit and polish the article for publication.',
      },
    ],
  },
  provider,
  toolRegistry,
);

const result = await workflow.execute('Write an article about AI agents', context);
console.log(result.content); // the editor's output

03Parallel workflows

Every agent receives the same input. The result content lists each agent's response, labeled by agent name, in configuration order.

TS
const workflow = WorkflowFactory.create(
  {
    name: 'multi-analysis',
    type: 'parallel',
    agents: [
      {
        name: 'sentiment-analyzer',
        description: 'Scores sentiment',
        model: 'claude-sonnet-4-6',
        provider: 'anthropic',
        systemPrompt: 'Analyze the sentiment of the text.',
      },
      {
        name: 'keyword-extractor',
        description: 'Extracts keywords',
        model: 'claude-sonnet-4-6',
        provider: 'anthropic',
        systemPrompt: 'Extract key topics and keywords.',
      },
      {
        name: 'summarizer',
        description: 'Summarizes the text',
        model: 'claude-sonnet-4-6',
        provider: 'anthropic',
        systemPrompt: 'Create a concise summary.',
      },
    ],
  },
  provider,
  toolRegistry,
);

const result = await workflow.execute('Analyze this product review: ...', context);

// [sentiment-analyzer]: ...
//
// [keyword-extractor]: ...
//
// [summarizer]: ...
console.log(result.content);

04Supervisor workflows

A supervisor workflow starts with the first agent in agents. After each response, the next agent is chosen in this order:

  • The response's nextAgent field, when an agent sets it.
  • The first matching rule in routing.rules. Each rule is a condition(context, response) function and a nextAgent name.
  • The round-robin order, when routing.strategy is 'round-robin'.

When none of these picks an agent, the workflow ends and returns the last response. The loop stops after 10 routing steps.

TS
import { WorkflowFactory, AnthropicProvider, ToolRegistry } from '@lov3kaizen/agentsea-core';

const workflow = WorkflowFactory.create(
  {
    name: 'customer-support',
    type: 'supervisor',
    agents: [
      {
        name: 'triage',
        description: 'Classifies the request and routes it',
        model: 'claude-sonnet-4-6',
        provider: 'anthropic',
        systemPrompt: `You route customer requests. Reply with one word:
technical, billing or general.`,
      },
      {
        name: 'technical-support',
        description: 'Technical troubleshooting',
        model: 'claude-sonnet-4-6',
        provider: 'anthropic',
        systemPrompt: 'Provide technical support and troubleshooting.',
        tools: [databaseQueryTool],
      },
      {
        name: 'billing-support',
        description: 'Billing and payment questions',
        model: 'claude-sonnet-4-6',
        provider: 'anthropic',
        systemPrompt: 'Handle billing and payment inquiries.',
        tools: [paymentApiTool],
      },
      {
        name: 'general-support',
        description: 'General customer support',
        model: 'claude-sonnet-4-6',
        provider: 'anthropic',
        systemPrompt: 'Provide general customer support.',
      },
    ],
    routing: {
      strategy: 'conditional',
      rules: [
        {
          condition: (_context, response) => response.content.includes('technical'),
          nextAgent: 'technical-support',
        },
        {
          condition: (_context, response) => response.content.includes('billing'),
          nextAgent: 'billing-support',
        },
        {
          condition: () => true,
          nextAgent: 'general-support',
        },
      ],
    },
  },
  new AnthropicProvider(),
  new ToolRegistry(),
);

const result = await workflow.execute('My credit card payment failed', context);

Note

The example routes on the text of the triage reply. Keyword matching is fragile, so prefer a structured reply or a nextAgent set by the agent where you can.

05Error handling

Set errorHandling on the workflow config. It is one string value:

'fail-fast' (default)
Throws the agent's error to the caller. The workflow stops.
'retry'
Re-invokes the failing agent up to retry.maxAttempts times. If every attempt fails, the error propagates.
'fallback'
Returns a response in place of the failed agent's output. The content says the agent failed and finish reason is error.
'continue'
Skips the failed agent. In a sequential workflow the next agent receives the same input. In a supervisor workflow the next agent in the list runs.
TS
const workflow = WorkflowFactory.create(
  {
    name: 'resilient-workflow',
    type: 'sequential',
    agents: [/* ... */],
    errorHandling: 'continue',
  },
  provider,
  toolRegistry,
);

try {
  const result = await workflow.execute(input, context);
  console.log(result.content);
} catch (error) {
  console.error('Workflow failed:', error);
}

06Retry strategy

With errorHandling: 'retry', the agent is re-invoked after a failure. Tune the attempts and backoff with the retry config:

TS
const workflow = WorkflowFactory.create(
  {
    name: 'resilient-workflow',
    type: 'sequential',
    agents: [/* ... */],
    errorHandling: 'retry',
    retry: {
      maxAttempts: 5,         // total attempts, including the first
      initialDelayMs: 500,    // base delay between attempts
      backoff: 'exponential', // 'linear' | 'exponential'
      maxDelayMs: 10000,      // cap on the computed delay
    },
  },
  provider,
  toolRegistry,
);

When retry is omitted, the defaults are 3 attempts with no delay. The delay applies only when initialDelayMs is greater than 0. linear waits initialDelayMs * attempt. exponential waits initialDelayMs * 2 ** (attempt - 1). maxDelayMs caps either value.

07Context and results

A workflow takes the same AgentContext as an agent. Its conversationId and memory store are used by every agent in the workflow.

TS
const context = {
  conversationId: 'workflow-123',
  sessionData: {
    userId: '12345',
    userPreferences: { language: 'en', timezone: 'UTC' },
  },
  history: [],
};

const result = await workflow.execute('Create a report', context);

console.log(result.content);
console.log(result.metadata.tokensUsed);
console.log(result.metadata.latencyMs);
console.log(result.metadata.iterations);

Note

Workflows do not expose a streaming API in this version. To stream output, call executeStream() on an individual Agent.

08Workflow factory

WorkflowFactory.create(config, provider, toolRegistry, memory?) returns the workflow class that matches config.type. The types are sequential, parallel and supervisor. A custom workflow must be created with its class directly.

TS
import { SupervisorWorkflow } from '@lov3kaizen/agentsea-core';

// The same config as the factory, constructed directly
const workflow = new SupervisorWorkflow(config, provider, toolRegistry, memory);

09Use cases

Sequential

  • Content pipelines: research, write, edit
  • Data processing: extract, transform, load
  • Multi-step analysis: collect, analyze, report

Parallel

  • Multi-perspective analysis: sentiment, keywords, summary
  • Competitive research across several companies
  • Generating several variations to compare

Supervisor

  • Customer support routing
  • Dynamic task delegation
  • Multi-round problem solving

10Best practices

  • Specialize agents: give each agent one clear role and a specific system prompt.
  • Choose an error strategy for the use case. Use retry for flaky external calls and fallback when a partial answer is acceptable.
  • Route with clear signals: have agents set nextAgent or return a structured answer that a rule can read.
  • Mind the loop limit: supervisor workflows stop after 10 routing steps. Design routing so the loop ends before that.
  • Share context through sessionData: pass what the agents need in the context.
  • Track cost and latency: record tokensUsed and latencyMs from each run.

11Next steps