Step 5: Implement the Prompt Template in Your Agent
Now that you have a tested prompt template, it’s time to implement it in your Agentforce agent to provide users with answers based on your custom data, including source citations for user trust. This workflow is bottom-up. First, create an action from the prompt template. Then, create a subagent. Lastly, assign the subagent and action to an agent. You can use an existing agent or build one that’s suited for your needs.
A subagent is a particular job that an agent can do and an essential element of an agent’s reasoning. A subagent contains actions, which are the tools available for the job, and instructions, which tell the agent how to make decisions. Collectively, the subagents assigned to your agent define the capabilities your agent can handle.
Identify your subagent and action, and then draft the information required for setup. Preparing these definitions in advance streamlines the configuration process and leads to better results.
- Learn more about identifying subagents and actions.
- Learn more about the subagent’s different parts.
Subagent Description: Describe what the subagent does overall.
Subagent Action Description: Describe what the specific action (task) does and when it’s used.
Subagent Classification Description: Describe what the subagent does and the types of user requests that are to be classified into this subagent. In other words, describe what user messages should trigger this subagent.
Subagent Scope: Define what the agent is allowed to do within a subagent context. The scope sets boundaries on the subagent’s capabilities and access to data or actions.
Cirrus plans its agent’s subagent and action. Their purpose is to get the subagent to answer questions about Cirrus products by using public product content from the Cirrus website.
Subagent Description: A support subagent for Cirrus Energy that answers questions about Cirrus renewable energy products by using public product content from the Cirrus website. The subagent helps users understand product categories, product differences, and key product details.
Agent Action Description: When the user asks about Cirrus Energy products, including solar panels, batteries, starter sets, or small turbines, this action retrieves information from the indexed Cirrus product pages and returns a grounded answer based on that content only.
Subagent Classification Description: Use this subagent when the user’s intent is to learn about Cirrus products, compare products, understand product specifications, or ask which Cirrus product fits a specific need. User questions include questions about products such as Professional Solar Panel 400W, Starter Set Pro, EcoWind Turbine 500W, batteries, and other products listed on the Cirrus website.
Subagent Scope: Use this subagent to answer questions about Cirrus product pages and product categories that exist on the public Cirrus website. The subagent can summarize product details, compare products, and answer questions grounded in the indexed product content. It can’t answer questions about order status, private account information, billing, or content that doesn’t exist in the connected Cirrus product pages.
Create an action from the prompt template that you created. Assign the action to a subagent, and then assign the subagent to your agent. This is a bottom-up approach, but you can use a top-down approach if it better suits your use case.
- Go to Setup.
- In the quick search box, find and select Agentforce Assets.
- In Agentforce Assets, go to the Actions tab, and then click +New Agent Action.
- On Create an Agent Action, for Reference Action Type, enter Prompt Template.
- For Reference Action, select the prompt template that you created in Step 4: Build and Test a Prompt in Prompt Builder.
- Enter Agent Action Label and Agent Action API Name.
- Click Next.
Under Agent Action Configuration, enter the key information that you prepared in advance, and complete the other fields.
- Agent Action Description: Enter the subagent action description that you prepared in advance.
- Loading Text: Enter the message shown to users while the agent is generating answers. For example:
Thinking…. - Inputs:
- Under Query:
- Description: Describe the context for this action, such as business-specific acronyms or process definitions. For example:
An AI-generated string to be used in the knowledge article search. - Select Collect data from user.
- Description: Describe the context for this action, such as business-specific acronyms or process definitions. For example:
- Under Citation Mode:
- Description: Tell the agent when to provide citations. For example:
Always use post generation. - Select Require input.
- Select Collect data from user.
- Description: Tell the agent when to provide citations. For example:
- Under Query:
- Outputs: Under Prompt Response, select Show in conversation.
- Click Finish to save your action configurations.
Define a subagent and assign your action to it.
- In Agentforce Studio, go to the Subagents tab, and then click +New Subagent.
- Enter a Name and API Name that describe what the agent does in plain language. For example:
Answer questions with knowledge from solar site. - Classification Description: Enter the Subagent Classification Description that you prepared in advance.
- Scope, enter the subagent scope you prepared in advance.
- Instructions: Add guidelines that tell your agent how to handle conversations in the context of the subagent, your business case, and the conversation in general. Each instruction is a single subagent-specific guideline. For example, see instructions listed under Prompt Example. Learn best practices for subagent instructions.
- Click Next.
- Before you create the subagent, select your action to include it in your subagent. Learn more about adding an action to a subagent from the asset library.
- Click Finish to save your changes.
Now that you have a subagent and action, assign them to your agent to allow it to use them when called.
- From the App Launcher, find and select Agentforce Studio. Can’t access Agentforce Studio? See permission issues and troubleshooting.
- From your Agents list, open an agent of your choice. Don’t have an agent? Follow the steps in the tip.
- On the left, hover over Subagents and click the + button.
- Select Add from Asset Library.
- Find the tile for the subagent you created. You can click Details to make sure it’s assigned with the action you created.
- Click Select and then Add to Agent.
How to Create an Agent
If you don’t have an agent yet, follow these instructions to create one. This example is of a service agent, but the basic process is the same for other types of agents.
- Learn more about creating an agent from an Agentforce service agent template.
- Learn more about agent types and considerations.
- From the App Launcher, find and select the Agentforce Studio app.
- On the Agents tab, click New Agent.
- Select the Agentforce Service agent template.
- Under Agent Details, select or create an Agent’s User Record for this agent. To securely access data and perform actions, Service agents operate as an agent user: a Salesforce integration user with all the permissions that the agent needs to do its job. See Best Practices for Agent User Permissions.
- Enter the agent’s name and then click Let’s Go.
- In the Agent Definition section, go to the menu on the left, hover over Subagents, and then click the + button.
- Select Add from Asset Library.
- Find the tile for the subagent you created. You can click Details to confirm that it’s assigned with the action you created.
- Click Select and then Add to Agent.
Now that you have an agent with a subagent and action to help it answer user questions and add citations, it’s time to test it to confirm that it delivers as expected.
Learn more about testing and troubleshooting your agent.
- In Agentforce Builder, click Preview on the top left.
- In the test panel, enter a query that your agent can handle.
- Review the agent’s response and confirm that the following is taking place.
- The prompt template action runs correctly.
- Citations appear in the response. Verify that source references appear correctly and link to the appropriate knowledge articles or web pages.
- The answer matches the expected format and content.
If citations don’t appear or appear incorrectly, review the citation configuration in your prompt template action and confirm that your development environment supports citation collection from prompt templates.
If the response doesn’t meet expectations, return to the action or subagent configuration and adjust the instructions or input requirements.