We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Agentic Search

Click to play video

As you already (hopefully) know from our Build an AI Agent course, an "agent" is just tool calls in a for loop.

Recursive RAG is like a simple AI agent, and we can make it more "agentic" by giving it more tools to use in its loop. We could even break up our step-by-step RAG pipeline into a set of tools, and allow the LLM to "run" the pipeline in the order it thinks is best for a given query.

The Basic Loop

while not done:
    # Choose tool based on what we learned
    tool = pick_next_tool(previous_results)
    # Search with that tool
    results = tool.search(query)
    # Update our knowledge
    previous_results.append(results)

The magic is in pick_next_tool() – it looks at what we found and decides what to do next. Imagine we had these tools:

  • Keyword search: Finds movies by keywords
  • Semantic search: Narrows by year, rating, or genre
  • Regex search: Finds movies by matching text patterns like "bear attack" or "wilderness survival"
  • Genre search: Filters movies by specific genres like horror, adventure, or drama
  • Actor search: Finds movies starring specific actors like Leonardo DiCaprio or Hugh Jackman

For example, say we ask our RAG agent:

"Find scary bear movies that were in a forest"

  1. It picks the genre search tool first to narrow down to horror/thriller movies.
  2. Then it uses regex search to find bear-related titles.
  3. It uses another regex search to find movies that also mention "forest."
  4. It uses semantic search to find movies about related terms like "wilderness" or "survival."
  5. Finally, it uses all the results to generate a summary with citations.

Each tool choice is influenced by the previous results, and is chosen for the specific query and results, rather than having the order preprogrammed in advance. That's how a human using a search engine would do it, after all!

One final note: adding a real-time LLM to search does make it a lot slower, and agentic loops? Even more so. Only use this approach when you really need that extra bit of intelligence and flexibility.

We aren't going to build agentic RAG in this course, simply because it's a lot of glue code that, if you complete this course and the AI Agent course, you'll be able to easily plug together yourself. The concept is straightforward enough.