Sub topic 2
How an agent is stored as metadata
This chapter assumes you know basic Salesforce administration, Salesforce DX project structure, and the Agentforce concepts of agents, topics, and actions. It explains which metadata types make up an agent, so you know what to retrieve and deploy in later chapters.
From the Builder to metadata
You build an agent in Agentforce Builder, but Salesforce saves it as metadata like any other configuration. Each part of the agent maps to a metadata type. Knowing the mapping lets you read a retrieved project and spot what is missing.
| Metadata type | What it holds |
|---|---|
| `Bot` | The agent record: name, description, and the agent user settings. |
| `BotVersion` | A version of the agent, including its status (active or inactive). |
| `GenAiPlanner` | The planner. It lists which topics and actions the agent can use. |
| `GenAiPlugin` | A topic: its description, scope, instructions, and the actions it contains. |
| `GenAiFunction` | An action definition that points to an invocable target, such as an Apex class or a Flow. |
The names come from earlier generative AI features. In current documentation, a GenAiPlugin is what you see as a topic, and a GenAiFunction is what you see as an action.
How the pieces connect
The Bot and its BotVersion are the agent itself. The GenAiPlanner ties the agent to its topics. Each GenAiPlugin references the GenAiFunction records it uses. A GenAiFunction references the Apex class or Flow that does the work.
The last two boxes are not agent metadata types. They are dependencies. If you deploy a GenAiFunction without the Apex class or Flow it points to, the deployment fails or the action cannot run. Chapter 3 covers how to find these dependencies.
What a retrieved project looks like
After you retrieve the agent (covered later), the files land under force-app/main/default in folders named for each type. A typical layout looks like this:
force-app/main/default/
bots/My_Service_Agent/
My_Service_Agent.bot-meta.xml
v1.botVersion-meta.xml
genAiPlanners/
genAiPlugins/
genAiFunctions/Treat these as source files. They are XML, so you can review them in a pull request and compare them between orgs. Open a GenAiPlugin file and you will find the topic's instructions as text. Open a GenAiFunction file and you will find the name of the invocable target.
Things to watch for
- Versions matter. A
BotVersionhas a status. Deploying a version does not make it active in the target org. You activate it as a separate step. - Names are references. Metadata refers to other components by API name. If a Flow has a different name in the target org, the reference breaks.
- Some values belong to an org. The
Botcan reference an agent user by username. Usernames are unique across Salesforce, so a sandbox username will not exist in production. Chapters 7 and 8 cover this. - Retrieve all types together. Retrieving only
Botgives you a shell. The topics and actions live in the other types.
Check your understanding
Exercise
A teammate retrieves only the Bot and BotVersion types and deploys them to a new org. The agent exists, but it has no topics and cannot run any actions. Which metadata types did they leave out, and what else must exist for the actions to work?
Show answer
They left out GenAiPlanner (which links the agent to its topics), GenAiPlugin (the topics), and GenAiFunction (the actions). For the actions to run, the Apex classes or Flows that the GenAiFunction records point to must also be deployed, along with any permissions needed to use them.
Exercise
After a successful deployment, the agent in the target org is not responding to users. Based on what this chapter says about BotVersion, what is the first thing to check?
Show answer
Check the status of the BotVersion. Deploying a version does not activate it, so the agent may still be inactive and need a separate activation step.