Sub topic 7
Adding the template to an agent as an action
This chapter assumes you have built and saved a prompt template in Prompt Builder, and that you know what an Agentforce agent and a topic are. Here you attach the template to a topic as an action. The next chapters cover the topic instructions that trigger it and the mapping of its inputs and outputs.
What the action does
A prompt template action is an action whose job is to run a prompt template. The agent decides when to call it, based on the topic's instructions. The template builds its prompt from your merge fields, and the Einstein Trust Layer and the model process that prompt. The generated text goes back to the agent.
The template therefore holds the wording and the grounding data. The agent only decides when to run it and which record to pass in.
Prerequisites for the template
Check these before you add the action:
- The template has an active version. A template with only saved or draft versions does not appear as a usable choice.
- The template type is one that the action picker lists. A Flex template that takes a record input, such as
Case, is the most flexible choice. - Your user and the agent's running user can read the objects and fields the template uses. Missing field access shows up later as empty merge fields.
This is the template used in the example below:
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.Add the action to a topic
The exact labels vary by release. The steps follow this pattern.
- Open the agent in Agent Builder and select the topic that should own the work, for example Case Hand-off.
- Open the topic's actions and choose to add a new action.
- Set the reference action type to Prompt Template.
- Pick your template, for example
Summarize_Case. - Review the generated action name and its instructions. Edit them to say what the action does and when to use it.
- Save the action and check that it now appears in the topic's action list.
The agent reads the action's name and instructions when it plans a response. A name such as Summarize Case with the instruction "Returns a short hand-off summary of one case" gives the planner a clear signal. A vague name such as Action 1 does not.
What the template inputs become
Each input resource in the template turns into an input of the action. In the example, the Case input becomes an action input that expects a case record. The agent has to supply it. It usually gets the value from the conversation, from a record the user is viewing, or by asking the user for a case number.
The generated text becomes the action's output. The agent can return it to the user directly or use it in a later step. Chapter 9 covers how to map these inputs and outputs.
Common problems
| Symptom | Likely cause | What to check |
|---|---|---|
| Template is missing from the picker | No active version, or an unsupported type | Activate a version in Prompt Builder |
| Agent never calls the action | Topic instructions do not mention it | Rewrite the instructions and the action description |
| Agent calls it but fields are blank | Wrong record passed, or no field access | Test the template with that record in Prompt Builder |
| Output differs from the preview | Template edited after the action was added | Confirm which version is active |
Exercise
You added a Summarize Case prompt template action to a topic. In testing, the agent answers case questions from its own general knowledge and never runs the template. The template works correctly in Prompt Builder. What should you check first, and why?
Show answer
Check the topic's instructions and the action's name and description. The template itself is fine, so the problem is that the agent's planner has no clear reason to select the action. Add an instruction that tells the agent to use the Summarize Case action when a user asks for a case summary, and make the action description say what it returns.