Agent
Build advanced, context-aware chatbots
R2R’s Agent system orchestrates Retrieval-Augmented Generation (RAG) to provide intelligent, multi-step reasoning over your data. By pairing large language models with R2R’s search capabilities, the agent can query your documents (and optionally the web), process queries in context, and return rich, cited answers.
Key Features
- Conversation Integration: Context is tracked through Conversations, allowing follow-up questions
- Hybrid Retrieval: Combines vector search, full-text search, and (optionally) knowledge graph retrieval
- Streaming Responses: Optionally stream token-by-token outputs
- Tool Usage: Potential for extended functionality, including local and web search
Note: The agent system is in active development. Future updates will introduce more tools, deeper conversation threading, and enhanced orchestration.
Basic Usage
Here’s a simple agent query:
Follow-Up with Conversations
To maintain context, store the conversation_id
and pass it on:
Tip: Use the Conversations API directly to manage messages, e.g., listing all user queries or archiving complete sessions.
Streaming Responses
Enable stream
in rag_generation_config
for real-time token-by-token output:
Advanced RAG Search
Customize the underlying retrieval with search_settings
. For example, to require semantic search and filter by document_id
:
Multiple Tools (Beta)
You can enable external search tools in the r2r.toml
under [agent]
:
When enabled, the agent can:
- Search your local ingestion store (default)
- Perform web searches for broader context (requires valid
Serper
or other API keys)
Integrations and Observability
- Document Management: Your agent interacts with R2R documents ingested via Documents API.
- Conversations: Manage context and user interactions via Conversations.
- Logs & Analytics: Monitor agent usage through R2R’s logging and analytics.
Best Practices
- Keep
conversation_id
: Passing it ensures the agent sees prior messages. - Tune
search_settings
: Fine-tune filters and semantic/hybrid search options. - Use
generation_config
: Adjustmodel
,temperature
, andmax_tokens
to match your desired style. - Streaming: Stream large responses for better UX.
- Memory & Cleanup: Clear or delete old conversations if context is no longer needed.
Troubleshooting
- Empty or irrelevant responses: Review
search_settings
filters, increaselimit
, or check your document ingestion. - Conversation confusion: Ensure the correct
conversation_id
is passed. - Timeouts: For very large documents or models, consider increasing your server’s timeouts or using streaming output.
Conclusion
R2R’s Agent feature transforms your document collections into an interactive knowledge base. With conversation context, advanced search integration, and streaming outputs, you can build robust, user-friendly AI applications. To dive deeper, explore:
Harness the agent for research, enterprise Q&A, or any scenario where context-driven, intelligent responses are needed.