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.
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.
Include these two parts in your prompt:
- Instructions and guidance for the LLM.
- 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.
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.
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:
- From the Data 360 app, find and select Agentforce Studio on the quick search bar.
- From the menu in the left, select Prompt Template.
- Click New Prompt Template.
- Select the Flex template type.
- Name the template and define the Input:
- Create an input named User Query.
- Set Type to Free Text.
- Click Next.
- In the Prompt Editor, paste your main prompt instructions into the prompt body.
- 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.
- 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.
- To test your prompt, click the Preview Settings icon on the left menu, and enter a sample user question under User Query.
- 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.
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 2: Build the Prompt Agent.
- Enter Agent Action Label and Agent Action API Name.
- Click Next.
Under Agent Action Configuration, enter the key information to configure the action.
- 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. - 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 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 Building a Deck Project Installation Instructions. - 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. - 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. - 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. - Click Next.
- 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.
- Click Finish to save your changes.
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.
- 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 an Agentforce Employee agent template. Enter the agent’s name and then click Let’s Go.
- In the Settings section, define the settings that determine how your agent behaves in conversations, such as system messages and language settings.
- 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.
- In the Data section, select your Salesforce Data Library. The Answer Questions with Knowledge action grounds your agent’s responses with it.
- 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.
- To give your users access to your agent in Lightning Experience and mobile, see Manage Employee Agent Access.
- Optionally, connect your agent to Enhanced Web Chat v1 or Slack.
- When you’re ready, activate your agent.