# Agent Metadata and Lifecycle Reference ## Table of Contents 1. Agent Metadata Structure 2. Agent Metadata Lifecycle Overview 3. Creating an Agent 4. Working With Authoring Bundles 5. Publishing Authoring Bundles 6. Activating Published Agents 7. Lifecycle Operations --- ## 1. Agent Metadata Structure Agent Script agents are defined across two independent metadata domains. Understanding this distinction is critical for every lifecycle operation. ### Two-Domain Entity Graph ``` AUTHORING DOMAIN (developer-owned, exists before any publish) AiAuthoringBundle ├── .agent (Agent Script source — editable text file) └── .bundle-meta.xml (metadata; optional links to published version) RUNTIME DOMAIN (created by publish) Bot (top-level container, one per agent) └── BotVersion (one per published version) └── GenAiPlannerBundle (versioned bundle, contains compiled agent definition) └── local subagents and actions (scoped to this version only) ``` The authoring domain is where you work. The runtime domain is what the org creates when you publish. These two domains are separate until you publish, which is when they connect. ### The Authoring Domain: AiAuthoringBundle An `AiAuthoringBundle` is a Salesforce metadata source component represented as a directory in your local project containing two files: **1. `.agent` file** — Agent Script source code. This is the editable text file where you define subagents, actions, variables, and flow control. It is human-readable and supports multiple versions. **2. `.bundle-meta.xml` file** — Metadata about the bundle. Contains a `bundleType` element set to `AGENT` and optionally a `` element that controls whether the bundle is DRAFT (editable) or locked to a published version: ```xml AGENT Local_Info_Agent.v2 ``` When `` is present, the bundle is locked to that published version and cannot be modified. Draft-state bundles omit `` entirely. Authoring bundles are stored in `/main/default/aiAuthoringBundles/` where `` comes from `sfdx-project.json`. ### Two Forms of AiAuthoringBundle Locally **Naked AiAuthoringBundle** (e.g., `Local_Info_Agent`) — No version suffix in the directory name. In the org, this always points to the highest DRAFT version. This is the only writable surface for pro-code developers. **Version-suffixed AiAuthoringBundle** (e.g., `Local_Info_Agent_1`, `Local_Info_Agent_2`) — Published snapshots retrieved from the org after publication. Locked by a `` element in their `bundle-meta.xml`. Read-only — modified deploys fail; unmodified deploys succeed as misleading no-ops. Use these for version history inspection, diffing, and auditing. NEVER edit a version-suffixed authoring bundle expecting your changes to persist. ### The Runtime Domain: Bot → BotVersion → GenAiPlannerBundle Publishing creates the runtime entities that make an agent usable in the org. **Bot** — Top-level container (one per agent). Links to all published versions. Query `BotDefinition` when the ID of a published agent is required. See [CLI for Agents](salesforce-cli-for-agents.md) for query syntax. **BotVersion** — One per published version (e.g., `v1`, `v2`, `v3`). Only one version can be active at a time. **GenAiPlannerBundle** — Compiled agent definition for a specific version. Contains subagents, actions, and all runtime metadata, scoped to that version only. Runtime entities are org-generated and never edited directly. ### Agent Pseudo Metadata Type When using the Salesforce CLI, `Agent:X` is a pseudo-metadata type that covers the runtime domain components: `Bot`, `BotVersion`, `GenAiPlannerBundle`, and related GenAiPlugin/GenAiFunction metadata. This saves you from specifying each type individually during retrieve/deploy. **CRITICAL GOTCHA:** `Agent:X` retrieve does NOT include `AiAuthoringBundle`. If you need the authoring bundle (to see the `` element or to work with the source), use `AiAuthoringBundle:X` explicitly. --- ## 2. Agent Metadata Lifecycle Overview ### Recommended Pipeline The end-to-end pipeline for creating and activating an agent: 1. `sf agent generate authoring-bundle --json --no-spec --name "