Sub topic 13
Letting an agent answer from knowledge
This chapter covers how an Agentforce agent uses a knowledge action to answer from your Knowledge content. It assumes you can build a basic agent with topics and actions. It also assumes you have a search index and a retriever, or a Data Library, from earlier chapters. Salesforce changes the setup screens often, so the exact labels may differ in your org.
What a knowledge action does
An agent has no built-in access to your Knowledge articles. It reaches them through an action. A knowledge action takes the customer's question, sends it to a retriever, and returns the matching chunks. The agent then writes its reply from those chunks.
The flow has four parts:
- The customer asks a question.
- The agent's reasoning engine picks a topic, then picks the knowledge action from that topic's actions.
- The action runs the retriever against the search index and returns chunks.
- The agent composes an answer from the returned chunks, and the Einstein Trust Layer screens the request and the response.
Two ways to connect knowledge
You can supply knowledge to an agent in two ways. Pick one per use case.
| Approach | How it works | Best when |
|---|---|---|
| Data Library with the standard knowledge action | You create a Data Library, and Agentforce builds the index and retriever for you. The agent uses the standard answer-questions-with-knowledge action. | You want the fastest setup and the defaults are acceptable. |
| Custom retriever in a prompt template, called from an action | You build the index and retriever yourself. You reference the retriever in a prompt template, then expose the template to the agent as an action. | You need specific filters, returned fields, or result counts. |
The Data Library is the shortcut. The custom path gives you control over what comes back. Both end in the same place: an action in a topic that returns chunks for the agent to use.
Setting up the action in a topic
An action only runs if the agent can choose it. The agent chooses actions from the topic it has already selected. This has two consequences.
- The action must be added to the right topic. An action that sits in a different topic from the one the question lands in is never called.
- The topic's description and scope decide whether the question reaches that topic at all. If the topic description does not mention product or policy questions, those questions may land elsewhere.
A typical setup looks like this:
- Open the agent in Agentforce Builder.
- Add or choose a topic, for example "Product and policy questions".
- Write a clear classification description and scope for the topic.
- Add the knowledge action to the topic. For the Data Library route, this is the standard knowledge answering action tied to your library.
- Add instructions that tell the agent how to use the action (see below).
- Preview the agent and test with real questions.
Instructions that tie the reply to the action
Adding the action is not enough. Without instructions, the agent may blend retrieved text with what the model already knows. The topic instructions should say three things: when to use the action, that the reply must rest only on the returned articles, and what to do when nothing comes back.
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.The fallback line matters most. A retriever almost always returns something, because vector search returns the nearest chunks even when they are a poor match. An agent with no fallback rule will try to answer from weak chunks. Later chapters cover writing and testing these instructions in more detail.
Confirming the content is there
Before you debug the agent, check that the content exists. An agent can only answer from articles that were published and ingested. This SOQL query lists the latest 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 20If an article is missing from the results, it is a Knowledge publishing problem. If it appears here but the agent never cites it, the problem is later in the chain: ingestion, the index, the retriever, or the action.
What the agent sees
The action returns chunks and the fields you configured on the retriever. The agent can only use what is returned. Two settings from the retriever chapter therefore shape every answer:
- Returned fields. If you do not return the article title or URL, the agent cannot cite them. Return at least the chunk text and the article title.
- Result count. Too few chunks can miss the passage that holds the answer. Too many add noise and can pull in contradictory text.
Filters apply here as well. A filter on language or article type limits which chunks the agent can see, so a filter that is too narrow looks like "the agent does not know" when the content does exist.
Common errors
| Symptom | Likely cause | Fix |
|---|---|---|
| The agent never calls the knowledge action | The action is missing from the topic, or the question lands in another topic | Add the action to the correct topic and sharpen the topic description |
| The agent answers confidently with no article support | Instructions do not require grounding or define a fallback | Add "base your reply only on the returned articles" and a fallback |
| The answer is correct but cites nothing | Title or URL is not in the retriever's returned fields | Add those fields to the retriever |
| A new article is not found | Article not published, or the index has not refreshed | Check `PublishStatus`, then check ingestion and index status |
| Answers are off topic | Result count is too high, or chunks match loosely | Lower the count, add filters, or improve article structure |
| An agent user cannot get content that an admin can | Permissions of the running user differ | Check the access of the agent's running user to the data |
Checking the result in preview
Use the agent preview and look at the trace of each turn, not only at the final text. The trace shows which topic was chosen, whether the action ran, what input it received, and what it returned. This lets you place a failure at one step:
- No action call means a topic or instruction problem.
- An action call with empty or irrelevant output means a retriever, index, or ingestion problem.
- Good output but a poor reply means an instruction problem.
Test at least three kinds of question: one the articles clearly answer, one they partly answer, and one they do not cover. The third should trigger your fallback.
Exercise
A customer asks about your return policy. The agent replies with a plausible policy, but the preview trace shows the knowledge action returned no chunks. What is wrong, and what change fixes it?
Show answer
The agent answered from the model's general knowledge because nothing constrained it when retrieval came back empty. Update the topic instructions to base replies only on returned articles and to tell the customer it has no information and offer escalation when no article is returned. Then also check why retrieval was empty, such as an unpublished article, a filter that is too narrow, or an index that has not refreshed.
Exercise
Your agent has a working retriever, but a question about product pricing never triggers the knowledge action. The action exists in the agent. Name two things to check.
Show answer
First, check that the action is added to the topic the question is routed to, since the agent only picks actions from the selected topic. Second, check the topic's description and scope, because a description that does not cover pricing questions can send them to a different topic.