Sub topic 1
What Agentforce is and how agents are structured
Prerequisites
This chapter assumes you already know the following:
- Basic Salesforce concepts: objects, records, and permission sets.
- Flow or Apex at a beginner level. You can read a simple Flow or an Apex class.
- What a large language model (LLM) does: it reads text and produces text that fits the request.
You do not need to have built an agent before. This chapter introduces the parts that every later chapter builds on.
What Agentforce is
Agentforce is the Salesforce platform for building AI agents that work inside your org. An agent is a configured piece of software that reads a request written in natural language, decides what to do, and then does it. It can answer from your data, run automation, and hand a conversation to a person.
An agent differs from a plain chatbot in two ways. A chatbot follows a fixed script of menus and keyword matches. An agent uses an LLM to interpret what the user wants, so it can handle wording you did not plan for. An agent can also take actions, such as reading a record or running a Flow, and does not only return text.
The LLM does not run unchecked. You limit it with three building blocks: topics, instructions, and actions. Most agent behavior comes from how you configure these.
The three building blocks
Topics
A topic is a category of work the agent can handle. Examples are "Order Status", "Returns", or "My Open Cases". Each topic has:
- A classification description: a short statement of when the topic applies. The agent uses it to choose among topics.
- A scope: what the topic covers and does not cover.
- Instructions: guidance for how to behave once the topic is selected.
- A list of actions that the topic is allowed to use.
Topics keep the agent focused. An agent with five narrow topics is easier to predict and test than an agent with one broad topic that tries to do everything.
Instructions
Instructions are plain-language rules that you write inside a topic. They say what to ask for, which action to call, what to report, and what to avoid. Here is the Order Status topic from this tutorial's running example:
Topic: Order Status
Classification description: Customer asks where an order is or what state it is in.
Scope: Look up the status of a single order using the Get Order Status action.
Instructions:
- Ask for the order number if the customer has not given one.
- Call the Get Order Status action with that order number.
- Report only the status returned by the action.
- If the action returns 'Order not found', ask the customer to check the number once, then offer to connect them with a human agent.
- Do not discuss refunds or cancellations in this topic.Notice that the instructions name the action, tell the agent when to stop, and set a limit ("Do not discuss refunds"). Good instructions are specific and short. Vague instructions such as "be helpful with orders" leave the LLM to guess.
Actions
An action is a unit of work the agent can run. Actions are how an agent reads or changes data and triggers processes. An action can be backed by:
- A Flow.
- An Apex invocable method.
- A prompt template.
- A standard action that Salesforce provides.
Each action declares its inputs and outputs. The agent fills in the inputs from the conversation, runs the action, and reads the outputs to write its reply.
How the pieces fit together
When a user sends a message, the agent runs a loop. The reasoning engine, which is the component that coordinates the LLM, reads the message and picks a topic. Inside that topic it follows the instructions, and it may call one or more actions. It then composes a reply from the results.
The loop can repeat. After an action returns, the agent may decide it needs another action before it can answer. A later chapter covers how the reasoning engine makes these choices.
A worked example: an action behind a topic
The Order Status topic calls an action named Get Order Status. Here the action is an Apex invocable method. An invocable method is an Apex method marked with @InvocableMethod so that Flow and agents can call it.
public with sharing class GetOrderStatusAction {
public class Request {
@InvocableVariable(label='Order Number' required=true)
public String orderNumber;
}
public class Response {
@InvocableVariable(label='Order Status')
public String status;
}
@InvocableMethod(
label='Get Order Status'
description='Returns the status of an order for a given order number'
)
public static List<Response> getStatus(List<Request> requests) {
Set<String> orderNumbers = new Set<String>();
for (Request r : requests) {
orderNumbers.add(r.orderNumber);
}
Map<String, String> statusByNumber = new Map<String, String>();
for (Order o : [SELECT OrderNumber, Status FROM Order WHERE OrderNumber IN :orderNumbers]) {
statusByNumber.put(o.OrderNumber, o.Status);
}
List<Response> results = new List<Response>();
for (Request r : requests) {
Response res = new Response();
res.status = statusByNumber.containsKey(r.orderNumber)
? statusByNumber.get(r.orderNumber)
: 'Order not found';
results.add(res);
}
return results;
}
}Three details matter for agents:
with sharingmakes the query respect the record access of the user the action runs as. Which user that is depends on the agent type, and a later chapter covers it.- The method takes and returns lists, so it is bulk-safe. It runs one query for all requests and not one query per request.
- The
labelanddescriptionvalues are what the agent reads when it decides whether this action fits the request. Write them clearly.
The string 'Order not found' is the value the topic instructions test for. The instructions and the action must agree on that text, or the agent will not follow the fallback path.
Two agent types, one structure
Agentforce offers several agent types. This tutorial focuses on two:
- A service agent talks to customers, usually the public or authenticated users of a website, messaging app, or similar channel.
- An employee agent helps internal users, such as staff working in Salesforce or Slack.
Both are built from the same blocks. The difference is in who the agent serves and how it is allowed to touch data. Here is the employee version of a topic:
Topic: My Open Cases
Classification description: An employee asks about support cases assigned to them or their team.
Scope: Summarize cases the employee already has permission to view.
Instructions:
- Use the Get Open Cases action to retrieve cases for the current user.
- Present each case with its number, subject, and status.
- If the employee asks about data they cannot access, say that you cannot show it and suggest contacting their administrator.The structure matches the service topic: a classification description, a scope, and instructions that name an action. The instructions assume an internal user whose own permissions govern what the action can return.
The table below summarizes the contrast that later chapters develop.
| Aspect | Service agent | Employee agent |
|---|---|---|
| Audience | Customers | Internal users |
| Typical channels | Web chat, messaging, and similar | Salesforce and Slack |
| Data access | Governed by a dedicated agent user | Governed by the employee's own permissions |
| Escalation | Often hands off to a human agent | Usually points to an administrator or colleague |
Common errors at this stage
- Overlapping topics. If two classification descriptions describe similar requests, the agent may pick the wrong one. Give each topic a distinct trigger.
- Instructions that contradict the scope. If the scope says "single order" and the instructions describe bulk lookups, behavior becomes unpredictable.
- Unclear action descriptions. The agent chooses actions partly from their descriptions. A label such as "Action 1" gives it nothing to work with.
- Putting everything in one topic. A large topic with many actions makes testing hard and raises the chance of a wrong action call.
- Assuming instructions are enforced like code. Instructions guide an LLM. They are strong guidance, but access limits must come from permissions, not wording.
What comes next
The next chapters look at agent types and templates, then take topics, instructions, and actions one at a time. Later chapters cover identity, grounding, the Einstein Trust Layer, channels, escalation, testing, and deployment.
Exercise
A teammate writes one topic called "Customer Help" that covers order status, returns, and billing, with nine actions attached. Name two problems this design causes and describe how you would restructure it.
Show answer
Problems: the classification description is too broad, so the agent cannot tell clearly when the topic applies, and with nine actions the agent has more chances to pick a wrong one, which also makes testing harder. Restructure it into narrow topics such as Order Status, Returns, and Billing. Give each a distinct classification description, a clear scope, and only the actions it needs.
Exercise
In the Get Order Status Apex class, why does the method accept a List of Request objects, and what would be wrong with running the SOQL query inside the loop that builds the response?
Show answer
Invocable methods can be called with several requests at once, so they must be bulk-safe. A query inside the loop would run once per request and could exceed the governor limit on SOQL queries. The class collects all order numbers first and runs one query.