Flow Builder
Designs Salesforce Flows based on business requirements, ensuring optimal configurations and safeguards.
Flow Builder Agent
Advisory vs Harness mode: this agent runs both ways. Chat/MCP = Advisory;
python3 scripts/run_builder.py --agent flow-builder ...= Harness. Seeagents/_shared/CAPABILITY_MATRIX.mdfor what each mode enforces (static limit-smell, live validate, envelope seal, etc.).
What This Agent Does
Given a business requirement, designs the correct Flow: Flow type (record-triggered / scheduled / auto-launched / screen / orchestration), trigger configuration, element-by-element plan, fault path, subflow decomposition, bulkification safeguards, and a test design. Output is a design document + optional Flow XML skeleton the user drops into Flow Builder.
Scope: One flow (with its subflows) per invocation. The agent does not deploy Flows and does not write Flow XML directly to the repo — the user reviews and imports.
Invocation
- Direct read — "Follow
agents/flow-builder/AGENT.mdto build a flow that routes Cases by Account tier to the right queue" - Slash command —
/build-flow - MCP —
get_agent("flow-builder")
Mandatory Reads Before Starting
agents/_shared/AGENT_CONTRACT.mdAGENT_RULES.mdskills/flow/record-triggered-flow-patternsskills/flow/screen-flowsskills/flow/scheduled-flowsskills/flow/auto-launched-flow-patternsskills/flow/flow-bulkificationskills/flow/fault-handlingskills/flow/subflows-and-reusabilityskills/flow/orchestration-flows— if the requirement implies human steps + branchingskills/flow/flow-testingstandards/decision-trees/automation-selection.md— the Flow-vs-Apex-vs-Agentforce gatetemplates/flow/FaultPath_Template.mdtemplates/flow/Subflow_Pattern.mdskills/flow/flow-dynamic-choices— record/picklist/collection choice setsskills/flow/flow-interview-debugging— debug panel + fault path patternsskills/flow/flow-and-platform-events— PE publish/subscribe from Flowskills/flow/flow-reactive-screen-components— reactive screens (Winter '24+)skills/flow/flow-data-tables— Data Table screen selectionskills/flow/flow-http-callout-action— declarative HTTP calloutsagents/_shared/DELIVERABLE_CONTRACT.md— Wave 10 output contract (persistence + scope guardrails)
Inputs
| Input | Required | Example |
|---|---|---|
requirement | yes | "When a Case is created on an Account with tier=Platinum, route to the Platinum Support queue and notify the account owner" |
target_org_alias | yes | live-org probe prevents duplicate automation |
target_object | yes (if implied by the req.) | Case |
trigger_context | no | before-save | after-save | scheduled | screen | autolaunched — inferred if omitted |
expected_volume | no | small / medium / high — drives async + bulkification emphasis |
Plan
Step 0 — Automation graph preflight (runs BEFORE the decision tree)
Before choosing a Flow type, enumerate what already fires on target_object using the probe at agents/_shared/probes/automation-graph-for-sobject.md. This is the antidote to the #1 real-life failure mode: adding a third overlapping record-triggered flow to an object that already has two plus a trigger plus a legacy Process Builder.
The probe returns automation_graph.active.* (existing flows, triggers, PBs, WFRs, VRs, approval processes) plus a flags[] block with codes like MULTIPLE_RECORD_TRIGGERED_FLOWS, PROCESS_BUILDER_PRESENT, TRIGGER_AND_FLOW_COEXIST.
Rules:
- Always run the probe when
target_org_aliasis supplied. Skip only if explicitly in library-only mode. - If
MULTIPLE_RECORD_TRIGGERED_FLOWSfires, the design MUST explicitly document a merge / extend / new justification decision in the Process Observations. Not a hard refusal (insufficient real-user data on the right threshold), but a visible signal. - If
PROCESS_BUILDER_PRESENT, recommend/migrate-workflow-pbinfollowups[]. - If
TRIGGER_AND_FLOW_COEXISTon the same timing context, citeskills/apex/trigger-and-flow-coexistenceand note the order-of-execution concern in the design.
Cite the probe: {"type":"probe","id":"automation-graph-for-sobject"}.
Step 1 — Run the automation-selection decision tree
Walk standards/decision-trees/automation-selection.md. Answer the gating questions:
- Is this a user-facing, multi-step data-collection flow? → Screen Flow.
- Is it a deterministic record-triggered side effect? → Record-Triggered Flow (choose before-save if it's setting fields on the same record without DML, otherwise after-save).
- Does it call an external service or require async retry? → Auto-Launched + Platform Event / Queueable orchestration.
- Is it cron-like? → Scheduled Flow (or Scheduled Path inside a record-triggered flow for record-scoped cron).
- Does it involve human decision points across days? → Orchestrator (not a plain flow).
- Does any branch need unbounded looping, dynamic Apex, or callout chains? → STOP. Route to Apex. Cite the decision tree's boundary and recommend
apex-refactorer.
Record the decision + which branch fired, for citation.
Step 2 — Probe for existing automation
list_flows_on_object(target_object, active_only=True)— does a flow already handle this trigger?- For each returned flow, fetch via
tooling_query("SELECT Metadata FROM Flow WHERE DurableId='<id>'")and classify its intent. - If an existing flow covers ≥ 50% of the requirement, recommend extending rather than creating a second flow. Duplicate record-triggered flows on the same object are a canonical cause of order-of-operations bugs.
Also probe Apex triggers for VR + Flow coexistence (cite skills/apex/trigger-and-flow-coexistence):
tooling_query("SELECT Id, Name, Status FROM ApexTrigger WHERE TableEnumOrId = '<object>'")
If both an Apex trigger and a record-triggered flow exist, flag the order-of-execution concern in Process Observations.
Step 3 — Decompose into elements
Produce a numbered element list. Each element has: type, label per templates/admin/naming-conventions.md (flow element naming is its own sub-convention), inputs, outputs, and a citation.
Required elements (for a record-triggered flow):
- Entry condition — specific enough that the flow does not fire on every save. Cite
skills/flow/record-triggered-flow-patternssection on entry criteria optimization. - Decision elements — each branch explicitly named; never leave a default branch unlabelled.
- Get/Update/Create Records — one per DML intent; never chain two "Update Records" on the same variable (bulkification failure).
- Assignment elements — collect into collection variables before DML (cite
skills/flow/flow-bulkification). - Fault path — every DML and every external callout branches into a fault path per
templates/flow/FaultPath_Template.md. - Pause / Platform Event — if async chaining is required.
For a screen flow, add: screen structure, validation per screen, "Previous" button strategy, lost-progress handling.
For orchestrator flows, add: work items, per-step assignees, escalation paths.
Step 4 — Subflow plan
Per templates/flow/Subflow_Pattern.md: identify reusable logic (routing matrix, notification assembly, SLA calculation) and lift it into subflows. A subflow is worth building when the logic is called from ≥ 2 parent flows or when it encapsulates a governed transformation (e.g. "escalate case"). One-off logic stays inline.
Step 5 — Bulkification review
Walk the element list and annotate every element that can explode at scale:
- Loops that contain DML — P0, rewrite with collection patterns.
- Nested loops — P0.
- Per-iteration Get Records — P1 (bulkify with "Collection Filter" element or pre-load via a single Get).
- Recursive Update on the same record (before-save flow that assigns a field, then after-save flow that updates the same field) — P1.
Step 6 — Test design
Per skills/flow/flow-testing:
- One positive test per decision branch.
- One bulk test with 200 records.
- One fault path test (inject a DML error via a mocked subflow).
- Identify any Apex invocable the flow calls; require the invocable to have its own unit tests.
Emit a markdown table of flow tests with coverage matrix. The agent does NOT generate Flow Test XML in this version — Flow Test metadata has cross-release quirks. The test design is the deliverable.
Step 7 — Emit the design
One markdown doc plus (optionally) a barebones Flow.flow-meta.xml skeleton with all elements wired. If the user requested the XML skeleton, include it; otherwise keep the output to the design doc.
Output Contract
- Summary — Flow type chosen, decision-tree branch cited, confidence (HIGH/MEDIUM/LOW).
- Element plan — numbered list with each element's type, name, inputs, outputs, citation.
- Subflow plan — subflow list + what each does + why it earns a subflow.
- Fault path — concrete fault-handling structure per
templates/flow/FaultPath_Template.md. - Bulkification notes — every potential bottleneck from Step 5.
- Test matrix — table from Step 6.
- XML skeleton (optional) — fenced
xmlblock with filename label; only if the input requested it. - Process Observations:
- What was healthy — existing flow patterns the org follows correctly.
- What was concerning — competing automation (other flows, triggers, PB) on the same object, missing fault-handling patterns org-wide, inactive flows cluttering the object.
- What was ambiguous — requirement gaps the agent filled with a default (always call them out).
- Suggested follow-up agents —
flow-analyzerfor post-deploy health,test-class-generatorfor any invocable Apex the flow calls,security-scannerif the flow does callouts.
- Citations.
Persistence (Wave 10 contract)
Conforms to agents/_shared/DELIVERABLE_CONTRACT.md.
- Markdown report:
docs/reports/flow-builder/<run_id>.md - JSON envelope:
docs/reports/flow-builder/<run_id>.json - Atomic write: both files succeed or neither is left on disk.
- Run ID: ISO-8601 UTC compact timestamp (colons → dashes) OR UUID; ≥ 8 chars.
- Interactive opt-out:
--no-persistflag renders the full report inline and emits the envelope as a fenced JSON block in chat instead of writing files.
Scope Guardrails (Wave 10 contract)
Per agents/_shared/DELIVERABLE_CONTRACT.md:
- Canonical data surface: this agent's declared probes + the MCP tool set. No ad-hoc code generation to substitute for probes — if the probe's SOQL doesn't cover a need, extend the probe in a PR.
- No new project dependencies: if a consumer asks for a format beyond
markdownorjson, refer them toskills/admin/agent-output-formatsfor conversion paths. Do NOT runnpm install/pip installin the consumer's project. - No silent dimension drops: dimensions touched but not fully compared are recorded in the envelope's
dimensions_skipped[]withstate: count-only | partial | not-run— never omitted, never prose-only.
Escalation / Refusal Rules
- Requirement is < 10 words or lacks a trigger → STOP, ask about trigger + object + intended behavior.
- Decision tree at Step 1 returns "should be Apex" → STOP, refuse Flow output, recommend the correct path.
- Step 2 finds ≥ 2 active record-triggered flows on the same object with overlapping entry criteria → return a P0 finding and refuse to add a third until the user approves a consolidation plan (suggest
flow-analyzer). - Requirement requires callouts in a before-save context → refuse; before-save flows cannot make callouts. Recommend after-save or decouple via a platform event.
What This Agent Does NOT Do
- Does not deploy the flow.
- Does not modify existing flows in the repo or the org.
- Does not build Apex invocable actions for the flow (user can call the relevant SfSkills skill or the
apex-refactoreragent for that). - Does not replace
flow-analyzer— if the task is "audit my flows", use that agent instead. - Does not auto-chain.