Sub topic 1
What you are deploying: agents, topics, and actions
Before you move an Agentforce agent from one org to another, you need to know what the agent is made of. An agent looks like one object in Agent Builder, but it is really a set of parts that reference each other and reference things outside the agent. If you miss one of those parts, the deployment fails or the agent behaves differently in the target org. This chapter names the parts and shows how they connect. Later chapters show how each one is stored as metadata, retrieved, and deployed.
Prerequisites
This chapter assumes you have:
- Basic Salesforce administration skills: orgs, sandboxes, profiles, and permission sets.
- Familiarity with Agentforce concepts, meaning you have seen an agent, a topic, and an action in Agent Builder.
- Basic Salesforce CLI (
sf) usage and a Salesforce DX project structure. - A working idea of what an Apex class and a Flow are, since both can serve as agent actions.
You do not need to have deployed an agent before. You do not need to write any metadata by hand in this chapter.
The agent as a set of layers
An Agentforce agent has three layers that you configure and, later, deploy:
- The agent itself. This holds its name, description, role, company context, and the user it runs as. It also holds the welcome and error messages that customers see.
- Topics. A topic is a category of work the agent can handle, such as "Order Status" or "Password Reset".
- Actions. An action is something the agent can do, such as look up a case, update a record, or send an email.
When a user sends a message, the agent's reasoning engine (the large language model plus Salesforce's planning logic) picks the topic that best fits the request. It then chooses which of that topic's actions to run, in what order, and what to say back. Topics and actions are the agent's working knowledge of what it may do. Moving the agent means moving that knowledge intact.
The bottom row of the diagram matters most for deployment. The Apex class, the prompt template, and the Flow are not part of the agent. They are separate components that the actions point to, and each one needs to exist in the target org.
Topics in detail
A topic has four parts that shape how the agent behaves:
- Name and classification description. The reasoning engine reads the description to decide whether a user's request belongs to this topic. A vague description sends requests to the wrong topic.
- Scope. This states what the topic does and does not cover. A narrow scope keeps the agent from answering outside its job.
- Instructions. These are natural-language rules that tell the agent how to behave within the topic. For example: "Always confirm the order number before looking up an order."
- Actions. This is the list of actions the agent may use inside the topic.
Topics are written in plain language, so deploying them is mostly a matter of copying text accurately. The risk is that the text refers to things that differ between orgs. Instructions can mention a field label, a record type name, or a business rule. If the target org has different labels or settings, the agent follows instructions that no longer match reality.
Actions in detail
An action wraps a capability so the reasoning engine can call it. Every action has a name, a description the engine reads when deciding whether to use it, and a definition of its inputs and outputs. The engine fills in the inputs from the conversation, so clear descriptions for each input improve its accuracy.
Each action runs one of a small number of target types:
| Target type | What it runs | What the target org needs |
|---|---|---|
| Apex | An invocable method in an Apex class | The Apex class, plus any objects and fields it uses |
| Flow | An autolaunched Flow | The Flow, active in the target org, plus the objects and fields it uses |
| Prompt template | A prompt template that calls the model | The prompt template, plus the data it merges in |
| Standard action | A built-in action supplied by Salesforce | The feature that supplies it, enabled in the target org |
The first three are custom: you or your team built them, so you must deploy them with the agent. Standard actions come from the platform, so there is nothing to deploy, but the underlying feature must be turned on in the target org. Chapter on target org readiness covers that.
An action does not carry its own logic. It only holds a reference to the Apex class, Flow, or template that does the work. If you deploy an action without its target, the deployment fails. In a worse case, it succeeds but the action errors at run time.
Instructions at the agent level
Besides topic-level instructions, the agent has its own role, company description, and tone. These apply to every conversation. They are text, so they move with the agent. You should still read them after deployment, because a role description written for a sandbox test (for example, "You are a test agent for the QA team") should not reach production unchanged.
Who the agent runs as
An agent needs an identity in the org so that its actions have permission to read and write data. How the identity works depends on the agent type:
- A service agent that talks to customers runs as a dedicated agent user. This is a user record you create, and it has its own profile and permission sets. Every action runs with that user's access.
- An employee agent that works inside Salesforce for staff runs as the person who is chatting with it, so it has that person's access.
For service agents, the agent user is not deployed with the agent in the usual way. Users are specific to each org, so you create or choose a matching user in the target org and point the agent at it. A common cause of failed or misbehaving deployments is an agent that names a user that does not exist in the target org.
Seeing the parts in a DX project
In a Salesforce DX project, the parts of an agent appear as separate metadata files. You do not need the details yet, but you should see that the agent is spread across several folders. After a retrieve, a project might look like this:
force-app/main/default/
bots/Service_Agent/
Service_Agent.bot-meta.xml
v1.botVersion-meta.xml
genAiPlanners/Service_Agent.genAiPlanner-meta.xml
genAiPlugins/Order_Status.genAiPlugin-meta.xml
genAiFunctions/Get_Order_Details.genAiFunction-meta.xml
classes/OrderLookup.cls
flows/Create_Return_Case.flow-meta.xml
permissionsets/Agent_Action_Access.permissionset-meta.xmlThe mapping from concept to metadata is:
- The agent maps to
Bot,BotVersion, andGenAiPlanner. - A topic maps to
GenAiPlugin. - An action maps to
GenAiFunction. - The Apex class, Flow, and permission set are ordinary metadata that the agent depends on.
The next chapter covers these metadata types one by one. For now, note that the agent is not a single file, and that its dependencies sit outside the agent folders.
To see which of these types your source org has, you can retrieve them with the CLI:
sf project retrieve start \
--metadata GenAiPlanner \
--metadata GenAiPlugin \
--metadata GenAiFunction \
--target-org source-orgThis assumes you have already authorized an org with the alias source-org. The command writes whatever it finds into your force-app folder, so you can open the files and match them to the topics and actions you see in Agent Builder.
Why the split matters for deployment
The layered design gives you three working rules.
- Agent definitions are portable, but their dependencies are not automatic. The agent, topics, and actions move as metadata. The Apex classes, Flows, prompt templates, and permission sets must be included by you.
- Names are the glue. Topics list actions by API name, and actions list targets by API name. If a name changes in one org and not the other, the link breaks. Avoid renaming components after the agent first deploys.
- Text is configuration. Descriptions and instructions steer the model. A change to a single description can change which topic handles a request, so treat these text fields as code that needs review.
Common misunderstandings
- "Deploying the Bot deploys everything." It does not. The
Botholds the agent's identity and versions. The planner, topics, and actions are separate types that you must include. - "Actions contain their code." They do not. They point to Apex, Flows, or templates, which you deploy separately.
- "The agent user comes with the agent." It does not. The user belongs to the org, and you set it up in the target.
- "Standard actions need no attention." They need no deployment, but the feature behind them must be enabled in the target org, or the action is unavailable.
What comes next
With the layers clear, the next chapter looks at how each one is stored as metadata. After that, you build an inventory of dependencies, prepare the target org, retrieve the agent, and write a manifest to deploy it.
Exercise
An agent has a topic called "Returns" with one action, "Create Return Case". The action targets a Flow named CreateReturnCase. You deploy the agent metadata to a target org, but the Flow does not exist there. Describe the two ways this can fail and which is harder to notice.
Show answer
The deployment can fail outright, because the action refers to a Flow that is not in the target org or in the deployment package. Or the deployment can succeed, if validation does not catch the missing reference, and the action then errors at run time when a user asks the agent to create a return. The run-time failure is harder to notice, because nothing alerts you until someone talks to the agent. The fix is to include the Flow, and anything it depends on, in the manifest, and to test the action after deployment.
Exercise
Match each concept to its metadata type: the agent's planner, a topic, and an action. Then say which of the three is not a good place to store Apex logic and why.
Show answer
The planner is GenAiPlanner, a topic is GenAiPlugin, and an action is GenAiFunction. An action (GenAiFunction) is not a place for Apex logic, because it holds only a reference to the Apex class, Flow, or prompt template that does the work. The Apex class is its own component and must be deployed separately.