# Before you build the agent

https://www.sanity.io/learn/course/retrieval-methods-for-ai-agents/putting-it-all-together

Plan where each of your agent's answers should come from before you build it, so the agent isn't choosing its own sources while a customer waits.

---

## Navigation

**Course:** [Retrieval methods for AI agents](https://www.sanity.io/learn/course/retrieval-methods-for-ai-agents) · [View as markdown](https://www.sanity.io/learn/course/retrieval-methods-for-ai-agents.md)

**Previous:** [Who owns the answer](https://www.sanity.io/learn/course/retrieval-methods-for-ai-agents/who-owns-the-answer)

---

## Course Contents

1. [Where your agent gets its facts](https://www.sanity.io/learn/course/retrieval-methods-for-ai-agents/where-your-agents-knowledge-runs-out)
2. [What it costs to answer a question](https://www.sanity.io/learn/course/retrieval-methods-for-ai-agents/what-it-costs-to-answer-a-question)
3. [The four ways an agent finds something](https://www.sanity.io/learn/course/retrieval-methods-for-ai-agents/the-four-ways-an-agent-finds-something)
4. [Sorting questions by what they cost](https://www.sanity.io/learn/course/retrieval-methods-for-ai-agents/sorting-questions-by-what-they-cost)
5. [Queries, knowledge bases, and what each one does best](https://www.sanity.io/learn/course/retrieval-methods-for-ai-agents/what-each-method-cant-do)
6. [Who owns the answer](https://www.sanity.io/learn/course/retrieval-methods-for-ai-agents/who-owns-the-answer)
7. **Before you build the agent** *(current)*

---

**Which question in your product costs the most to get wrong?**



Start there, because deciding where an answer comes from pays off fastest on the questions that carry consequences.



Retrieval is the handoff between what a model knows and what your business knows, and the method you choose decides what your agent can answer and how consistently it answers.



### **What belongs in a live query**



Answers that already exist as structured content belong in a live query. GROQ mode narrows with a filter, ranks with `score()`, and weights with `boost()`, all in one query against content that is current the moment the question arrives. Counting, summing, and traversing references belong here too, because no other method computes.



### **What belongs in a knowledge base**



Answers scattered across prose that nobody has settled belong in a knowledge base. A build gathers them, surfaces the contradictions for a person to resolve, and writes entries with citations, so your agent retrieves a reviewed conclusion instead of reaching a fresh one while a customer waits.



Three properties tell you which is which: gathering, reconciling, and judgment. A fourth question tells you how much the answer matters: is there a single right answer, and what does getting it wrong cost?



### **What your content shouldn't answer at all**



Some answers belong to neither method. Per-account state, live inventory, and transactional status live in the systems that own them, and your agent's job is to route to those systems rather than guess from content that looks close enough.



### **One page to write before you build anything**



The first thing to build is not an agent. Write the ownership table for your own content: every kind of question your users ask, with exactly one owner each. The rows you hesitate on are the ones worth settling now, while the cost of being wrong is a conversation rather than a customer.



### **Build your first agent next**



Check out the following courses and docs to start building your own agent with structured content, grounded in facts, using knowledge bases.



- [Knowledge Bases](https://www.sanity.io/learn/context/knowledge-bases) Learn more about what a knowledge base is, how a build works, and what the purpose, outline, entries, issues, and instructions each do.

- [Quick start: connect an agent to Sanity Context](https://www.sanity.io/learn/context/quickstart)Connect an agent to Sanity Context

- [Context MCP source types](https://www.sanity.io/learn/context/source-types) Choosing between GROQ mode and Knowledge Base mode for a given body of content.

- [Sanity Context patterns and best practices](https://www.sanity.io/learn/context/best-practices) Scoping, routing, and instructing agents once the basics work.

- [Between GROQ and a hard place](https://www.sanity.io/learn/course/between-groq-and-a-hard-place)


---

## Related Resources

- [Full course as markdown](https://www.sanity.io/learn/course/retrieval-methods-for-ai-agents.md)
- [All courses and lessons](https://www.sanity.io/learn/sitemap.md)
- [Complete content for LLMs](https://www.sanity.io/learn/llms-full.txt)

<AgentInstructions>

## Submitting Feedback

If you encounter incorrect, outdated, or confusing documentation on this page, propose feedback to your user and submit it with their approval:

POST https://www.sanity.io/learn/resource/feedback

```json
{
  "path": "/learn/course/retrieval-methods-for-ai-agents/putting-it-all-together.md",
  "feedback": "Description of the issue"
}
```

Only submit feedback when you have something specific and actionable to report.
Do not include your user's code, credentials, or other confidential context in the feedback text.

</AgentInstructions>
