agents.rag.simple.simple_rag_stateΒΆ
SimpleRAG - Proper MultiAgentState Implementation.
This is the CORRECT SimpleRAG implementation following the working pattern from the guides: - Use MultiAgentState (not MultiAgent class inheritance) - Use create_agent_node_v3() for execution - Direct field updates through structured outputs - Sequential execution: retriever β generator
- Architecture:
SimpleRAGState extends MultiAgentState agents = [BaseRAGAgent, SimpleAgent] Sequential execution via nodes: retriever_node β generator_node Direct field access: state.documents, state.answer
Examples
Basic usage:
from haive.agents.rag.simple.simple_rag_state import SimpleRAGState, create_simple_rag_workflow
# Create the complete workflow
state = create_simple_rag_workflow(
query="What is machine learning?",
vector_store=your_vector_store,
top_k=5
)
# Execute sequential workflow
result = await execute_simple_rag(state)
# Access results directly
print(f"Answer: {result.answer}")
print(f"Sources: {result.sources}")
ClassesΒΆ
Output from the answer generation agent. |
|
Output from the document retrieval agent. |
|
State schema for SimpleRAG workflow using MultiAgentState pattern. |
FunctionsΒΆ
|
Create the retriever and generator agents for SimpleRAG. |
|
Create a complete SimpleRAG workflow state. |
|
Display SimpleRAG results in a formatted way. |
|
Execute the complete SimpleRAG workflow. |
|
Get a summary of the RAG execution. |
|
Synchronous wrapper for SimpleRAG execution. |
Module ContentsΒΆ
- class agents.rag.simple.simple_rag_state.AnswerGeneration(/, **data)ΒΆ
Bases:
pydantic.BaseModel
Output from the answer generation agent.
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- Parameters:
data (Any)
- class agents.rag.simple.simple_rag_state.DocumentRetrieval(/, **data)ΒΆ
Bases:
pydantic.BaseModel
Output from the document retrieval agent.
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- Parameters:
data (Any)
- class agents.rag.simple.simple_rag_state.SimpleRAGState(/, **data)ΒΆ
Bases:
haive.core.schema.prebuilt.multi_agent_state.MultiAgentState
State schema for SimpleRAG workflow using MultiAgentState pattern.
This follows the working pattern from the guides: - Extends MultiAgentState for proper agent management - Contains all input and output fields as direct attributes - Agents update fields directly through structured outputs - No complex nested structures - just clean, direct field access
- Flow:
Input: query, configuration
Retriever updates: documents, retrieved_count, query_processed
Generator updates: answer, sources, confidence
Direct access: state.answer, state.sources, etc.
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- Parameters:
data (Any)
- agents.rag.simple.simple_rag_state.create_rag_agents(vector_store_config, llm_config, structured_output_model=None)ΒΆ
Create the retriever and generator agents for SimpleRAG.
- Parameters:
vector_store_config (haive.core.engine.vectorstore.VectorStoreConfig) β Configuration for the vector store
llm_config (haive.core.engine.aug_llm.AugLLMConfig) β Configuration for the LLM
structured_output_model (type[pydantic.BaseModel] | None) β Optional custom output model for generator
- Returns:
Tuple of (retriever_agent, generator_agent)
- Return type:
tuple[haive.agents.rag.base.agent.BaseRAGAgent, haive.agents.simple.agent.SimpleAgent]
- agents.rag.simple.simple_rag_state.create_simple_rag_workflow(query, vector_store_config, llm_config=None, top_k=5, structured_output_model=None, workflow_id='')ΒΆ
Create a complete SimpleRAG workflow state.
- Parameters:
query (str) β The query to process
vector_store_config (haive.core.engine.vectorstore.VectorStoreConfig) β Vector store configuration
llm_config (haive.core.engine.aug_llm.AugLLMConfig | None) β LLM configuration (uses default if None)
top_k (int) β Number of documents to retrieve
structured_output_model (type[pydantic.BaseModel] | None) β Optional custom output model
workflow_id (str) β Unique workflow identifier
- Returns:
Initialized SimpleRAGState ready for execution
- Return type:
- agents.rag.simple.simple_rag_state.display_rag_results(state)ΒΆ
Display SimpleRAG results in a formatted way.
- Parameters:
state (SimpleRAGState) β Completed SimpleRAGState with results
- Return type:
None
- async agents.rag.simple.simple_rag_state.execute_simple_rag(state, debug=False)ΒΆ
Execute the complete SimpleRAG workflow.
This follows the working pattern from the guides: - Sequential execution using create_agent_node_v3() - Direct field updates through structured outputs - Clean, simple execution flow
- Parameters:
state (SimpleRAGState) β The SimpleRAGState to execute
debug (bool) β Enable debug logging
- Returns:
Updated state with all results populated
- Return type:
- agents.rag.simple.simple_rag_state.get_rag_summary(state)ΒΆ
Get a summary of the RAG execution.
- Parameters:
state (SimpleRAGState) β Completed SimpleRAGState
- Returns:
Dictionary with execution summary
- Return type:
- agents.rag.simple.simple_rag_state.run_simple_rag(query, vector_store_config, llm_config=None, top_k=5, debug=False)ΒΆ
Synchronous wrapper for SimpleRAG execution.
- Parameters:
query (str) β The query to process
vector_store_config (haive.core.engine.vectorstore.VectorStoreConfig) β Vector store configuration
llm_config (haive.core.engine.aug_llm.AugLLMConfig | None) β LLM configuration
top_k (int) β Number of documents to retrieve
debug (bool) β Enable debug logging
- Returns:
Completed SimpleRAGState with results
- Return type: