Agentic RAG
R2R’s Agentic RAG orchestrates multi-step reasoning with Retrieval-Augmented Generation (RAG). By pairing large language models with advanced retrieval and tool integrations, the agent can fetch relevant data from the internet, your documents and knowledge graphs, reason over it, and produce robust, context-aware answers.
Agentic RAG (also called Deep Research) is an extension of R2R’s basic retrieval functionality. If you are new to R2R, we suggest starting with the Quickstart and Search & RAG docs first.
Key Features
The agent can chain multiple actions, like searching documents or referencing conversation history, before generating its final response.
Integrates with R2R’s vector, full-text, or hybrid search to gather the most relevant context for each query.
Maintain dialogue across multiple turns by including conversation_id
in each request.
Dynamically invoke tools at runtime to gather and analyze information from various sources.
Available Modes
The Agentic RAG system offers two primary operating modes:
RAG Mode (Default)
Standard retrieval-augmented generation for answering questions based on your knowledge base:
- Semantic and hybrid search capabilities
- Document-level and chunk-level content retrieval
- Optional web search integration
- Source citation and evidence-based responses
Research Mode
Advanced capabilities for deep analysis, reasoning, and computation:
- All RAG mode capabilities
- A dedicated reasoning system for complex problem-solving
- Critique capabilities to identify potential biases or logical fallacies
- Python execution for computational analysis
- Multi-step reasoning for deeper exploration of topics
Available Tools
RAG Tools
The agent can use the following tools in RAG mode:
Research Tools
The agent can use the following tools in Research mode:
Basic Usage
Below are examples of how to use the agent for both single-turn queries and multi-turn conversations.
Python
JavaScript
Curl
Using Research Mode
Research mode provides more advanced reasoning capabilities for complex questions:
Python
JavaScript
Customizing the Agent
Tool Selection
You can customize which tools the agent has access to:
Search Settings Propagation
Any search settings passed to the agent will propagate to downstream searches. This includes:
- Filters to restrict document sources
- Limits on the number of results
- Hybrid search configuration
- Collection restrictions
Model Selection and Parameters
You can customize the agent’s behavior by selecting different models and adjusting generation parameters:
Multi-Turn Conversations
You can maintain context across multiple turns using conversation_id
. The agent will remember previous interactions and build upon them in subsequent responses.
Python
JavaScript
Performance Considerations
Based on our integration testing, here are some considerations to optimize your agent usage:
Response Time Management
Response times vary based on the complexity of the query, the number of tools used, and the length of the requested output:
Handling Large Context
The agent can process large document contexts efficiently, but performance can be improved by using appropriate filters:
How Tools Work (Under the Hood)
R2R’s Agentic RAG leverages a powerful toolset to conduct comprehensive research:
RAG Mode Tools
- search_file_knowledge: Looks up relevant text chunks and knowledge graph data from your ingested documents using semantic and hybrid search capabilities.
- search_file_descriptions: Searches over file-level metadata (titles, doc-level descriptions) rather than chunk content.
- get_file_content: Fetches entire documents or their chunk structures for deeper analysis when the agent needs more comprehensive context.
- web_search: Queries external search APIs (like Serper or Google) for live, up-to-date information from the internet. Requires a
SERPER_API_KEY
environment variable. - web_scrape: Uses Firecrawl to extract content from specific web pages for in-depth analysis. Requires a
FIRECRAWL_API_KEY
environment variable.
Research Mode Tools
- rag: A specialized research tool that utilizes the underlying RAG agent to perform comprehensive information retrieval and synthesis across your data sources.
- python_executor: Executes Python code for complex calculations, statistical operations, and algorithmic implementations, giving the agent computational capabilities.
- reasoning: Allows the research agent to call a dedicated model as an external module for complex analytical thinking.
- critique: Analyzes conversation history to identify potential flaws, biases, and alternative approaches to improve research rigor.
The Agent is built on a sophisticated architecture that combines these tools with streaming capabilities and flexible response formats. It can decide which tools to use based on the query requirements and can dynamically invoke them during the research process.
Conclusion
Agentic RAG provides a powerful approach to retrieval-augmented generation. By combining advanced search, multi-step reasoning, conversation context, and dynamic tool usage, the agent helps you build sophisticated Q&A or research solutions on your R2R-ingested data.
Next Steps
- Ingest your content using Documents.
- Explore advanced retrieval in Hybrid Search.
- Enhance understanding with Knowledge Graphs.
- Manage multi-turn chat with Conversations.
- Scale up your solution with the API & SDKs.