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ΒΆ

AnswerGeneration

Output from the answer generation agent.

DocumentRetrieval

Output from the document retrieval agent.

SimpleRAGState

State schema for SimpleRAG workflow using MultiAgentState pattern.

FunctionsΒΆ

create_rag_agents(vector_store_config, llm_config[, ...])

Create the retriever and generator agents for SimpleRAG.

create_simple_rag_workflow(query, vector_store_config)

Create a complete SimpleRAG workflow state.

display_rag_results(state)

Display SimpleRAG results in a formatted way.

execute_simple_rag(state[, debug])

Execute the complete SimpleRAG workflow.

get_rag_summary(state)

Get a summary of the RAG execution.

run_simple_rag(query, vector_store_config[, ...])

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:
  1. Input: query, configuration

  2. Retriever updates: documents, retrieved_count, query_processed

  3. Generator updates: answer, sources, confidence

  4. 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:

SimpleRAGState

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:

SimpleRAGState

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:

dict[str, Any]

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:

SimpleRAGState