Sub topic 4
Designing a focused action
This chapter covers how to scope an action before you build it. It assumes you know the basic Salesforce data model, can build a simple autolaunched flow, and have a general idea of how an agent chooses between actions. The earlier chapters introduced how agents, topics, and actions relate, and why Flow is a good fit for many actions. Here the question is narrower: what should one action do, and what should it leave out?
Why scope matters to an agent
A flow built for a screen or a record trigger is read by people who know the context. An action is read by a language model that sees only a name, a description, and a list of inputs and outputs. It picks an action by comparing the customer's request with those texts. A broad action makes that comparison harder, and the agent will call it with wrong inputs or at the wrong moment.
A focused action has four traits:
- It does one job that you can state in one sentence.
- Its inputs are values a customer can plausibly supply or the agent can already know.
- Its outputs answer the question that triggered the call.
- Its side effects are predictable from its name.
Compare two designs for the same need.
| Design | Name | What it does | Problem |
|---|---|---|---|
| Broad | Manage Case | Looks up, updates, closes, or escalates a case, depending on an `operation` input | The agent must guess the right `operation` value. One bad guess changes data. |
| Focused | Get Case Status | Reads the status of one case | None of note. It is read-only and its purpose is clear. |
| Focused | Escalate Case | Sets the escalation flag on one case | Writes data, so it needs clear instructions about when to use it. |
Splitting the broad design into several actions moves the decision about which operation to run from an input value into the agent's action selection. The agent is better at the second kind of decision, because the descriptions of separate actions are written to be compared.
The one-sentence test
Before you open Flow Builder, write what the action does in one sentence with one verb. If you need "and" or "or" to describe it, you probably have more than one action.
- "Get the status of a case from its case number." Passes.
- "Look up a case and update it if the customer asks." Fails. It is a lookup and an update.
- "Create a case or return an existing one for this contact." Borderline. This is a find-or-create pattern. Keep it as one action only if the agent never needs to do one half alone. Otherwise split it.
Name the action with that verb and the object: Get Case Status, Update Shipping Address, Create Return Request. Avoid vague verbs such as "Handle", "Process", or "Manage".
Separate reads from writes
A read action returns data and changes nothing. If the agent calls it too often or with a slightly wrong input, nothing is damaged. A write action changes records, and a mistaken call can be hard to undo. Treat the two differently.
- Keep read and write logic in separate actions where you can. The agent can then look up a record, confirm it with the customer, and only then call the write action.
- For write actions, require inputs that identify the record exactly, such as a record ID or a case number, and not a free-text name that could match several records.
- For destructive or hard-to-reverse writes, require a confirmation input or have the agent instructions say to confirm with the customer first. Chapter 11 covers where to put those instructions.
- Prefer updating a narrow set of fields. An action that updates one status field is easier to reason about than one that accepts a whole record.
Choose inputs the agent can supply
Each input is a question the agent must answer before it can call the action. The agent can fill an input from three sources: what the customer said in the conversation, context the agent already holds, and the result of an earlier action. If an input fits none of these, the agent will either ask the customer or invent a value.
Use these rules when deciding what to ask for:
- Ask for the smallest identifier that finds the record. A case number is better than a case's subject text.
- Do not ask for values the flow can look up itself. If the flow can find the account from the case, do not add an
accountIdinput. - Do not ask the customer for internal IDs they have never seen, such as an 18-character record ID. If the agent needs one, get it from a previous action's output.
- Keep the number of inputs low. Each extra input is another chance for the agent to ask an unneeded question or pass a wrong value.
- Use simple data types. Text, number, boolean, and date are easy for the agent to fill. A full record variable or a collection of records is harder to populate from a conversation.
The Get Case Status flow from this tutorial follows these rules. It takes one text input, and returns one text output:
<variables>
<name>caseNumber</name>
<dataType>String</dataType>
<isCollection>false</isCollection>
<isInput>true</isInput>
<isOutput>false</isOutput>
<description>The Case Number of the case to look up, for example 00001026.</description>
</variables>
<variables>
<name>caseStatus</name>
<dataType>String</dataType>
<isCollection>false</isCollection>
<isInput>false</isInput>
<isOutput>true</isOutput>
<description>The current Status of the case, or a short message if no case was found.</description>
</variables>The input is a value the customer already has. The output is a single sentence-sized result, so the agent can pass it straight into its reply. The next two chapters cover how to define these variables and write their descriptions.
Design outputs for the reply
Outputs are what the agent has to work with when it writes its answer. Return what the customer asked for and little else.
- Return the answer, not the whole record. A status string is easier to relay than ten fields, and it avoids exposing data the customer did not ask about.
- Return human-readable values. Use the status label such as "Waiting on Customer", not an internal code.
- Return a result for the empty case. If no record matches, return a short message rather than a blank value, so the agent does not stay silent or guess.
- Consider a separate boolean or text output for success, so the agent can tell a real result from a failure. Chapter 8 covers error outputs in detail.
Decide how much logic belongs in the flow
The flow should hold the business rules, and the agent should hold the conversation. If a rule such as "only open cases can be escalated" is written in the agent's instructions, the model may apply it inconsistently. If it is written as a decision element in the flow, it runs the same way every time.
A practical split:
- Put validation, calculations, eligibility checks, and data access in the flow.
- Put wording, tone, and when to ask follow-up questions in the agent's topic and action instructions.
- Return a clear message from the flow when a rule blocks the request, such as "This case is already closed and cannot be escalated", so the agent can explain it.
This also keeps the action safe when it is reused in more than one topic, because the rules travel with the flow.
Fit the action to its topic
An action lives inside a topic, and a topic is a set of related jobs. Check that your action belongs with its neighbors.
flowchart TDRather than a diagram of the whole agent, use this checklist when you place an action:
- Does the action's purpose match the topic's description?
- Would the agent ever confuse it with a sibling action? If two actions have overlapping descriptions, rewrite one or merge them.
- Is the topic already crowded? A long list of actions makes selection harder. Consider moving some into a new topic.
Common mistakes
- The catch-all action. One action with an
operationinput tries to cover many jobs. Split it by verb. - Overlapping actions. "Get Case Status" and "Check Case" do the same thing under different names. The agent may pick either, and results will vary. Keep one.
- Hidden side effects. A lookup action that also updates a "last viewed" field surprises people and breaks the read-only guarantee. Move the update elsewhere.
- Too many inputs. A flow with eight inputs invites wrong values. Look for inputs the flow can derive.
- Internal names in outputs. Returning API values such as
Closed_Won__cmakes the agent's reply awkward. Return labels. - Rules in prose only. If a restriction exists only in the agent's instructions, treat it as a suggestion. Enforce it in the flow.
Worked example: scoping a return request
A retailer wants an agent to help with returns. The first draft is a flow called Handle Return with these inputs: orderNumber, action (lookup, create, or cancel), reason, refundMethod, customerEmail, and notes.
Apply the one-sentence test. "Handle returns" has no single verb, so split it:
- Get Return Eligibility. Input:
orderNumber. Output:eligibilityMessage. Read-only. The flow checks the return window and order status. - Create Return Request. Inputs:
orderNumber,reason. Outputs:returnNumber,resultMessage. Writes one record. The flow re-checks eligibility itself before creating anything. - Cancel Return Request. Input:
returnNumber. Output:resultMessage. Writes one field.
Then trim the inputs. customerEmail is dropped, since the flow can find the customer from the order. refundMethod is dropped, because the business rule always refunds to the original payment method, and that rule lives in the flow. notes is dropped because the agent has no reason to ask for it. The action input disappears, because each action now has one purpose.
The result is three actions with one or two inputs each. Each can be described in a sentence, and the write actions take exact identifiers.
Exercise
A flow named "Update Order" accepts an orderId, a field text input, and a newValue text input, and sets whichever field the agent names. List two problems with this design for an agent action, and describe a better design.
Show answer
First, the agent must choose valid field names and values, so a wrong guess can write bad data to the wrong field, and the flow can write to any field it is given. Second, the name and purpose are vague, so the agent cannot tell from the description when to call it. A better design uses one action per real job, such as "Update Shipping Address" with typed inputs for the address parts and "Cancel Order" with only an order number. Each action sets fixed fields, takes exact identifiers, and enforces its own business rules in the flow.
Exercise
A "Get Account Details" action returns the whole Account record, including revenue and owner fields, when a customer only asks "What plan am I on?" Which design principle does this break, and how would you change the action?
Show answer
It breaks the principle of returning only what answers the question. Returning the whole record exposes data the customer did not ask about and gives the agent extra material to misuse. Change it to a focused action such as "Get Current Plan" that takes the account identifier, and returns a single readable output like planName, with a short message if no plan is found.