Skip to main content
Fan out work to multiple agents, then combine the results. Restate runs the agents in parallel with automatic retries and recovery. If one agent fails, only that agent is retried, the successful results are preserved.

Example: parallel claim analysis

Three specialist agents analyze a claim concurrently. A decision agent combines their results.
workflow-parallel.ts
const run = async (ctx: restate.Context, claim: ClaimInput) => {
  const [eligibility, rateComparison, fraudCheck] = await RestatePromise.all([
    ctx.serviceClient(eligibilityAgent).run(claim),
    ctx.serviceClient(rateComparisonAgent).run(claim),
    ctx.serviceClient(fraudCheckAgent).run(claim),
  ]);

  const model = wrapLanguageModel({
    model: openai("gpt-5.4"),
    middleware: durableCalls(ctx, { maxRetryAttempts: 3 }),
  });

  const { text } = await generateText({
    model,
    system: "You are a claim decision engine.",
    prompt: `Decide about claim ${JSON.stringify(claim)}.
        Base your decision on the following analyses:
        Eligibility: ${eligibility}, Cost: ${rateComparison} Fraud: ${fraudCheck}`,
  });
  return text;
};
Install Restate and launch it:
npm install --global @restatedev/restate-server@latest @restatedev/restate@latest
restate-server
Get the example:
restate example typescript-vercel-ai-tour-of-agents && cd typescript-vercel-ai-tour-of-agents
npm install
Export your OpenAI API key and run the agent:
export OPENAI_API_KEY=sk-...
npx tsx ./src/workflow-parallel.ts
Register the agents with Restate:
restate deployments register http://localhost:9080 --force --yes # dev only: overrides previous registrations
Start a request for a claim that needs to be analyzed by multiple agents in parallel:
curl localhost:8080/restate/call/ParallelAgentClaimApproval/run --json '{
    "date":"2024-10-01",
    "category":"orthopedic",
    "reason":"hospital bill for a broken leg",
    "amount":3000,
    "placeOfService":"General Hospital"
}'
In the UI, you can see that the handler called the sub-agents in parallel. Once all sub-agents return, the main agent makes a decision.
Parallel agent execution trace