---
schema_version: "1"
id: 0345299da786b4af62c3b95b3b100730dd4f2eea0bff1272ab7bce1c146619fc
title: "Step 5: Implement the Prompt Template in Your Agent"
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/data-ae/ground-agentforce-on-website/guides/aes-implement-prompt-template-in-agent.md
canonical_url: https://developer.salesforce.com/docs/ai/ground-agentforce-on-website/guide/aes-implement-prompt-template-in-agent.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 186b4bc95dd3a432e139e828901f81ba7474c7f2db720272bfc410ae060dd5b1
products:
  - Ground Agentforce on Your Own Website
  - data-ae
---
# 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.

## Prepare Action and Subagent Key Definitions

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](https://help.salesforce.com/s/articleView?id=ai.agent_plan_action_identify.htm&type=5).
- Learn more about [the subagent's different parts](https://help.salesforce.com/s/articleView?language=en_US&id=ai.copilot_topics.htm&type=5).

**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.

### Example

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 Agent Action from Prompt Template

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.

### Create a New Action

1. Go to **Setup**.
2. In the quick search box, find and select **Agentforce Assets**.
3. In **Agentforce Assets**, go to the **Actions** tab, and then click **+New Agent Action**.
4. On **Create an Agent Action**, for **Reference Action Type**, enter **Prompt Template**.
5. For **Reference Action**, select the prompt template that you created in [Step 4: Build and Test a Prompt in Prompt Builder](https://developer.salesforce.com/docs/ai/ground-agentforce-on-website/guide/aes-create-prompt.md).
6. Enter **Agent Action Label** and **Agent Action API Name**.
7. Click **Next**.

### Configure the Action

Under **Agent Action Configuration**, enter the key information that you prepared in advance, and complete the other fields.

1. **Agent Action Description**: Enter the subagent action description that you prepared in advance.
2. **Loading Text**: Enter the message shown to users while the agent is generating answers. For example: `Thinking…`.
3. **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**.
   - 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**.
4. **Outputs**: Under **Prompt Response**, select **Show in conversation**.
5. Click **Finish** to save your action configurations.

### 3. Create a New Subagent

Define a subagent and assign your action to it.

1. In **Agentforce Studio**, go to the **Subagents** tab, and then click **+New Subagent**.
2. Enter a **Name** and **API Name** that describe what the agent does in plain language. For example: `Answer questions with knowledge from solar site`.
3. **Classification Description**: Enter the Subagent Classification Description that you prepared in advance.
4. **Scope**, enter the subagent scope you prepared in advance.
5. **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](https://developer.salesforce.com/docs/ai/ground-agentforce-on-website/guide/aes-create-prompt.md). Learn [best practices for subagent instructions](https://help.salesforce.com/s/articleView?id=ai.copilot_topics_instructions.htm&type=5).
6. Click **Next**.
7. 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](https://help.salesforce.com/s/articleView?language=en_US&id=ai.agent_actions_add_asset_library.htm&type=5).
8. Click **Finish** to save your changes.

### 4. Assign the Subagent and Action to Your Agent

Now that you have a subagent and action, assign them to your agent to allow it to use them when called.

1. From the **App Launcher**, find and select **Agentforce Studio**. Can't access Agentforce Studio? See [permission issues and troubleshooting](https://help.salesforce.com/s/articleView?language=en_US&id=ai.agent_builder_studio.htm&type=5).
2. From your **Agents** list, open an agent of your choice. Don't have an agent? Follow the steps in the tip.
3. On the left, hover over **Subagents** and click the **+** button.
4. Select **Add from Asset Library**.
5. Find the tile for the subagent you created. You can click **Details** to make sure it's assigned with the action you created.
6. Click **Select** and then **Add to Agent**.

**tip:** **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](https://help.salesforce.com/s/articleView?id=sf.bots_service_intro.htm&type=5).
- Learn more about [agent types and considerations](https://help.salesforce.com/s/articleView?id=sf.agentforce_agent_types.htm&type=5).

1. From the **App Launcher**, find and select the **Agentforce Studio** app.
2. On the **Agents** tab, click **New Agent**.
3. Select the **Agentforce Service** agent template.
4. 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](https://help.salesforce.com/s/articleView?id=sf.bots_service_user_best_practices.htm&type=5).
5. Enter the agent's name and then click **Let's Go**.
6. In the **Agent Definition** section, go to the menu on the left, hover over **Subagents**, and then click the **+** button.
7. Select **Add from Asset Library**.
8. Find the tile for the subagent you created. You can click **Details** to confirm that it's assigned with the action you created.
9. Click **Select** and then **Add to Agent**.

### 5. Test and Troubleshoot the 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](https://help.salesforce.com/s/articleView?id=ai.agent_parent_test.htm&type=5).

1. In **Agentforce Builder**, click **Preview** on the top left.
2. In the test panel, enter a query that your agent can handle.
3. 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.
