agent generate template

Generate an agent template from an existing agent in your DX project so you can then package the template in a second-generation managed package.

WARNING: This command doesn’t work for agents that were created from an Agent Script file. In other words, you can’t currently package an agent template for agents that use Agent Script.

At a high-level, agents are defined by the Bot, BotVersion, and GenAiPlannerBundle metadata types. The GenAiPlannerBundle type in turn defines the agent’s topics and actions. This command uses the metadata files for these three types, located in your local DX project, to generate a BotTemplate metadata file for a specific agent (Bot). You then use the BotTemplate metadata file, along with the GenAiPlannerBundle metadata file that references the BotTemplate, to package the template in a managed package that you can share between orgs or on AppExchange.

Use the –agent-file flag to specify the relative or full pathname of the Bot metadata file, such as force-app/main/default/bots/My_Awesome_Agent/My_Awesome_Agent.bot-meta.xml. A single Bot can have multiple BotVersions, so use the –agent-version flag to specify the version. The corresponding BotVersion metadata file must exist locally. For example, if you specify “–agent-version 4”, then the file force-app/main/default/bots/My_Awesome_Agent/v4.botVersion-meta.xml must exist.

The new BotTemplate metadata file is generated in the “botTemplates” directory in the output directory specified with the –output-dir flag, and has the name <Agent_API_name>_v<Version>_Template.botTemplate-meta.xml, such as my-package/botTemplates/My_Awesome_Agent_v4_Template.botTemplate-meta.xml. The command displays the full pathname of the generated files when it completes.

See “Develop and Package Agent Templates Using Scratch Orgs” (https://developer.salesforce.com/docs/atlas.en-us.pkg2_dev.meta/pkg2_dev/dev2gp_package_agent_templates.htm) for details about the complete process, which includes using a scratch org to create and test the agent, retrieving the agent metadata to your DX project, running this command to create the agent template, and then packaging the template.

Flag Name (Long)Flag Name (Short)Description
‑‑agent‑file‑fType: Value
Required

Path to an agent (Bot) metadata file.
‑‑agent‑versionN/AType: Value
Required

Version of the agent (BotVersion).
‑‑api‑versionN/AType: Value

Override the api version used for api requests made by this command
‑‑flags‑dirN/AType: Value

Import flag values from a directory.
‑‑jsonN/AType: Boolean

Format output as json.
‑‑output‑dir‑rType: Value

Directory where the generated BotTemplate and GenAiPlannerBundle files are saved.
‑‑source‑org‑sType: Value
Required

Username or alias of the namespaced scratch org that contains the agent which this template is based on.

Generate an agent template from the My_Awesome_Agent Bot metadata file in your DX project and save the BotTemplate and GenAiPlannerBundle to the specified directory; use version 1 of the agent. The agent that the template is based on is in the org with alias “my-scratch-org”: