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.
When to prefer this over one big agent
Section titled “When to prefer this over one big agent”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.
1. Build the specialist sub-flow
Section titled “1. Build the specialist sub-flow”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
topicstring. 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.
2. Wire it as a subagent
Section titled “2. Wire it as a subagent”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).


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.


You can attach several Subflow nodes to one orchestrator, each pointing at a different specialist. The orchestrator picks among them per call.
3. Build the orchestrator agent
Section titled “3. Build the orchestrator agent”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 orchestrator emits its final answer under content, the same as any agent.
4. Pass data into the specialist
Section titled “4. Pass data into the specialist”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.
5. Add a trigger and a reply
Section titled “5. Add a trigger and a reply”Treat the orchestrator like any agent flow:
- Add a trigger: a Webhook,
Webhook / Chat, or Schedule. - Add a
Channel / *send node and wireAgent → Channel/*with the message set to{{ $prev->content }}. See connecting an agent to a chat channel.
6. Test it
Section titled “6. Test it”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.
One specialist for several agents
Section titled “One specialist for several agents”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.
Related
Section titled “Related”- Subflow: the node that runs a flow as a tool.
- Llm / Agent: the agent that orchestrates.
- How to build an AI agent: the single-agent loop.
- Connect an agent to a chat channel.
- Expressions: read a subagent’s inputs with
$start.