Skip to content

Commit 89ef4ee

Browse files
Merge pull request #376 from salesforcecli/fix-bot-template-generation
Fix bot template generation
2 parents 29f2f11 + b48cfe7 commit 89ef4ee

67 files changed

Lines changed: 4704 additions & 273 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -422,14 +422,18 @@ _See code: [src/commands/agent/generate/authoring-bundle.ts](https://github.com/
422422

423423
## `sf agent generate template`
424424

425-
Generate an agent template from an existing agent in your DX project so you can then package the template in a managed package.
425+
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.
426426

427427
```
428428
USAGE
429-
$ sf agent generate template --agent-version <value> -f <value> [--json] [--flags-dir <value>] [--api-version <value>]
429+
$ sf agent generate template -o <value> --agent-version <value> -f <value> [--json] [--flags-dir <value>] [--api-version
430+
<value>] [-r <value>]
430431
431432
FLAGS
432433
-f, --agent-file=<value> (required) Path to an agent (Bot) metadata file.
434+
-o, --source-org=<value> (required) Username or alias of the namespaced scratch org that contains the agent which
435+
this template is based on.
436+
-r, --output-dir=<value> Directory where the generated BotTemplate and GenAiPlannerBundle files are saved.
433437
--agent-version=<value> (required) Version of the agent (BotVersion).
434438
--api-version=<value> Override the api version used for api requests made by this command
435439
@@ -438,32 +442,41 @@ GLOBAL FLAGS
438442
--json Format output as json.
439443
440444
DESCRIPTION
441-
Generate an agent template from an existing agent in your DX project so you can then package the template in a managed
442-
package.
445+
Generate an agent template from an existing agent in your DX project so you can then package the template in a
446+
second-generation managed package.
447+
448+
WARNING: This command doesn't work for agents that were created from an Agent Script file. In other words, you can't
449+
currently package an agent template for agents that use Agent Script.
443450
444451
At a high-level, agents are defined by the Bot, BotVersion, and GenAiPlannerBundle metadata types. The
445452
GenAiPlannerBundle type in turn defines the agent's topics and actions. This command uses the metadata files for these
446-
three types, located in your local DX project, to generate a BotTemplate file for a specific agent (Bot). You then use
447-
the BotTemplate file, along with the GenAiPlannerBundle file that references the BotTemplate, to package the template
448-
in a managed package that you can share between orgs or on AppExchange.
453+
three types, located in your local DX project, to generate a BotTemplate metadata file for a specific agent (Bot). You
454+
then use the BotTemplate metadata file, along with the GenAiPlannerBundle metadata file that references the
455+
BotTemplate, to package the template in a managed package that you can share between orgs or on AppExchange.
449456
450457
Use the --agent-file flag to specify the relative or full pathname of the Bot metadata file, such as
451458
force-app/main/default/bots/My_Awesome_Agent/My_Awesome_Agent.bot-meta.xml. A single Bot can have multiple
452-
BotVersions, so use the --agent-version flag to specify the version. The corresponding BotVersion file must exist
453-
locally. For example, if you specify "--agent-version 4", then the file
459+
BotVersions, so use the --agent-version flag to specify the version. The corresponding BotVersion metadata file must
460+
exist locally. For example, if you specify "--agent-version 4", then the file
454461
force-app/main/default/bots/My_Awesome_Agent/v4.botVersion-meta.xml must exist.
455462
456-
The new BotTemplate file is generated in the "botTemplates" directory in your local package directory, and has the
457-
name <Agent_API_name>_v<Version>_Template.botTemplate-meta.xml, such as
458-
force-app/main/default/botTemplates/My_Awesome_Agent_v4_Template.botTemplate-meta.xml. The command displays the full
459-
pathname of the generated files when it completes.
463+
The new BotTemplate metadata file is generated in the "botTemplates" directory in the output directory specified with
464+
the --output-dir flag, and has the name <Agent_API_name>\_v<Version>\_Template.botTemplate-meta.xml, such as
465+
my-package/botTemplates/My_Awesome_Agent_v4_Template.botTemplate-meta.xml. The command displays the full pathname of
466+
the generated files when it completes.
467+
468+
See "Develop and Package Agent Templates Using Scratch Orgs"
469+
(https://developer.salesforce.com/docs/atlas.en-us.pkg2_dev.meta/pkg2_dev/dev2gp_package_agent_templates.htm) for
470+
details about the complete process, which includes using a scratch org to create and test the agent, retrieving the
471+
agent metadata to your DX project, running this command to create the agent template, and then packaging the template.
460472
461473
EXAMPLES
462-
Generate an agent template from a Bot metadata file in your DX project that corresponds to the My_Awesome_Agent
463-
agent; use version 1 of the agent.
474+
Generate an agent template from the My_Awesome_Agent Bot metadata file in your DX project and save the BotTemplate
475+
and GenAiPlannerBundle to the specified directory; use version 1 of the agent:
464476
465477
$ sf agent generate template --agent-file \
466-
force-app/main/default/bots/My_Awesome_Agent/My_Awesome_Agent.bot-meta.xml --agent-version 1
478+
force-app/main/default/bots/My_Awesome_Agent/My_Awesome_Agent.bot-meta.xml --agent-version 1 --output-dir \
479+
my-package --source-org my-scratch-org
467480
```
468481

469482
_See code: [src/commands/agent/generate/template.ts](https://github.com/salesforcecli/plugin-agent/blob/1.32.10/src/commands/agent/generate/template.ts)_

command-snapshot.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@
7474
"alias": [],
7575
"command": "agent:generate:template",
7676
"flagAliases": [],
77-
"flagChars": ["f"],
78-
"flags": ["agent-file", "agent-version", "api-version", "flags-dir", "json"],
77+
"flagChars": ["f", "r", "s"],
78+
"flags": ["agent-file", "agent-version", "api-version", "flags-dir", "json", "output-dir", "source-org"],
7979
"plugin": "@salesforce/plugin-agent"
8080
},
8181
{
Lines changed: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
# summary
22

3-
Generate an agent template from an existing agent in your DX project so you can then package the template in a managed package.
3+
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.
44

55
# description
66

7-
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 file for a specific agent (Bot). You then use the BotTemplate file, along with the GenAiPlannerBundle file that references the BotTemplate, to package the template in a managed package that you can share between orgs or on AppExchange.
7+
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.
88

9-
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 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.
9+
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.
1010

11-
The new BotTemplate file is generated in the "botTemplates" directory in your local package directory, and has the name <Agent_API_name>_v<Version>_Template.botTemplate-meta.xml, such as force-app/main/default/botTemplates/My_Awesome_Agent_v4_Template.botTemplate-meta.xml. The command displays the full pathname of the generated files when it completes.
11+
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.
12+
13+
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.
14+
15+
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.
1216

1317
# examples
1418

15-
- Generate an agent template from a Bot metadata file in your DX project that corresponds to the My_Awesome_Agent agent; use version 1 of the agent.
19+
- 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":
1620

17-
<%= config.bin %> <%= command.id %> --agent-file force-app/main/default/bots/My_Awesome_Agent/My_Awesome_Agent.bot-meta.xml --agent-version 1
21+
<%= config.bin %> <%= command.id %> --agent-file force-app/main/default/bots/My_Awesome_Agent/My_Awesome_Agent.bot-meta.xml --agent-version 1 --output-dir my-package --source-org my-scratch-org
1822

1923
# flags.agent-version.summary
2024

@@ -24,22 +28,59 @@ Version of the agent (BotVersion).
2428

2529
Path to an agent (Bot) metadata file.
2630

31+
# flags.output-dir.summary
32+
33+
Directory where the generated BotTemplate and GenAiPlannerBundle files are saved.
34+
35+
# flags.source-org.summary
36+
37+
Username or alias of the namespaced scratch org that contains the agent which this template is based on.
38+
2739
# error.invalid-agent-file
2840

29-
Invalid Agent file. Must be a Bot metadata file. Example: force-app/main/default/bots/MyBot/MyBot.bot-meta.xml
41+
Invalid Agent file. Must be a Bot metadata file. Example: force-app/main/default/bots/MyBot/MyBot.bot-meta.xml.
3042

3143
# error.no-entry-dialog
3244

33-
No entryDialog found in BotVersion file.
45+
No entryDialog found in the BotVersion metadata file.
3446

3547
# error.invalid-bot-type
3648

3749
The 'type' attribute of this Bot metadata component XML file can't have a value of 'Bot', which indicates that it's an Einstein Bot and not an agent: %s.
3850

3951
# error.no-label
4052

41-
No label found in Agent (Bot) file: %s.
53+
No label found in Agent (Bot) metadata file: %s.
4254

4355
# error.no-ml-domain
4456

4557
No botMlDomain found in Agent (Bot) file: %s.
58+
59+
# error.local-topics-without-source
60+
61+
The local topic (genAiPlugin) you're trying to include in the agent template doesn't have a reference to a global topic. All topics in the agent template must be global assets defined in the Agent Asset Library in the source org that contains the agent that the template is based on.
62+
%s.
63+
64+
# error.local-actions-without-source
65+
66+
The local action (genAiFunction) you're trying to include in the agent template doesn't have a reference to a global action. All actions in the agent template must be global assets defined in the Agent Asset Library in the source org that contains the agent that the template is based on.
67+
%s.
68+
69+
# warn.reference-asset-from-managed-package
70+
71+
The local asset (genAiPlugin or genAiFunction) that you're including in the agent template references an asset from a managed package. Make sure that the managed package is defined as a dependency in the sfdx-project.json file:
72+
%s.
73+
74+
# error.global-asset-not-found
75+
76+
The following assets (genAiPlugin or genAiFunction) that you're including in the agent template reference an asset that isn't in the source org:
77+
%s.
78+
79+
# error.nga-agent-not-supported
80+
81+
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.
82+
83+
# warn.copied-asset-directories
84+
85+
The following directories have been copied to the target path. Review their contents and remove any unnecessary assets:
86+
%s.

0 commit comments

Comments
 (0)