Skip to main content
This cookbook demonstrates how to use the agentic capabilities which ship by default in R2R. The R2R agent is an intelligent system that can formulate its own questions, search for information, and provide informed responses based on the retrieved context. It can be customized on the fly.
Agents in the R2R framework are still in beta. Please let us know what you like/dislike and what features you would like to see added.

Understanding R2R’s RAG Agent

R2R’s RAG agent is designed to provide powerful, context-aware responses by combining large language models with a search capability over your ingested documents. When you initialize an R2R application, it automatically creates a RAG assistant that’s ready to use. R2R plans to extend its agent functionality to mirror core features supported by OpenAI and more, including:
  • Multiple tool support (e.g., code interpreter, file search)
  • Persistent conversation threads
  • Complete end to end observability of agent interactions
R2R also provides support for local RAG capabilities, allowing you to create AI agents that can access and reason over your local document store, entirely offline. The RAG agent is also available for use through the R2R API, specifically via the agent endpoint.

Using the RAG Agent

Now, let’s use the RAG agent to answer questions:
In this example, the agent might formulate its own questions to gather more information before providing a response. For instance, it could ask the search tool about Aristotle’s scientific works or his methods of inquiry.

Streaming Responses

To see the agent’s thought process in real-time, you can use streaming responses:
This will produce a streaming response, showing the agent’s thought process, including its search queries and the gradual construction of its response.

Customizing the RAG Agent

This section is still under development, please proceed carefully when customizing agents.
You can customize various aspects of the RAG agent’s behavior:
This example demonstrates how to:
  • Set custom search filters
  • Enable hybrid search (combining vector and keyword search)
  • Adjust the number of search results
  • Customize the generation config
  • Use a specific model for the response

Conclusion

The R2R RAG assistant is a powerful tool that combines large language models with advanced search capabilities. By leveraging your ingested documents and the flexible agent endpoint, you can create dynamic, context-aware conversational experiences. Key takeaways:
  1. R2R automatically creates a RAG assistant when initializing the application.
  2. The agent endpoint provides easy access to the RAG assistant’s capabilities.
  3. You can customize various aspects of the assistant’s behavior, including search settings and generation parameters.
  4. Streaming responses allow for real-time interaction and visibility into the assistant’s thought process.
Experiment with different settings and configurations to find the optimal setup for your specific use case. Remember to keep your ingested documents up-to-date to ensure the assistant has access to the most relevant and recent information.