---
schema_version: "1"
id: efc429eaa8519aaadf249bc11bb583ffc6f1256ca551e857111d303ffb0d3360
title: "Step 3: Build Agentforce Agent"
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/data-ae/power-agentforce-visual-data/guides/aes-build-agent-visual-data.md
canonical_url: https://developer.salesforce.com/docs/ai/power-agentforce-visual-data/guide/aes-build-agent-visual-data.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 46a06c42d3d0bd181f9c624d61f6cb5914df82b4361ea32a9e8f4567501916e6
products:
  - Power Agentforce with Complex Visual Data
  - data-ae
---
# Step 3: Build Agentforce Agent

Now that you have the Agentforce Data Library set up and your individual retriever configured in Intelligent Context, it's time to build an Agentforce agent that answers user questions based on your visual data.

This guide shows how to set up an employee agent that uses the unstructured data files and retriever configurations you created in the previous steps. While this example focuses on an employee agent, you can apply the same approach to other agent types, such as service agents for customer-facing scenarios. See more examples in [Retail Solution Powered by Data 360 – DIY Store Front](https://github.com/salesforce-misc/Data360AgentforceSolutionKitRetail).

## 1. Build and Test a Prompt in Prompt Builder

Prepare a prompt for the agent to define how it behaves, what sources it uses, how it responds when information is missing, and how it formats the final answer.

### Prompt Parts

Include these two parts in your prompt:

1. Instructions and guidance for the LLM.
2. Two parameters to allow the model to generate answers based on your indexed content and not on general model knowledge.

- **Question**: The question coming from the user through the agent, a free-text input that receives the user's question from the agent.
- **Retriever**: The content the retriever returns from the search index. This retriever output passes the relevant chunks and metadata from the search index into the prompt.

### Prompt Considerations

As you build your prompt, consider the following.

- Be explicit about what sources the model is allowed to use.
- Clearly define what should happen when the retriever doesn't return a good answer.
- Specify whether the answer should include citations or source URLs.
- Tailor the formatting to the expected end-user experience.
- Keep the instructions focused on the actual role of the agent.

#### Prompt Example

```text
Objective: You are an AI expert. When a customer asks questions related to building a deck, provide a helpful answer.

Prompt Rules:
1. Begin the response with exactly one catchy, customer-friendly paragraph that are directly related to the customer's specific deck-building question.
   - The paragraph must clearly reference the topic of the question and the tone should be enthusiastic and encouraging, as if guiding the customer through their project and display exactly 10 lines.
   - Do not shorten, merge, or combine lines.
2. Display all the information in the response.
3. Display all the installation steps exactly. Do not change the wording, and do not skip any step for each category.
4. Do NOT mix content from different items.
5. Your tone should be friendly and informative, as if speaking directly to the customer.
6. Ensure that your response is relevant to the specific question asked.
7. Do NOT add any extra words, explanations, summaries, or commentary beyond the retrieved content.
8. Do NOT use JSON. Use plain text only.

Question:{!$Input:Question}
You can use following information to answer:{!$EinsteinSearch:Building_a_Deck_Retriever_1Cx_96bc9aaf8da.results}
```

## 2. Build the Prompt Template

The prompt template defines how the agent uses the retrieved data to answer a user. After you configure the prompt, it follows this work process.

- The user's question is passed into the prompt through Query.
- The same question is used as the retriever's search text.
- The retriever returns the most relevant results from the indexed website content.
- These results are passed into the prompt as Knowledge Base Information.
- The LLM uses both the question and the retrieved content to generate a grounded answer. It keeps the response tied to your indexed website content instead of relying on general model knowledge.

To build the prompt template:

1. From the Data 360 app, find and select **Agentforce Studio** on the quick search bar.
2. From the menu in the left, select **Prompt Template**.
3. Click **New Prompt Template**.
4. Select the **Flex** template type.
5. Name the template and define the **Input**:
   - Create an input named **User Query**.
   - Set Type to **Free Text**.
   - Click **Next**.
6. In the Prompt Editor, paste your main prompt instructions into the prompt body.
7. Insert the Query and Retriever parameters to the bottom of the prompt:
   - To add the query parameter, click **Insert Resource** and select **User Query**.
   - To add the individual retriever you created, click **Insert Resource**, then click **Retrievers** and then **Configure Retrievers**.
8. Configure the Retriever within the prompt:
   - On the **Resources** tab on the left, select your individual retriever from the list, for example: **ADL_deck Retriever**.
   - Scroll down to **Search Parameters**.
   - Under **Search Text**, search and enter **User Query**.
   - Select the DMO output fields: **Chunk**.
   - Click **Apply and Insert**, and then **Save and Preview**.
9. To test your prompt, click the **Preview Settings** icon on the left menu, and enter a sample user question under **User Query**.
10. Validate that these results are taking place.
    - The retriever returns relevant results.
    - The answer is grounded in the indexed content.
    - The response format follows your instructions.
    - Fallback behavior works when no relevant content is found.

If the results are weak, refine the prompt wording, retriever configuration, or indexing approach before you activate your agent.

## 3. 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 2: Build the Prompt Agent.
6. Enter **Agent Action Label** and **Agent Action API Name**.
7. Click **Next**.

### Configure the Action

Under **Agent Action Configuration**, enter the key information to configure the action.

1. **Agent Action Description**: Describe what the action does and when it's used. For example: `Execute when a customer asks a question related to building a deck, and display exact prompt response`.
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**.
4. **Outputs**: Under **Prompt Response**, select **Show in conversation**.
5. Click **Finish** to save your action configurations.

### 4. 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 Building a Deck Project Installation Instructions`.
3. **Classification Description**: Describe what the subagent does and the types of user requests that should be classified into this subagent. This describes what user messages should trigger this subagent. For example, `Handle customer queries related to how to build a deck and provide the information about it`.
4. **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. For example, `Your job is only to assist customers with queries related to building a deck and perform the associated action and display the response. You should not handle unrelated topics or provide information outside of DIY Projects`.
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, `If customer asks building a deck queries, then run the action 'Building Deck Prompt' and display exact prompt response`. 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 the action that you created 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.

## 5. Create an Employee Agent

Now that you have a subagent and action that are grounded on your prompt and individual retriever, assign them to your agent to allow it to use them when called. This example is of an employee agent, but the basic process is the same for other types of agents.

- Learn more about [creating an agent from an Agentforce employee agent template](https://help.salesforce.com/s/articleView?id=ai.agent_employee_agent_setup.htm&type=5).
- Learn more about [agent types and considerations](https://help.salesforce.com/s/articleView?id=ai.agent_setup_explore_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 an **Agentforce Employee** agent template. Enter the agent's name and then click **Let's Go**.
4. In the **Settings** section, define the settings that determine how your agent behaves in conversations, such as system messages and language settings.
5. On the left, hover over **Subagents** and click the **+** button.
6. Select **Add from Asset Library**.
7. Find the tile for the subagent you created. You can click **Details** to make sure it's assigned with the action you created.
8. Click **Select** and then **Add to Agent**.
9. In the **Data** section, select your Salesforce Data Library. The **Answer Questions with Knowledge** action grounds your agent's responses with it.
10. Test your agent. Enter queries the agent should handle on the **Preview** tab to confirm that it runs your prompt and returns answers that match the expected format and content. For more details about testing, see [Preview and Test in Agentforce Builder](https://help.salesforce.com/s/articleView?id=ai.agent_preview_and_test.htm&language=en_US&type=5).
11. To give your users access to your agent in Lightning Experience and mobile, see [Manage Employee Agent Access](https://help.salesforce.com/s/articleView?id=ai.agent_manage_aea_access.htm&type=5).
12. Optionally, connect your agent to [Enhanced Web Chat v1 or Slack](https://help.salesforce.com/s/articleView?id=ai.agent_deploy_enhanced_chat_v1.htm&type=5#connect_aea_v1).
13. When you're ready, [activate your agent](https://help.salesforce.com/s/articleView?id=ai.copilot_setup_activate_deactivate.htm&type=5).
