Sub topic 7
Adding the template to an agent as an action
This chapter assumes you can already build a prompt template in Prompt Builder, including inputs and merge fields. It also assumes you know what an Agentforce agent and a topic are. Here you connect the two: you take a finished template and make it something an agent can run.
What the action does
An agent action is a unit of work the agent can choose to run. A prompt template action is an action whose work is "fill this template with data, send it to the model, and return the generated text." The agent does not see the template body. It sees an action with a label, a description, inputs, and an output.
This differs from topic instructions in a practical way. Instructions are guidance the agent reads when it plans its reply. A template is a fixed prompt that you test and version. If you need the same summary format every time, put the format in a template. Use instructions to decide when to run it.
Compared with a Flow or Apex action, a prompt template action generates text. It does not change records or call external systems. Flow and Apex actions are better when the agent must create, update, or fetch data.
Prerequisites in your org
Check these before you open the agent:
- The template has at least one active version. A template that only has a saved draft will not appear as a usable action.
- The template type works with agent actions. A Flex template is the safest choice because you define its inputs yourself. Other types can have fixed inputs that do not fit a conversation, so check the current documentation for your release.
- The agent's running user can read the objects and fields the template uses. The template runs with that user's access. A field the user cannot see is left empty in the prompt, and the model works from what remains.
- The Einstein generative AI features and Prompt Builder are enabled in the org.
A template that works in Prompt Builder preview can still produce thin output through an agent. Preview runs as you, and the agent runs as its own user.
The template used in this chapter
The example is a case summary template. Its API name is Summarize_Case. It has one input, a Case record.
You are a service assistant. Write a short, factual summary of the case below for a customer call hand-off.
Case number: {!$Input:Case.CaseNumber}
Subject: {!$Input:Case.Subject}
Status: {!$Input:Case.Status}
Description: {!$Input:Case.Description}
Rules:
- Use at most five sentences.
- Use only the information above. If something is missing, say it is unknown.
- Do not promise refunds or dates.Notice what the template already handles: the output length, the facts it may use, and a prohibition on promises. The action inherits all of this. You do not repeat these rules in the topic.
Adding the action to a topic
Actions belong to topics. The agent only considers an action when the conversation is in the topic that holds it. This is the main reason an action seems to be ignored, so decide on the topic before you add the action.
The steps below use Agentforce Builder. Menu names shift between releases, but the flow is stable.
- Open the agent in Agentforce Builder and select the topic that should own the action, for example
Case Hand-off. - In the topic's action list, choose to add a new action.
- For the reference action type, choose Prompt Template.
- Select
Summarize_Casefrom the list of available templates. - Fill in the label, the API name, and the action instructions.
- Save, then review the generated inputs and outputs.
If you do not see the template in step 4, the cause is almost always one of the prerequisites above: no active version, an unsupported type, or a missing permission.
The fields you fill in
| Field | Purpose | Example |
|---|---|---|
| Agent Action Label | Name shown in the builder and in logs | Summarize Case |
| API Name | Stable identifier used in metadata and deployment | `Summarize_Case` |
| Agent Action Instructions | Text the agent reads to decide whether this action fits the request | Use this action to produce a short hand-off summary of one existing case. Requires a case record. |
| Inputs | Values the agent must supply | Case (record) |
| Outputs | Values returned to the agent | Prompt Response (text) |
The action instructions are different from topic instructions. They describe one action: what it does and what it needs. Topic instructions describe the flow across the whole topic. The next chapter covers topic instructions in detail.
How the pieces connect at runtime
When you save the action, the platform wraps the template in an invocable action. The agent calls it the same way it calls any Flow or Apex action. The template's input resources become the action's inputs. The generated text becomes the action's output.
Two details matter here. First, the merge fields are resolved by the platform, not by the agent. The agent only provides the record identity. Second, the prompt passes through the Einstein Trust Layer on its way to the model, so masking and other protections apply to action calls in the same way as to direct template calls.
The record input problem
A Flex template with a record input needs a record. In a chat, the user types a case number, not a record ID. The agent must turn "00001234" into a Case record before the action can run.
You have three common ways to handle this:
- The agent already has context. If the conversation starts from a Case page, the record can be passed in as context and no lookup is needed.
- A lookup action runs first. A Flow or Apex action takes the case number and returns the Case record. The topic instructions tell the agent to call it first.
- The template takes text, not a record. You define a text input and let the user supply the values. This is simpler, but you lose the automatic record fields and related data.
The second option is the most common for service agents. It means the topic needs two actions, one to find the case and one to summarize it. The topic instructions are what order them. Chapter 8 shows the wording. Input mapping details are in chapter 9.
A complete example configuration
This is how the pieces fit together for the case hand-off topic. The topic text is shown in full so you can see where the action fits in.
Topic: Case Hand-off
Classification description: Handles requests to summarize a support case for a colleague or a customer call.
Scope: Summarizing existing cases only. Does not create or update cases.
Instruction 1: When the user asks for a case summary, ask for the case number if it was not given.
Instruction 2: Once the case is identified, use the Summarize Case action and return its output to the user without rewriting the facts.The scope line is doing real work. It tells the agent this topic never edits cases, which keeps the agent from stretching a summary request into an update. The last instruction tells the agent to pass the output through unchanged. Without it, the agent can paraphrase the summary, and you lose the guarantees you built into the template rules.
Common errors
The action is never called. Check, in order: is the action in the topic that matched the request? Does the action instruction describe the request in terms the user would use? Does the topic instruction tell the agent to use it?
The agent asks the user for a record ID. The agent has no way to resolve the record. Add a lookup action or pass context from the page.
The output is empty or vague. The running user probably lacks field access. Compare the preview in Prompt Builder with the agent's result. If Prompt Builder gives a full summary and the agent does not, permissions are the first suspect.
The agent rewrites the output. The topic instructions do not say to return it as is. Add that to the instruction that calls the action.
You edit the template and nothing changes. The action points at the active version. Edits to a draft version have no effect until you activate it. Versioning is covered in chapter 11.
The action disappears after deployment. The template and the agent must both be deployed, and the template must be activated in the target org. A deployed template that is inactive cannot be selected.
A design note on granularity
Keep one template per job. A template that tries to summarize, classify, and draft a reply gives the agent one action with three outputs jammed into one block of text. Three small templates give the agent three actions it can choose between, and each one can be tested alone.
Also keep the action instruction short and specific. The agent uses it as a selection signal. "Generates text" is useless. "Produces a five-sentence hand-off summary of one existing case" is something the agent can match against a request.
Exercise
You add the Summarize Case action to the Case Hand-off topic. In testing, the agent answers "Please give me the case record ID" instead of calling the action. Name two ways to fix this without changing the template.
Show answer
Add a lookup action (Flow or Apex) that finds the case from its case number, and tell the topic instructions to call it before Summarize Case. Alternatively, pass the case record as page context so the agent already has it. Both avoid asking the user for an ID, and neither needs a template change.
Exercise
The summary looks complete in Prompt Builder preview, but the agent returns a summary with the Description missing. What is the most likely cause, and what do you check?
Show answer
The agent's running user probably cannot read the Case Description field, while your own user can. Check the field-level security and object access of the agent user, and compare it with your own. Preview runs as you, and the agent runs as its own user.