Sub topic 2
How an agent is stored as metadata
This chapter assumes you can read a Salesforce DX project, run sf commands, and tell a topic from an action in Agentforce. It explains which metadata types make up an agent, how they reference each other, and where they appear on disk. You need this before you can retrieve, package, and deploy an agent correctly.
The five types at a glance
Agent Builder shows one agent, but the metadata API splits it into several components. Each component has its own file in your project, so a retrieve or a manifest has to name all of them.
| Metadata type | What it represents | Typical file suffix |
|---|---|---|
| `Bot` | The agent as a whole: name, description, agent user, agent type | `.bot-meta.xml` |
| `BotVersion` | A version of the agent, with its status (active or inactive) | `.botVersion-meta.xml` |
| `GenAiPlanner` | The planner that selects topics and actions at run time. It lists the topics and actions the agent can use. | `.genAiPlanner-meta.xml` |
| `GenAiPlugin` | One topic: its description, scope, instructions, and the actions it can call | `.genAiPlugin-meta.xml` |
| `GenAiFunction` | One action: a wrapper around an Apex invocable method, a Flow, or a prompt template | `.genAiFunction-meta.xml` |
"Plugin" and "function" are the metadata API names. In the UI, a plugin is a topic and a function is an action. Expect to translate between the two vocabularies whenever you read a deployment error or a diff.
How the pieces reference each other
The types form a tree. The Bot is the root, and a BotVersion hangs off it. The planner holds references to topics and actions by API name. Each topic holds references to its actions. Each action points at the executable asset that does the work.
The last three nodes are not agent metadata types. They are dependencies, and the next chapter covers how to find them. For now, remember that a GenAiFunction file only names its target. If the target is missing in the destination org, the deployment fails or the action cannot run.
What each file contains
The snippets below are abridged to show the fields that matter for deployment. Real files carry more elements, and the exact set depends on the API version and agent type. Always treat your own retrieved files as the source of truth.
Bot
The Bot file holds identity and the agent user.
<?xml version="1.0" encoding="UTF-8"?>
<Bot xmlns="http://soap.sforce.com/2006/04/metadata">
<label>My Service Agent</label>
<description>Answers order and returns questions</description>
<botUser>[email protected]</botUser>
<type>ExternalCopilot</type>
</Bot>The botUser element is a username. Usernames are unique across all Salesforce orgs, and sandbox usernames usually end in the sandbox name. A value that is valid in the source org will often be wrong in the target. This is one of the main environment-specific settings, and a later chapter returns to it.
BotVersion
A BotVersion holds the version's configuration and its status. Its full name combines the bot name and a version label, such as My_Service_Agent.v1. On disk, versions sit in a folder next to the bot file.
<?xml version="1.0" encoding="UTF-8"?>
<BotVersion xmlns="http://soap.sforce.com/2006/04/metadata">
<fullName>v1</fullName>
<status>Inactive</status>
</BotVersion>Deployment does not activate the agent for you. Activation is a separate step, covered in its own chapter. Keep that in mind when you read a version file that says Active. The status you retrieved describes the source org, not what the target org will show after a deploy.
GenAiPlanner
The planner is the index of what the agent can do. It lists topics and agent-level actions by API name.
<?xml version="1.0" encoding="UTF-8"?>
<GenAiPlanner xmlns="http://soap.sforce.com/2006/04/metadata">
<masterLabel>My Service Agent</masterLabel>
<description>Planner for the service agent</description>
<plannerType>AiCopilot__ReAct</plannerType>
<genAiPlugins>
<genAiPluginName>Order_Status</genAiPluginName>
</genAiPlugins>
<genAiFunctions>
<functionName>Lookup_Order</functionName>
</genAiFunctions>
</GenAiPlanner>If a name listed here does not exist in the target org and is not in your deployment, the planner is the component that fails validation. Errors like this point at the planner file, but the real problem is a missing topic or action.
GenAiPlugin
A topic carries the text that shapes the agent's behavior: a description, a scope, and a list of instructions. It also lists the actions it may call.
<?xml version="1.0" encoding="UTF-8"?>
<GenAiPlugin xmlns="http://soap.sforce.com/2006/04/metadata">
<masterLabel>Order Status</masterLabel>
<description>Handles questions about where an order is</description>
<scope>Answer questions about order status and shipping.</scope>
<pluginType>Topic</pluginType>
<language>en_US</language>
<canEscalate>false</canEscalate>
<genAiFunctions>
<functionName>Lookup_Order</functionName>
</genAiFunctions>
<genAiPluginInstructions>
<masterLabel>Instruction 1</masterLabel>
<developerName>Instruction_1</developerName>
<description>Ask for the order number before looking up an order.</description>
<sortOrder>1</sortOrder>
<language>en_US</language>
</genAiPluginInstructions>
</GenAiPlugin>The scope and instruction text is natural language that the model reads at run time. It deploys like any other metadata, so a wording change made in the source org moves to the target only if you retrieve and deploy it. The wording is also what you review in a pull request when the agent behaves differently.
GenAiFunction
An action definition connects the planner's vocabulary to executable code.
<?xml version="1.0" encoding="UTF-8"?>
<GenAiFunction xmlns="http://soap.sforce.com/2006/04/metadata">
<masterLabel>Lookup Order</masterLabel>
<description>Returns the status of an order by order number</description>
<invocationTarget>Get_Order_Status</invocationTarget>
<invocationTargetType>flow</invocationTargetType>
<isConfirmationRequired>false</isConfirmationRequired>
</GenAiFunction>invocationTarget is the API name of the Flow, Apex class, or prompt template. invocationTargetType says which kind it is. This pair is your link to the dependency inventory. For each action, read these two elements and add the target to your list.
Action folders may also contain input and output schema files (JSON) that describe the parameters the action accepts and returns. Retrieve them with the action, and commit them with it. If you copy only the .genAiFunction-meta.xml file by hand, you can lose them.
What it looks like in a DX project
After a retrieve, agent files land under the default package directory. 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/
│ └── My_Service_Agent.genAiPlanner-meta.xml
├── genAiPlugins/
│ └── Order_Status.genAiPlugin-meta.xml
└── genAiFunctions/
└── Lookup_Order/
├── Lookup_Order.genAiFunction-meta.xml
└── schema/
├── input/schema.json
└── output/schema.jsonFolder names and nesting can vary by API version, so compare against what your own retrieve produces. To list what the project holds, run this from the project root:
find force-app -type f \( -name "*.bot-meta.xml" -o -name "*.botVersion-meta.xml" \
-o -name "*.genAiPlanner-meta.xml" -o -name "*.genAiPlugin-meta.xml" \
-o -name "*.genAiFunction-meta.xml" \) | sortYou should see one line per component. If a type is missing, the retrieve did not request it, or the source org does not contain that component.
Practical consequences for deployment
- Name your retrieve by type.
--metadata Botdoes not bring topics or actions. You must request each of the five types, as the earlier retrieve example does. - References are by API name. Renaming a topic or action in the source org changes the name the planner uses. Retrieve again after a rename, or the old name lingers in files you have already committed.
- The files are text and diff well. Topic instructions are visible in version control, which makes behavior changes reviewable.
- Metadata does not include everything. The agent user, its permissions, and the targets of actions live in other components. Metadata that references a missing component deploys only if the component is in the same deployment or already exists in the target.
- Types change across API versions. Salesforce adds fields and sometimes new types for agents. Pin the
sourceApiVersioninsfdx-project.jsonand the<version>in your manifest to the same value, and recheck both when you upgrade.
Exercise
A teammate retrieves only Bot and BotVersion and deploys them to a new sandbox. What is missing, and which type tells the planner which topics exist?
Show answer
The topics (GenAiPlugin), the actions (GenAiFunction), and the planner (GenAiPlanner) are missing, so the deployed agent has no behavior. The GenAiPlanner lists the topics by API name, with each topic listing its own actions.
Exercise
You open a .genAiFunction-meta.xml file and see <invocationTarget>Get_Order_Status</invocationTarget> with <invocationTargetType>flow</invocationTargetType>. What must exist in the target org for this action to work, and where does that component come from?
Show answer
A Flow with the API name Get_Order_Status must exist in the target org, either already there or deployed in the same package. It is not part of the agent metadata types, so you add it to the manifest as a Flow member.