agents.rag.multi_agent_rag.multi_rag¶
Multi-Agent RAG System Implementation.
from typing import Any This module provides complete multi-agent RAG workflows using the multi-agent framework with conditional routing, sequential processing, and parallel execution patterns.
Classes¶
Advanced RAG system that adapts its strategy based on query complexity and results. |
|
Base multi-agent RAG system with retrieve -> grade -> generate workflow. |
|
Conditional multi-agent RAG system with smart routing based on document quality. |
|
Multi-agent RAG system with iterative document processing. |
|
Parallel multi-agent RAG system for consensus-based processing. |
Functions¶
|
Create a conditional RAG system with smart routing. |
|
Create an iterative RAG system with document-by-document processing. |
|
Create a sequential RAG system with configurable components. |
|
Check document quality and route accordingly. |
|
Conditional routing function to determine if documents need grading. |
|
Conditional routing function to determine if query needs refinement. |
|
Test compatibility between two agents using the compatibility module. |
Validate compatibility across multiple agents in a workflow. |
Module Contents¶
- class agents.rag.multi_agent_rag.multi_rag.AdaptiveRAGMultiAgent(simple_rag=None, complex_rag=None, consensus_rag=None, **kwargs)¶
Bases:
haive.agents.multi.base.ConditionalAgent
Advanced RAG system that adapts its strategy based on query complexity and results.
This system demonstrates sophisticated conditional routing with multiple decision points and fallback strategies.
Init .
- Parameters:
simple_rag (BaseRAGMultiAgent | None) – [TODO: Add description]
complex_rag (IterativeRAGMultiAgent | None) – [TODO: Add description]
consensus_rag (ParallelRAGMultiAgent | None) – [TODO: Add description]
- class agents.rag.multi_agent_rag.multi_rag.BaseRAGMultiAgent(retrieval_agent=None, grading_agent=None, answer_agent=None, **kwargs)¶
Bases:
haive.agents.multi.base.SequentialAgent
Base multi-agent RAG system with retrieve -> grade -> generate workflow.
This is the simple sequential RAG agent as mentioned in the user prompt.
Init .
- Parameters:
retrieval_agent (haive.agents.rag.multi_agent_rag.agents.SimpleRAGAgent | None) – [TODO: Add description]
grading_agent (haive.agents.rag.multi_agent_rag.agents.DocumentGradingAgent | None) – [TODO: Add description]
answer_agent (haive.agents.rag.multi_agent_rag.agents.SimpleRAGAnswerAgent | None) – [TODO: Add description]
- class agents.rag.multi_agent_rag.multi_rag.ConditionalRAGMultiAgent(retrieval_agent=None, grading_agent=None, answer_agent=None, query_refiner=None, **kwargs)¶
Bases:
haive.agents.multi.base.ConditionalAgent
Conditional multi-agent RAG system with smart routing based on document quality.
This system uses conditional routing to decide whether to grade documents, refine queries, or generate answers based on the current state.
Init .
- Parameters:
retrieval_agent (haive.agents.rag.multi_agent_rag.agents.SimpleRAGAgent | None) – [TODO: Add description]
grading_agent (haive.agents.rag.multi_agent_rag.agents.DocumentGradingAgent | None) – [TODO: Add description]
answer_agent (haive.agents.rag.multi_agent_rag.agents.SimpleRAGAnswerAgent | None) – [TODO: Add description]
query_refiner (Any | None) – [TODO: Add description]
- class agents.rag.multi_agent_rag.multi_rag.IterativeRAGMultiAgent(retrieval_agent=None, iterative_grader=None, answer_agent=None, custom_grader_callable=None, **kwargs)¶
Bases:
haive.agents.multi.base.SequentialAgent
Multi-agent RAG system with iterative document processing.
This system demonstrates iterating over retrieved documents and processing each one individually, as mentioned in the user prompt.
Init .
- Parameters:
retrieval_agent (haive.agents.rag.multi_agent_rag.agents.SimpleRAGAgent | None) – [TODO: Add description]
iterative_grader (haive.agents.rag.multi_agent_rag.agents.IterativeDocumentGradingAgent | None) – [TODO: Add description]
answer_agent (haive.agents.rag.multi_agent_rag.agents.SimpleRAGAnswerAgent | None) – [TODO: Add description]
custom_grader_callable (collections.abc.Callable | None) – [TODO: Add description]
- class agents.rag.multi_agent_rag.multi_rag.ParallelRAGMultiAgent(rag_agents=None, **kwargs)¶
Bases:
haive.agents.multi.base.ParallelAgent
Parallel multi-agent RAG system for consensus-based processing.
This system runs multiple RAG agents in parallel and aggregates their results.
Init .
- Parameters:
rag_agents (list[BaseRAGMultiAgent] | None) – [TODO: Add description]
- agents.rag.multi_agent_rag.multi_rag.create_conditional_rag_system(documents=None, custom_grader=None)¶
Create a conditional RAG system with smart routing.
- Parameters:
documents (list[langchain_core.documents.Document] | None)
custom_grader (collections.abc.Callable | None)
- Return type:
- agents.rag.multi_agent_rag.multi_rag.create_iterative_rag_system(documents=None, custom_grader=None)¶
Create an iterative RAG system with document-by-document processing.
- Parameters:
documents (list[langchain_core.documents.Document] | None)
custom_grader (collections.abc.Callable | None)
- Return type:
- agents.rag.multi_agent_rag.multi_rag.create_sequential_rag_system(documents=None, use_grading=True, use_citations=False)¶
Create a sequential RAG system with configurable components.
- agents.rag.multi_agent_rag.multi_rag.document_quality_check(state)¶
Check document quality and route accordingly.
- Returns:
Documents are good enough for generation - “insufficient”: Need more/better documents - “regrade”: Need different grading approach
- Return type:
“sufficient”
- Parameters:
state (haive.agents.rag.multi_agent_rag.state.MultiAgentRAGState)
- agents.rag.multi_agent_rag.multi_rag.should_grade_documents(state)¶
Conditional routing function to determine if documents need grading.
- Returns:
If documents need to be graded - “generate”: If documents are already good enough - “refine”: If query needs refinement
- Return type:
“grade”
- Parameters:
state (haive.agents.rag.multi_agent_rag.state.MultiAgentRAGState)
- agents.rag.multi_agent_rag.multi_rag.should_refine_query(state)¶
Conditional routing function to determine if query needs refinement.
- Returns:
Try retrieval again with refined query - “generate”: Generate answer with available documents - “END”: Stop processing (failure case)
- Return type:
“retrieve”
- Parameters:
state (haive.agents.rag.multi_agent_rag.state.MultiAgentRAGState)
- agents.rag.multi_agent_rag.multi_rag.test_agent_compatibility(agent1, agent2)¶
Test compatibility between two agents using the compatibility module.
This demonstrates using the compatibility module to test if agents can work together as mentioned in the user prompt.