@salesforce/plugin-agent 1.10.0 → 1.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,95 @@
1
+ /*
2
+ * Copyright (c) 2024, salesforce.com, inc.
3
+ * All rights reserved.
4
+ * Licensed under the BSD 3-Clause license.
5
+ * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
6
+ */
7
+ import { join } from 'node:path';
8
+ import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
9
+ import { Lifecycle, Messages } from '@salesforce/core';
10
+ import { AgentTester, AgentTestCreateLifecycleStages } from '@salesforce/agents';
11
+ import { MultiStageOutput } from '@oclif/multi-stage-output';
12
+ Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
13
+ const messages = Messages.loadMessages('@salesforce/plugin-agent', 'agent.test.create');
14
+ export default class AgentTestCreate extends SfCommand {
15
+ static summary = messages.getMessage('summary');
16
+ static description = messages.getMessage('description');
17
+ static examples = messages.getMessages('examples');
18
+ static state = 'beta';
19
+ static flags = {
20
+ spec: Flags.file({
21
+ summary: messages.getMessage('flags.spec.summary'),
22
+ description: messages.getMessage('flags.spec.description'),
23
+ char: 's',
24
+ required: true,
25
+ exists: true,
26
+ }),
27
+ 'target-org': Flags.requiredOrg(),
28
+ 'api-version': Flags.orgApiVersion(),
29
+ preview: Flags.boolean({
30
+ summary: messages.getMessage('flags.preview.summary'),
31
+ }),
32
+ 'no-prompt': Flags.boolean({
33
+ summary: messages.getMessage('flags.no-prompt.summary'),
34
+ char: 'p',
35
+ }),
36
+ };
37
+ mso;
38
+ async run() {
39
+ const { flags } = await this.parse(AgentTestCreate);
40
+ const agentTester = new AgentTester(flags['target-org'].getConnection(flags['api-version']));
41
+ const lifecycle = Lifecycle.getInstance();
42
+ lifecycle.on(AgentTestCreateLifecycleStages.CreatingLocalMetadata, async () => {
43
+ this.mso = new MultiStageOutput({
44
+ jsonEnabled: this.jsonEnabled(),
45
+ stages: Object.values(AgentTestCreateLifecycleStages),
46
+ title: `Creating test for ${flags.spec}`,
47
+ });
48
+ this.mso?.skipTo(AgentTestCreateLifecycleStages.CreatingLocalMetadata);
49
+ return Promise.resolve();
50
+ });
51
+ lifecycle.on(AgentTestCreateLifecycleStages.DeployingMetadata, async () => Promise.resolve(this.mso?.skipTo(AgentTestCreateLifecycleStages.DeployingMetadata)));
52
+ lifecycle.on(AgentTestCreateLifecycleStages.Waiting, async () => Promise.resolve(this.mso?.skipTo(AgentTestCreateLifecycleStages.Waiting)));
53
+ lifecycle.on(AgentTestCreateLifecycleStages.Done, async (result) => {
54
+ if (result.response.success) {
55
+ this.mso?.skipTo(AgentTestCreateLifecycleStages.Done);
56
+ this.mso?.stop();
57
+ }
58
+ else {
59
+ this.mso?.error();
60
+ this.mso?.stop();
61
+ }
62
+ return Promise.resolve();
63
+ });
64
+ const confirmationCallback = flags['no-prompt']
65
+ ? async () => Promise.resolve(true)
66
+ : async (spec) => this.confirm({
67
+ message: `An AiEvaluationDefinition with the name ${spec.name} already exists in the org. Do you want to overwrite it?`,
68
+ defaultAnswer: false,
69
+ });
70
+ const { path, contents } = await agentTester.create(flags.spec, {
71
+ outputDir: join('force-app', 'main', 'default', 'aiEvaluationDefinitions'),
72
+ preview: flags.preview,
73
+ confirmationCallback,
74
+ });
75
+ if (flags.preview) {
76
+ this.mso?.skipTo(AgentTestCreateLifecycleStages.Done);
77
+ this.mso?.stop();
78
+ this.log(`Preview of AiEvaluationDefinition created at ${path}`);
79
+ this.log();
80
+ this.log(contents);
81
+ }
82
+ else {
83
+ this.log(`AiEvaluationDefinition created at ${path} and deployed to ${flags['target-org'].getUsername() ?? flags['target-org'].getOrgId()}`);
84
+ }
85
+ return {
86
+ path,
87
+ contents,
88
+ };
89
+ }
90
+ catch(error) {
91
+ this.mso?.error();
92
+ return super.catch(error);
93
+ }
94
+ }
95
+ //# sourceMappingURL=create.js.map
@@ -0,0 +1 @@
1
+ {"version":3,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,EAAE,MAAM,CAAC,8BAA8B,CAAC,IAAI,CAAC,CAAC;YACtD,IAAI,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC;YACjB,IAAI,CAAC,GAAG,CAAC,gDAAgD,IAAI,EAAE,CAAC,CAAC;YACjE,IAAI,CAAC,GAAG,EAAE,CAAC;YACX,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QACrB,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,GAAG,CACN,qCAAqC,IAAI,oBACvC,KAAK,CAAC,YAAY,CAAC,CAAC,WAAW,EAAE,IAAI,KAAK,CAAC,YAAY,CAAC,CAAC,QAAQ,EACnE,EAAE,CACH,CAAC;QACJ,CAAC;QAED,OAAO;YACL,IAAI;YACJ,QAAQ;SACT,CAAC;IACJ,CAAC;IAES,KAAK,CAAC,KAAiC;QAC/C,IAAI,CAAC,GAAG,EAAE,KAAK,EAAE,CAAC;QAClB,OAAO,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAC5B,CAAC"}
@@ -1,12 +1,14 @@
1
1
  # summary
2
2
 
3
- Create an agent in your org from a local agent spec file.
3
+ Create an agent in your org using a local agent spec file.
4
4
 
5
5
  # description
6
6
 
7
- To generate an agent spec file, run the "agent generate spec" CLI command, which outputs a YAML file with the list of jobs and descriptions that the new agent can perform. Then specify this generated spec file to the --spec flag of this command, along with the name of the new agent.
7
+ Before you run this command, you must first generate an agent spec file by running the "agent generate spec" CLI command, which outputs a YAML file with the agent properties and list of AI-generated topics. Topics define the range of jobs the agent can handle. Then specify the generated agent spec file to this command using the --spec flag, along with the name (label) of the new agent using the --agent-name flag.
8
8
 
9
- When this command finishes, your org contains the new agent, which you can then edit in the Agent Builder UI. The new agent already has a list of topics and actions that were automatically created from the list of jobs in the provided agent spec file. This command also retrieves all the metadata files associated with the new agent to your local DX project.
9
+ When this command finishes, your org contains the new agent, which you can then edit in the Agent Builder UI. The new agent's topics are the same as the ones listed in the agent spec file. The agent might also have some AI-generated actions. This command also retrieves all the metadata files associated with the new agent to your local Salesforce DX project.
10
+
11
+ Use the --preview flag to review what the agent looks like without actually saving it in your org. Rather, the command creates a JSON file with all the agent details in the current directory.
10
12
 
11
13
  To open the new agent in your org's Agent Builder UI, run this command: "sf org open agent --name <api-name-of-your-agent>".
12
14
 
@@ -16,27 +18,27 @@ Path to an agent spec file.
16
18
 
17
19
  # flags.preview.summary
18
20
 
19
- Preview the agent without saving in your org.
21
+ Preview the agent without saving it in your org.
20
22
 
21
23
  # flags.agent-name.summary
22
24
 
23
- Name for the new agent.
25
+ Name (label) of the new agent.
24
26
 
25
27
  # flags.agent-api-name.summary
26
28
 
27
- API name for the new agent.
29
+ API name of the new agent; if not specified, the API name is derived from the agent name (label); the API name must not exist in the org.
28
30
 
29
31
  # flags.user-id.summary
30
32
 
31
- Custom user ID for the agent.
33
+ ID of a user in your org that is assigned to your agent; determines what your agent can access and do.
32
34
 
33
35
  # flags.enrich-logs.summary
34
36
 
35
- Adds agent conversation data to event logs.
37
+ Adds agent conversation data to event logs so you can view all agent session activity in one place.
36
38
 
37
39
  # flags.tone.summary
38
40
 
39
- Conversational style of agent responses.
41
+ Conversational style of the agent, such as how it expresses your brand personality in its messages through word choice, punctuation, and sentence structure.
40
42
 
41
43
  # flags.primary-language.summary
42
44
 
@@ -52,6 +54,10 @@ Missing required flags: %s
52
54
 
53
55
  # examples
54
56
 
55
- - Create an agent called "CustomerSupportAgent" in an org with alias "my-org" using the specified agent spec file:
57
+ - Create an agent called "ResortManager" in an org with alias "my-org" using the specified agent spec file:
58
+
59
+ <%= config.bin %> <%= command.id %> --agent-name ResortManager --spec specs/resortManagerAgent.yaml --target-org my-org
60
+
61
+ - Preview the creation of an agent called "ResortManager" and use your default org:
56
62
 
57
- <%= config.bin %> <%= command.id %> --name CustomerSupportAgent --spec ./config/agentSpec.json --target-org my-org
63
+ <%= config.bin %> <%= command.id %> --agent-name ResortManager --spec specs/resortManagerAgent.yaml --preview
@@ -1,44 +1,52 @@
1
1
  # summary
2
2
 
3
- Generate an agent spec, which is the list of jobs that the agent performs.
3
+ Generate an agent spec, which is a YAML file that captures what an agent can do.
4
4
 
5
5
  # description
6
6
 
7
- When using Salesforce CLI to create an agent in your org, you can choose to generate a YAML-formatted agent spec file with this command as a first step.
7
+ Before you use Salesforce CLI to create an agent in your org, you must first generate an agent spec with this command. An agent spec is a YAML-formatted file that contains information about the agent, such as its role and company description, and then an AI-generated list of topics based on this information. Topics define the range of jobs your agent can handle.
8
8
 
9
- An agent spec is a list of jobs and descriptions that capture what the agent can do. Use flags such as --role and --company-description to provide details about your company and the role that the agent plays in your company; you can also enter the information interactively if you prefer. When you then execute this command, the large language model (LLM) associated with your org uses the information to generate the list of jobs that the agent most likely performs. We recommend that you provide good details for --role, --company-description, etc, so that the LLM can generate the best and most relevant list of jobs and descriptions. Once generated, you can edit the spec file; for example, you can remove jobs that don't apply to your agent.
9
+ Use flags, such as --role and --company-description, to provide details about your company and the role that the agent plays in your company. If you prefer, you can also be prompted for the information. Upon command execution, the large language model (LLM) associated with your org uses the information you provided to generate a list of topics for the agent. Because the LLM uses the company and role information to generate the topics, we recommend that you provide accurate and specific details so the LLM generates the best and most relevant topics. Once generated, you can edit the spec file; for example, you can remove topics that don't apply to your agent or change the description of a particular topic.
10
10
 
11
- When your agent spec is ready, you then create the agent in your org by specifying the agent spec file to the --job-spec flag of the "agent create" CLI command.
11
+ You can iterate the spec generation process by using the --spec flag to pass an existing agent spec file to this command, and then using the --role, --company-description, etc, flags to refine your agent properties. Iteratively improving the description of your agent allows the LLM to generate progressively better topics.
12
+
13
+ You can also specify a custom prompt template that the agent uses, and ground the prompt template to add context and personalization to the agent's prompts.
14
+
15
+ When your agent spec is ready, you then create the agent in your org by running the "agent create" CLI command and specifying the spec with the --spec flag.
12
16
 
13
17
  # flags.output-file.summary
14
18
 
15
- Path for the generated agent spec file (yaml); can be an absolute or relative path.
19
+ Path for the generated YAML agent spec file; can be an absolute or relative path.
16
20
 
17
21
  # flags.max-topics.summary
18
22
 
19
- Maximum number of agent job topics to generate in the spec; default is 10.
23
+ Maximum number of topics to generate in the agent spec; default is 10.
20
24
 
21
25
  # flags.prompt-template.summary
22
26
 
23
- Developer name of a customized prompt template to use instead of the default.
27
+ API name of a customized prompt template to use instead of the default prompt template.
24
28
 
25
29
  # flags.grounding-context.summary
26
30
 
27
- Context information to be used with the customized prompt template.
31
+ Context information and personalization that's added to your prompts when using a custom prompt template.
28
32
 
29
33
  # flags.spec.summary
30
34
 
31
- Spec file (yaml) to use as input to the command.
35
+ Agent spec file, in YAML format, to use as input to the command.
32
36
 
33
37
  # examples
34
38
 
35
- - Create an agent spec for your default org in the default location and use flags to specify the agent's role and your company details:
39
+ - Generate an agent spec in the default location and use flags to specify the agent properties, such as its role and your company details; use your default org:
40
+
41
+ <%= config.bin %> <%= command.id %> --type customer --role "Field customer complaints and manage employee schedules." --company-name "Coral Cloud Resorts" --company-description "Provide customers with exceptional destination activities, unforgettable experiences, and reservation services."
42
+
43
+ - Generate an agent spec by being prompted for the required agent properties and generate a maxiumum of 5 topics; write the generated file to the "specs/resortManagerSpec.yaml" file and use the org with alias "my-org":
36
44
 
37
- <%= config.bin %> <%= command.id %> --type customer --role "Assist users in navigating and managing bookings" --company-name "Coral Cloud" --company-description "Resort that manages guests and their reservations and experiences"
45
+ <%= config.bin %> <%= command.id %> --max-topics 5 --output-file specs/resortManagerAgent.yaml --target-org my-org
38
46
 
39
- - Create an agent spec by being prompted for role and company details interactively; write the generated file to the "specs" directory and use the org with alias "my-org":
47
+ - Specify an existing agent spec file called "specs/resortManagerAgent.yaml", and then overwrite it with a new version that contains newly AI-generated topics based on the updated role information passed in with the --role flag:
40
48
 
41
- <%= config.bin %> <%= command.id %> --output-dir specs --target-org my-org
49
+ <%= config.bin %> <%= command.id %> --spec specs/resortManagerAgent.yaml --output-file specs/resortManagerAgent.yaml --role "Field customer complaints, manage employee schedules, and ensure all resort operations are running smoothly" --target-org my-org
42
50
 
43
51
  # error.missingRequiredFlags
44
52
 
@@ -0,0 +1,11 @@
1
+ # summary
2
+
3
+ Interactively generate a specification file for a AI evaluation test.
4
+
5
+ # description
6
+
7
+ This command will prompt you for the necessary information to create a new spec file (in yaml format). You can then create a new AI evaluation using "sf agent test create --spec <spec-file>".
8
+
9
+ # examples
10
+
11
+ - <%= config.bin %> <%= command.id %>
@@ -0,0 +1,27 @@
1
+ # summary
2
+
3
+ Summary of a command.
4
+
5
+ # description
6
+
7
+ More information about a command. Don't repeat the summary.
8
+
9
+ # flags.spec.summary
10
+
11
+ Description of a flag.
12
+
13
+ # flags.spec.description
14
+
15
+ More information about a flag. Don't repeat the summary.
16
+
17
+ # flags.preview.summary
18
+
19
+ Preview the test metadata without deploying to your org.
20
+
21
+ # flags.no-prompt.summary
22
+
23
+ Don't prompt for confirmation when overwriting an existing test.
24
+
25
+ # examples
26
+
27
+ - <%= config.bin %> <%= command.id %>