# Retrieval and Search Tools — AI Agents and Tool Use

Source: https://www.geekswithgeeks.com/en/ai-agents-mcp/kinds-retrieval

> Give an agent access to documents and databases and treat retrieval as just another tool.

## Retrieval as a tool

Models do not know your private documents or yesterday's data. A **search tool** (keyword, vector or SQL) lets the agent look things up when it needs them, rather than stuffing everything into the prompt. This is the "agentic" form of RAG: the model decides what to search for, reads the results and can search again with a better query.

## What agents can reach

Most tools fall into a few families: knowledge, computation, systems and the screen.

![Three families: retrieve, compute, act.](assets/figures/ai-agents-mcp/section-4-map.svg) — Figure 4.1 — Retrieve, compute and act.

## A search tool that cites sources

Return short snippets with ids so answers can cite them and the model can fetch a full document only when needed.

```python
@tool
def search_docs(query: str, limit: int = 5) -> str:
    """Search the help-centre articles. Returns up to `limit` snippets as
    [doc_id] snippet. Call get_doc(doc_id) for the full text."""
    hits = index.search(query, limit)
    return "\n".join(f"[{h.id}] {h.snippet[:200]}" for h in hits)
```

## Retrieved text is untrusted

A document in your index might contain instructions aimed at the model. Treat retrieved text as data, never as commands, and see the safety section for defences.

**Quiz:** What does "agentic RAG" add to plain RAG?

- [ ] It removes the need for documents
- [x] The model decides what to search and can search again
- [ ] It guarantees correct answers
- [ ] It works without a search index

*Answer:* The model decides what to search and can search again. The model drives retrieval as a tool, iterating until it has what it needs.
