Sub topic 10
Implementing an action with Flow
This chapter assumes you can build an autolaunched flow, you know how Flow variables work, and you have added an action to a topic in Agentforce Builder. It builds the Flow version of the order-status action from the Apex example in the previous chapter. The two versions should behave the same from the agent's point of view.
What the agent sees of a flow
When you add a Flow action, the agent never reads your flow elements. It sees only these things:
- The flow's label, API name, and description, which become the action's name and instructions.
- Each variable marked Available for input, with its name, description, data type, and whether it is a collection.
- Each variable marked Available for output, with the same properties.
Everything inside the flow is hidden from the agent. If the agent calls the action at the wrong time or fills an input badly, the cause is nearly always in that short list.
Only autolaunched flows can be used as actions. Screen flows need a person to interact with screens, so they do not fit. Record-triggered flows run on data changes and cannot be called by an agent. If you have a screen flow you want to reuse, build a separate autolaunched flow for the agent that holds only the logic.
Flow structure
A good action flow has three parts: read the inputs, do the work, and always set the outputs. The third part is the one people skip. An output variable that is never assigned arrives at the agent as empty, and the agent has to guess why.
Define the variables
Create each variable in the Flow Builder resource manager. For every one, set the API name, data type, and description deliberately. The API name is part of what the agent reads, so orderNumber helps the agent and var1 does not.
Flow label: Get Order Status
API name: Get_Order_Status
Description: Looks up the status of one order by its order number.
Use when the customer asks where their order stands.
Variable: orderNumber
Data type: Text
Available for input: yes
Description: The order number the customer provided, for example
00000101. Ask the customer if it was not given.
Do not guess.
Variable: status
Data type: Text
Available for output: yes
Description: Current status of the order, such as Draft or Activated.
Empty if no order was found.
Variable: message
Data type: Text
Available for output: yes
Description: A short plain-language message describing the outcome,
including when no order matches the number.The descriptions are the same text as in the Apex version. The Flow checkboxes (Available for input and Available for output) do the job that @InvocableVariable does in Apex. A variable with neither box checked is invisible to the agent, which is correct for internal working variables.
Description text you can reuse
A useful description answers four questions: what is this value, what does a valid one look like, what should the agent do if it is missing, and what does empty mean. The sample above covers all four. Compare:
| Variable | Weak description | Stronger description |
|---|---|---|
| orderNumber | The id | The order number the customer provided, for example 00000101. Ask the customer if it was not given. Do not guess. |
| status | Result | Current status of the order, such as Draft or Activated. Empty if no order was found. |
Build the flow logic
Follow these steps for the order lookup.
- Add a Get Records element on Order. Filter on
OrderNumberequals{!orderNumber}. Store only the first record, and store only the fields you need (Status) rather than all fields. - Add a Decision element named "Order found?" that checks whether the record variable is null.
- On the found path, add an Assignment that sets
statusto the record's Status andmessageto a sentence that includes the order number and status. - On the not-found path, add an Assignment that leaves
statusempty and setsmessageto "No order was found with number" followed by{!orderNumber}. - Add a fault path from the Get Records element to a third Assignment that sets
messageto a short failure statement. - Save and activate the flow.
Activation matters. The action picker lists only active flows, and an agent that points at an older active version keeps using it until you activate the new one.
Choose context-aware settings
Flows invoked as actions run in the context of the agent's running user, and by default an autolaunched flow runs in user mode or system mode depending on how it is configured. Check the How to Run the Flow setting. If the flow reads orders, decide on purpose whether it should respect the user's sharing and field access. System mode exposes data the user could not otherwise see, and the agent will happily repeat what it receives. Choose user mode unless you have a reason and have restricted the output.
Data types and structure in Flow
The agent fills inputs by producing values, so simple types work best.
- Text, Number, Boolean, Date, and Date/Time are the most reliable. The agent can derive each from conversation.
- Picklist-like text works when you list the allowed values in the description, for example "One of: Standard, Express, Overnight".
- Record variables and collections can be used, but the agent has to build structured values, and errors rise. For inputs, prefer scalar fields such as an Id or a name, and have the flow load the record itself.
- Outputs can be records or collections, but the agent then reads every field. Return a few scalar values and a message instead of a whole record.
Convert at the boundary. If the customer says "tomorrow", the agent resolves a date. If your flow needs text, convert with a formula inside the flow rather than expecting the agent to format it.
Input collection settings
In Agentforce Builder, each flow input has settings that control how the agent gets the value. Exact labels vary by release, so check your org, but the two ideas are stable:
- Require input makes the agent obtain a value before it calls the action. Use this for anything the flow cannot proceed without, such as the order number.
- Collect data from user tells the agent to ask the user for the value rather than infer it from context. Turn it off for values the agent should pull from earlier conversation or from other actions, such as a customer Id returned by a previous lookup.
An optional input with a sensible default in the flow is better than a required input that annoys the user. Set the default in the variable and say so in the description: "Defaults to Standard if the customer does not say."
Output visibility
Each output also has visibility settings. Two are worth knowing:
- Filter from agent (the exact name varies) hides an output from the agent's reasoning. Use it for values you only need for display or for passing along.
- Show in conversation displays the value to the user directly, without the agent rewriting it.
Hiding an output removes it from the agent's context, so the agent cannot mention or reason about it. Show an output in the conversation only if verbatim display is what you want, such as a formatted confirmation number.
Errors and empty results
Flows fail in two ways, and the agent needs a different signal for each.
An empty result is a normal outcome: the query ran and found nothing. Return a message that says so. If you return nothing, the agent may retry the action, ask the user again, or invent an answer.
A fault is an unexpected failure, such as a lock error or a missing permission. Without a fault path, the flow stops and the agent receives a generic error. With a fault path, you can assign a message and end normally. Keep the message short and free of internals. Put the raw {!$Flow.FaultMessage} in a debug log or a custom object rather than in the output, because the agent may repeat it to the customer.
Align with topic instructions
The topic's instructions should say when to use the action, and the action's description should say what it does. Do not duplicate the input rules in both places. If the topic says "always ask for the order number" and the input description says "do not guess", that is fine. If the topic says "look up the account name" and the flow input is an Id, the agent gets two conflicting signals.
Test and refine
- Run the flow in Flow Builder with debug mode first. Test a valid number, an unknown number, and a case that triggers the fault path.
- In Agentforce Builder, use the preview panel and send realistic utterances, such as "Where is order 00000101?" and "Where is my order?".
- Open the reasoning or trace view for each turn. Check which action was chosen, which input values were passed, and what the agent said about the outputs.
- Change one description at a time and run the same utterances again. When a change fixes one case and breaks another, the descriptions probably overlap with another action.
Exercise
A flow action returns the whole Order record in a record variable, and the agent keeps quoting irrelevant fields to customers. What change would you make, and why?
Show answer
Replace the record output with a few scalar output variables, for example status and message, and mark only those as available for output. The agent reads everything it is given, so returning only what is needed for the answer keeps its replies focused and avoids exposing fields the customer should not see.
Exercise
Your order lookup flow finds no matching order. The agent says "I ran into a problem" instead of "No order was found". What is the likely cause in the flow, and how do you fix it?
Show answer
The not-found path probably leaves the output variables unassigned, so the agent receives nothing to explain. Add a decision after Get Records and an assignment on the not-found path that sets message to a plain statement such as "No order was found with number ..." and describe in the message variable that it covers the no-match case.