Sub topic 2
Where grounding fits in an Agentforce agent
This chapter shows where grounding happens inside an Agentforce agent. It assumes you know basic Salesforce administration, have seen Salesforce Knowledge articles, and have a general idea of what a large language model (LLM) is. It also assumes you know that Agentforce agents have topics and actions. The chapter does not build anything in Data Cloud yet. It sets up the model you need for the later chapters on retrievers, prompt templates, and knowledge actions.
The pieces of an agent
An Agentforce agent is made of a few parts. Each part has a different job in grounding.
- Topic: a group of related jobs the agent can handle, such as "Order questions" or "Product and policy questions". A topic has a classification description, a scope, and instructions.
- Instructions: natural-language rules attached to a topic. They tell the agent how to behave and when to use an action.
- Action: something the agent can do. An action can run a flow, call Apex, call a prompt template, or look up knowledge.
- Reasoning engine: the LLM-driven component that reads the customer message, picks a topic, and decides which action to run.
Grounding does not live in one of these parts. It is spread across them. The topic decides whether a knowledge lookup should happen. The action performs it. A prompt template or the action's own configuration tells the model how to use what came back.
Two ways to ground an answer
There are two common routes for supplying your content to the model.
- Through a prompt template. You build a template in Prompt Builder. It includes a retriever resource, which runs a search over a Data Cloud search index and inserts the matching chunks into the prompt. An agent action then calls that template.
- Through a knowledge action. The agent uses a built-in answer-questions-with-knowledge action. This action is backed by an Agentforce Data Library, which wraps a search index and a retriever for you.
Both routes end the same way. Retrieved excerpts are placed in the prompt, and the model is told to answer from them.
| Aspect | Prompt template with retriever | Knowledge action with Data Library |
|---|---|---|
| Setup effort | More steps. You create the index, the retriever, and the template. | Fewer steps. The library creates the index and retriever. |
| Control over the prompt text | Full. You write every line. | Limited. You steer mostly through topic instructions. |
| Control over filters and returned fields | Full, set on the retriever. | Narrower, set through library options. |
| Best fit | Custom answer formats, specific fields, reuse outside agents | Standard question answering over Knowledge |
Later chapters cover each route in detail. For now, remember that you choose between control and speed.
The request path
The following diagram shows what happens when a customer asks a question that needs your content.
Three points about this path matter for the rest of the tutorial.
- The retrieval step happens before the model writes anything. The model never searches your data itself. It only sees what the retriever returns.
- The prompt is assembled from your instructions, the retrieved excerpts, and the customer's question. Each of these is a place where grounding can succeed or fail.
- The Einstein Trust Layer sits between the prompt and the model. A later chapter covers it. Here, note only that grounded content passes through it like any other prompt content.
What the topic controls
A topic does two things for grounding.
First, the topic's classification description and scope decide whether the agent routes a question to the topic at all. If a customer asks about a return policy and no topic mentions policies, the agent will not reach your knowledge action. The model may then answer from its general knowledge or decline. Many "the agent ignored my articles" reports are really routing problems.
Second, the topic's instructions say how to use the action and what to do with the result. Here is a sample instruction that ties the reply to the knowledge action and defines a fallback.
When a customer asks a product or policy question, use the knowledge action to look up the answer.
Base your reply only on the returned articles.
If no relevant article is returned, do not guess. Tell the customer you do not have that information and offer escalation.This instruction has three parts: a trigger (when to look up), a constraint (use only the returned articles), and a fallback (what to do on an empty result). A later chapter returns to this pattern. Instructions without a fallback are the most common cause of invented answers.
What the action controls
The action is where retrieval actually runs. It decides:
- Which retriever or Data Library is queried.
- What text is sent as the search query. Often this is derived from the customer's message by the reasoning engine.
- Which fields come back with each chunk, such as the article title and URL.
Because the model sees only returned fields, an action that returns text but no title cannot cite an article by name. Returned fields are a configuration choice, not something the model can recover later.
What the prompt template controls
If you use a prompt template, it controls how excerpts are framed for the model. This is the shape of a grounding prompt:
Answer the customer's question using only the knowledge article excerpts provided below.
If the excerpts do not contain the answer, say you could not find it and offer to connect the customer with a human agent.
Do not use outside knowledge. Mention the article title when you rely on an excerpt.
Excerpts:
<retriever results inserted here by the prompt template>
Question:
<customer question inserted here>The bracketed lines are placeholders. In Prompt Builder you replace them with a retriever resource and an input resource. The text above them is what you write by hand.
Checking that content exists before blaming the agent
Before you debug the agent, confirm that the content you expect is published. This SOQL query lists the most recently published English article versions.
SELECT Id, Title, UrlName, PublishStatus, Language, LastPublishedDate
FROM Knowledge__kav
WHERE PublishStatus = 'Online'
AND Language = 'en_US'
ORDER BY LastPublishedDate DESC
LIMIT 20Only articles with PublishStatus = 'Online' are candidates for ingestion. A draft article never reaches Data Cloud, so no retriever can return it. If your article is missing from this result, fix publishing first.
Common errors at this layer
| Symptom | Likely cause at the agent layer |
|---|---|
| The agent answers from general knowledge | The topic scope does not match the question, or the instructions lack a "use only returned articles" rule |
| The agent says it has no information, but the article exists | The retriever returned nothing. Check the index, filters, and publishing status |
| The reply is correct but names no source | The action or template does not return the title or URL field |
| The agent invents a policy when search is empty | No fallback instruction for empty results |
| A custom template is never used | No action calls the template, or the topic does not include that action |
How this connects to the rest of the tutorial
The agent layer is the last stage in the chain. Upstream, Knowledge articles are published, ingested into Data Cloud, split into chunks, embedded as vectors, and indexed. A retriever searches that index. This chapter covered the downstream end, where a topic, an action, and optionally a prompt template consume the results. When you build the upstream pieces in later chapters, keep the downstream needs in mind: the fields you return and the filters you set decide what the agent can say.
Exercise
A customer asks, "Can I return an opened item?" The agent replies with a plausible policy, but the policy does not appear in any of your articles. Name two places in the agent configuration you would check first, and say what you would look for in each.
Show answer
First, the topic: confirm its scope and classification description cover return-policy questions, and confirm its instructions say to use the knowledge action and base the reply only on returned articles. Second, the fallback: confirm the instructions say what to do when no article is returned, such as saying the information is not available and offering escalation. You could also check the knowledge action or prompt template to see that it is attached to the topic and that no template text allows outside knowledge.
Exercise
Name one reason to choose a prompt template with a retriever over a knowledge action backed by a Data Library, and one reason for the opposite choice.
Show answer
Choose the prompt template when you need full control over prompt wording, returned fields, or filters, or want to reuse the template outside an agent. Choose the Data Library knowledge action when you want standard question answering over Knowledge with less setup, since the library creates the index and retriever for you.