Skip to content
Docs

How to build a multi-agent flow

A single agent that has to do everything (research, look things up, format, decide, reply) accumulates a long system message and a wide pile of tools. The more it carries, the more its context fills up and the more it can drift off task.

In Publicus you split that work. You build specialist sub-flows, each focused on one job, and an orchestrator agent that delegates to them through the Subflow node. Each subagent runs in its own clean context, does its one job, and returns a result. The orchestrator stays small and decides what to do next.

This guide walks the whole loop: build a specialist → wire it as a subagent → orchestrate → test.

Reach for a multi-agent flow when:

  • The task has distinct phases. Research, then draft, then check. Each phase wants its own instructions, and you do not want phase-one’s reasoning crowding phase-three’s context.
  • A sub-task needs its own narrow tool set. A lookup specialist gets the database tools; the orchestrator never sees them. Smaller tool sets mean cleaner, more reliable tool choices.
  • You want to reuse a capability. A “summarise a document” sub-flow can serve several orchestrators.
  • Context isolation matters. A subagent only sees the arguments the orchestrator passed it, not the whole conversation. That keeps each agent focused and keeps sensitive context from leaking into every step.

Stay with one agent when the task is short, single-phase, and uses a handful of tools. The orchestration overhead is not worth it there.

Create a new flow for the specialist. Keep it focused and linear.

  • Give it an input schema describing what it needs. A research specialist might take a single topic string. The orchestrating model fills these fields when it calls the subagent.
  • Add the nodes that do the work. Inside the sub-flow, read the inputs as $start->topic, the same way a directly-run flow reads its start data.
  • Make the node whose result you want returned the last node. Its output becomes the subagent’s result. If the specialist is itself an Agent, let that Agent node be last so its answer flows back.

A subagent runs as a full run of its own, so the specialist can use anything a normal flow can: connectors, paged processing, Switch branches, conditional exits. You do not need to keep it straight-line.

Open your orchestrator flow and add a Subflow node (the picker groups it under AI). Configure:

  • Target flow: pick the specialist flow you built.
  • Tool description: optional; when this orchestrator should call it, e.g. Before answering any question about a competitor. The orchestrator reads it after the specialist flow’s own Description (set in the flow’s Flow settings), so describe what the flow does there, e.g. Researches a topic and returns a short summary of findings. Make both specific: they are what the model reads to decide whether to delegate.
  • Timeout (seconds): optional; cap how long the specialist may run.
  • Compensating tool: optional; the name of another tool on the same orchestrator that undoes this one (see Roll back side effects).
The Subflow node's settings: Target flow, Run the draft, On error, Timeout (seconds), Tool name, Tool description, Approval, Compensating tool and Pinned arguments
The Subflow node's settings: Target flow, Run the draft, On error, Timeout (seconds), Tool name, Tool description, Approval, Compensating tool and Pinned arguments

Then connect the Subflow node’s OUTPUT to the orchestrator agent’s TOOL handle (the violet wrench at the left of the Agent node’s bottom edge). The specialist is now a tool the orchestrator can call.

An orchestrator flow where a Subflow node is wired into the Agent's Tools handle, the wrench on the bottom edge of the node
An orchestrator flow where a Subflow node is wired into the Agent's Tools handle, the wrench on the bottom edge of the node

You can attach several Subflow nodes to one orchestrator, each pointing at a different specialist. The orchestrator picks among them per call.

Add an Agent node to the orchestrator flow and configure it as you would any agent:

  • Model: your LLM.
  • Instructions: describe the orchestrator’s job and tell it to delegate. For example: You coordinate specialists. Use the research tool to gather facts before you answer. Do not guess.
  • Message: the user’s request, usually from the trigger: {{ $start->payload->message }}.
The Agent node's settings: Provider, Model, Credential, Instructions, Message, Max steps and Approval mode, with the Chat app, More settings and Advanced sections closed below them
The Agent node's settings: Provider, Model, Credential, Instructions, Message, Max steps and Approval mode, with the Chat app, More settings and Advanced sections closed below them

The orchestrator emits its final answer under content, the same as any agent.

The orchestrating model supplies the subagent’s arguments from the fields in the specialist’s input schema. You do not wire those values by hand. Those values become the specialist’s own start data, so inside the specialist you read them with $start, exactly as if someone had run the flow directly with that input.

Because a subagent runs in its own context, it does not see the orchestrator’s start payload or conversation. Give the specialist everything it needs through its input schema. That isolation is what keeps each agent’s context clean.

Treat the orchestrator like any agent flow:

Click Run by hand on the orchestrator flow. Publicus builds a form from the flow’s input schema so you can run it without crafting a request by hand. Watch the canvas: the orchestrator agent streams its tokens, and when it calls a subagent the specialist runs and its result returns to the orchestrator.

Each subagent call is recorded as its own run, linked to the orchestrator’s run. From the orchestrator’s run report you can drill into each specialist run to see exactly which nodes it executed and what it returned.

If a subagent fails, the orchestrator receives the error as a tool result and can recover or route around it rather than crashing. Refine the specialist until it returns the shape you want.

Roll back side effects with a compensating tool

Section titled “Roll back side effects with a compensating tool”

When the orchestrator runs a sequence of side-effecting subagent calls (book a room, then book a flight, then charge a card), a failure or a denied approval halfway through can leave earlier steps applied. To make a subagent reversible, set its Compensating tool field to the name of another tool on the same orchestrator that undoes it, for example a cancel-booking subagent that reverses create-booking.

When a run fails, or an approval is denied after side effects have already happened, Publicus runs the compensating tools for every completed call in reverse order, passing each one the same arguments as the original call. Build compensating tools so they are safe to run more than once, and so they can undo the action from those same arguments (for example, cancelling by the same booking reference the forward call used). If no compensating tool is set, a failure is reported to the orchestrator as an error and nothing is rolled back.

To let several agents call the same specialist, give each of them the flow: a Subflow node on its tool handle, or a flow row in its Toolbox (see Build an agent). Each agent’s canvas then shows every flow it can call.