---
title: "What is agentic search? AI agents that search in a loop (2026)"
canonical: "https://xerj.org/science/agentic-search"
updated: "2026-11-22"
---

# What is agentic search?

SHORT ANSWER · UPDATED 2026-11-22
What is agentic search? It is an AI agent searching with tools in a loop: it runs a query, reads the result, and picks the next query or file. Claude Code works this way with glob and grep. The cost is context: every result the agent reads uses tokens, so smaller, ranked results leave more room to reason.
**Key number:** One ranked XERJ answer on psf/requests was 1,303 bytes where ripgrep printed 25,150: about 330 tokens instead of about 6,300 at 4 characters per token. (as of 2026-11-22 · sources: [capture](https://xerj.org/answers/local-code-search-mcp-fewer-tokens-than-grep), [OpenAI tokens guide](https://help.openai.com/en/articles/4936856-what-are-tokens-and-how-to-count-them))
Last checked: 2026-11-22. The definition follows Anthropic's engineering post on context engineering; token sizes use OpenAI's rule of thumb.

**TL;DR** Agentic search is retrieval run by the agent itself: the model calls search tools in a loop, reads what comes back, and decides what to search next, instead of receiving one batch of retrieved passages up front. It keeps results fresh, because nothing is indexed ahead of time, and it lets the agent follow leads. Its cost is the context the results take up.

## Agent prompt

```text
Act as a coding agent. Read https://xerj.org/science/agentic-search and https://xerj.org/llms.txt. Install XERJ, index this repository, register xerj mcp, and from now on search with xerj_search before reading whole files. Report how many bytes each search returned.
```

## How it works

The agent gets search tools and a goal. It runs a search, reads the output, and decides what to do next: open a file, refine the query, or answer. Anthropic describes agents as LLMs autonomously using tools in a loop, and calls this pattern "just in time" retrieval: the agent keeps light references, such as file paths and queries, and loads data into context when it needs it.
Claude Code is the best-known example. Per Anthropic, CLAUDE.md files go into context up front, while glob and grep let the agent find and read files just in time.

## Agentic search vs RAG

|  | Classic RAG | Agentic search |

| Who picks the query | the pipeline, from the user prompt | the agent, at each step |
| When retrieval runs | once, before the answer | any number of times during the task |
| Index needed | yes, built ahead of time | optional: grep needs none, an index helps on large trees |
| Main cost | index build and refresh | tokens spent reading results |

## How XERJ uses it

XERJ is a new way for AI to search for data. It gives the agent a search tool that returns a few ranked passages with file:line instead of every matching line. The agent still searches in a loop; each step simply reads less. Register it with `xerj mcp` next to grep, and let the agent pick per question. XERJ is single-node, and search is lexical by default.

## History and research

Anthropic's [Effective context engineering for AI agents](https://www.anthropic.com/engineering/effective-context-engineering-for-ai-agents) (2025-09-29) has a section on context retrieval and agentic search, and describes the hybrid approach Claude Code uses. Retrieval-augmented generation itself goes back to Lewis et al., 2020.

## Related terms

[Context engineering](https://xerj.org/science/context-engineering), [agentic memory](https://xerj.org/science/agentic-memory), [Model Context Protocol](https://xerj.org/science/model-context-protocol), [syntax-aware search](https://xerj.org/science/syntax-aware-search) and [BM25](https://xerj.org/science/bm25).

## FAQ

### What is agentic search?

Agentic search is retrieval run by the agent itself: the model calls search tools in a loop, reads what comes back, and decides what to search next, instead of receiving one batch of retrieved passages up front.

### How is agentic search different from RAG?

Classic RAG retrieves passages once, before the model answers. In agentic search the model chooses its own queries and tools during the task, and can search again after reading results. Many systems mix both.

### Which tools do agents use for agentic search?

Coding agents often use glob to find files and grep or ripgrep to find text, then read files. Others call a search index through MCP, such as a docs server or a local code index that returns ranked passages.

### Why does the size of search output matter?

Everything a tool returns goes into the context window. OpenAI's rule of thumb is that 1 token is about 4 characters of English text, so a 25,150-byte grep output costs about 6,300 tokens and a 1,303-byte ranked answer about 330.

### Is agentic search the same as agentic RAG?

They overlap. Agentic RAG usually means an agent that plans retrieval steps over a RAG pipeline; agentic search is the wider idea of an agent that searches with tools in a loop.

## Evidence

- Anthropic defines agents as LLMs autonomously using tools in a loop, describes "just in time" context retrieval, and says Claude Code drops CLAUDE.md into context up front while glob and grep retrieve files just in time. Source: [https://www.anthropic.com/engineering/effective-context-engineering-for-ai-agents](https://www.anthropic.com/engineering/effective-context-engineering-for-ai-agents)
- 1 token is approximately 4 characters of English text. Source: [https://help.openai.com/en/articles/4936856-what-are-tokens-and-how-to-count-them](https://help.openai.com/en/articles/4936856-what-are-tokens-and-how-to-count-them)
- On psf/requests one XERJ answer was 1,303 bytes; rg printed 25,150. Source: [/answers/local-code-search-mcp-fewer-tokens-than-grep](https://xerj.org/answers/local-code-search-mcp-fewer-tokens-than-grep)
- Lewis et al., Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks, 2020. Source: [https://arxiv.org/abs/2005.11401](https://arxiv.org/abs/2005.11401)

## Related

- [Agentic RAG and classic RAG compared](https://xerj.org/answers/agentic-rag-vs-rag)
- [RAG or grep for AI agents?](https://xerj.org/answers/rag-vs-grep)
- [ast-grep, ripgrep and ugrep for agents](https://xerj.org/compare/ast-grep-vs-ripgrep-vs-ugrep)
- [Context7 alternatives 2026](https://xerj.org/compare/context7-alternatives-2026)
