Overview
You can merge multiple branches into one downstream node in the Agent Builder. The shared node runs regardless of which branch was taken, so you can keep one source of truth for follow up actions and reduce duplication in complex agents.When to merge branches
Use a merged node when:- Different paths share the same outcome Example: You route requests by department (IT, HR, Finance), but every path should end with the same Respond step or the same Create doc action.
- You want a single place to maintain logic or formatting Update instructions or output formatting in one node instead of many, reducing the risk of inconsistencies.
- You want a cleaner canvas as agents grow Converging branches reduces visual clutter and makes graphs easier to understand and safely extend.
How merging branches works
On the canvas:- You connect the last node of each branch into the same downstream node (the “merged” node).
- At run time, only the branch that actually executes feeds its outputs into the merged node; the node then runs once for that path.
- The merged node can be any supported step type, including sub-agents; merging works in both parent agents and sub-agents.
- You can continue to branch again after the merged node if needed.
Merge branches into a single node
To merge branches in an existing agent:- Open your agent in the Agent Builder.
- Identify the branch endpoints you want to converge (for example, final Respond steps that are currently duplicated).
- Choose or create the shared downstream node:
- Use an existing node (for example, keep one of your existing Respond steps), or
- Add a new node (for example, Respond, Create doc, or a sub-agent) and configure it as your shared output.
- On each branch’s last node, drag from the drag-to-connect handle to the shared node to create the merge connection.
- Review the shared node’s configuration:
- Make sure its inputs reference only data that’s available from every path that can reach it.
- Adjust instructions so the output still makes sense for all branches.
- Save and run Preview with test inputs that exercise each branch, confirming that:
- The correct branch logic still runs.
- The merged node runs once per execution and returns the expected final response or action.
To refactor older agents, repeat this process to replace duplicated end-steps with a single shared node, then delete any now-unused duplicates. This reduces maintenance and keeps branches in sync over time.