Skip to content
Byte Yatra Blogs

RAG for agents: retrieve per step, not per task

Fetching documents once at the start leaves the agent blind halfway through the job

Byte Yatra Team

2 min read ·

Classic retrieval-augmented generation fetches a few documents, stuffs them into the prompt and asks one question. That works for a chatbot. For an agent that takes ten steps, the documents it needed at step seven are rarely the ones you guessed at step one.

Retrieval as a tool

Instead of stuffing documents up front, expose search_docs(query) and let the agent call it whenever it hits a gap. The agent already knows how to use tools; searching becomes one more of them.

TOOLS = [
    {
        "name": "search_docs",
        "description": "Search the company handbook and runbooks. "
                       "Use whenever you need a policy, a procedure or a fact you are unsure of.",
        "input_schema": {"type": "object",
                         "properties": {"query": {"type": "string"}},
                         "required": ["query"]},
    },
]

The agent knows what it is missing better than you can predict in advance.

Keep chunks small and cited

Return short passages with their source. The agent can quote them and you can verify the answer later.

Chunk styleProblemBetter
Whole documentsFills the context, buries the answer200–400 word passages
No sourceNobody can check the claimTitle, section and link with every passage
Top 20 resultsThe model skims and misses the best oneTop 3–5, ranked

Let the agent refine its query

First searches are often too broad. A good result format makes the next search better: show the titles of near misses so the agent can narrow down, and say plainly when nothing matched rather than returning weak results.

Mix search methods

Keyword search finds exact terms like error codes and product names. Semantic search finds paraphrases. Many teams run both and merge the results; agents benefit because their queries swing between the two styles.

Measure retrieval separately

When an agent gives a wrong answer, check first whether the right passage was ever retrieved. If it was not, fix search. If it was and the agent ignored it, fix the prompt. Mixing the two up wastes weeks.

Responses

Loading responses