Connecting Agentforce to Data Cloud for Grounding with RAG — How to Build Custom Retrievers & Agents

Learn how to create a custom retriever in Einstein Studio, test prompt templates for retrieval, and connect the retriever to an Agentforce Service Agent so your LLM responses are grounded in web-crawled knowledge.

Overview

What this guide covers: This article walks through creating a custom retriever in Einstein Studio, configuring prompt templates in Prompt Builder, and connecting the retriever to an Agentforce Service Agent. By the end, you’ll understand how to reliably surface FAQ content (Chunk__c) from a Data Cloud search index and use it to ground responses with RAG.

Why use a custom retriever?

A retriever returns relevant content chunks from a knowledge source to augment a Large Language Model (LLM) prompt. Using a custom retriever lets you precisely control which fields and records are returned — critical when you need your agent to answer from specific FAQ content rather than generic web knowledge.

Create a custom retriever in Einstein Studio

Follow these steps to create and configure a retriever that returns the Chunk__c field (the actual FAQ text):

  • Navigate to Data Cloud → Einstein Studio → Retrievers → New Retriever and choose Individual Retriever.
  • Select a retriever type: Data Space, Data Model Object (DMO), or Search Index. For web-crawled FAQ content, target the Search Index for your FAQ DMO.
  • Configure return fields — at minimum select Chunk__c. Optionally include SourceRecordId__c and DataSource__c for citations and debugging.
  • Save and activate the retriever in Einstein Studio.

Configure retriever filters and results

Defaults are usually fine, but keep these suggestions in mind:

  • Set result count to a balanced number (20 is a good default) to provide enough context without overwhelming the LLM.
  • Use dynamic field filters sparingly — they add flexibility but may impact retriever limits.

Build and test a prompt template in Prompt Builder

Testing at the prompt template level gives you direct control and visibility into what the retriever returns. Steps to validate the retriever:

  • Open Prompt Builder → Answer Questions with Knowledge.
  • Remove the default dynamic retriever resource ({!$EinsteinSearch:sfdc_ai__DynamicRetriever.results}) from the Knowledge section for testing.
  • Insert your custom retriever as the Search resource and set the Search Text to Free Text → Query.
  • As Output Fields, select Chunk__c only.
  • Save a new version, activate it, and use the preview to test queries — populate the Retriever ID (from Einstein Studio) in the preview to see real retrieval results.
  • Experiment with different LLM models, languages, and prompts to ensure grounded answers.

Configure Agentforce Service Agent

Once confident with the retriever and prompt template, create an Agentforce agent that uses your custom data library:

  • Navigate to Setup → Agentforce → Agentforce Agents → New Agent and choose Agentforce Service Agent.
  • Choose the relevant topics (for example, General FAQ).
  • Under Data Library, create a new library and select Custom Retriever, then link to your SF Foundations FAQ retriever.
  • Save the agent and run queries to validate responses.

Best practices and troubleshooting

  • Always test retrieval at the prompt template level before attaching to an agent — it’s faster to iterate and debug.
  • Return only the fields the LLM needs (Chunk__c) to avoid noisy or irrelevant context.
  • Use SourceRecordId__c for traceable citations when necessary.
  • Monitor retriever limits on your Data Cloud instance and apply filters wisely.

Key takeaways

  • Custom retrievers give precise control over which knowledge chunks are returned to the LLM.
  • Prompt Builder is a powerful place to validate retrieval and adjust prompt instructions.
  • Connecting a custom retriever to an Agentforce Service Agent via a custom data library enables grounded, reliable answers based on web-crawled FAQs.

Conclusion: Why this matters

Grounding LLM responses with Data Cloud and Agentforce reduces hallucination risk and makes agents trustworthy sources of company knowledge. Salesforce admins and developers can use retrievers to deliver more accurate support experiences, streamline knowledge delivery, and maintain traceable citations for compliance and auditing.

For implementers, this approach is applicable across service portals, internal knowledge-bases, and customer support bots where accurate, auditable responses are required.