agents.rag.simple.multi_agent_simple_rag

SimpleRAG - Proper MultiAgent Implementation.

This is the CORRECT SimpleRAG implementation using the proper MultiAgent pattern:

SimpleRAG extends MultiAgent with agents={“retriever”: BaseRAGAgent, “generator”: SimpleAgent}

The key insight is that SimpleRAG IS a MultiAgent that coordinates two specific agents: 1. BaseRAGAgent: Handles document retrieval 2. SimpleAgent: Generates answers from documents

This follows the MultiAgent[AgentsT] pattern where: - SimpleRAG extends MultiAgent - agents field contains the two agents - execution_mode=”sequence” for retrieval → generation flow

Examples

Basic usage:

rag = SimpleRAG(
    name="qa_system",
    retriever_config=VectorStoreConfig(vector_store=vector_store),
    llm_config=AugLLMConfig(temperature=0.7),
    top_k=5
)

result = await rag.arun("What is machine learning?")

From documents:

rag = SimpleRAG.from_documents(
    documents=my_documents,
    embedding_config=embedding_config,
    llm_config=AugLLMConfig()
)

Classes

SimpleRAG

SimpleRAG - MultiAgent coordinating BaseRAGAgent and SimpleAgent.

Module Contents

class agents.rag.simple.multi_agent_simple_rag.SimpleRAG

Bases: haive.agents.multi.agent.MultiAgent

SimpleRAG - MultiAgent coordinating BaseRAGAgent and SimpleAgent.

This is the proper implementation of SimpleRAG following the MultiAgent pattern:

Structure:

SimpleRAG extends MultiAgent agents = {

“retriever”: BaseRAGAgent, # Handles document retrieval “generator”: SimpleAgent # Generates answers from documents

} execution_mode = “sequence” # retriever → generator

The MultiAgent pattern means: - SimpleRAG IS a MultiAgent - It contains other agents in its agents field - It coordinates their execution in sequence - It uses the proper graph building and state management

This is much cleaner than custom composition because it leverages the existing MultiAgent infrastructure for routing, state management, and execution patterns.

Examples

Basic RAG:

rag = SimpleRAG(
    name="qa_assistant",
    retriever_config=VectorStoreConfig(vector_store=vector_store),
    llm_config=AugLLMConfig(temperature=0.7),
    top_k=5
)

result = await rag.arun("What is machine learning?")

With structured output:

class QAResponse(BaseModel):
    answer: str
    sources: List[str]
    confidence: float

rag = SimpleRAG(
    name="structured_qa",
    retriever_config=retriever_config,
    llm_config=llm_config,
    structured_output_model=QAResponse
)

From documents:

rag = SimpleRAG.from_documents(
    documents=my_documents,
    embedding_config=embedding_config,
    llm_config=AugLLMConfig()
)
async arun(input_data, debug=False, **kwargs)

Execute RAG pipeline using MultiAgent sequential execution.

This leverages the MultiAgent infrastructure but processes the results to provide RAG-specific functionality like document extraction and context formatting.

Parameters:
  • input_data (str | dict[str, Any]) – Query string or structured input dict with ‘query’ field

  • debug (bool) – Enable debug logging and detailed output

  • **kwargs – Additional execution parameters

Returns:

Generated response from the generator agent

Raises:
Return type:

Any

classmethod from_documents(documents, embedding_config, llm_config, name='SimpleRAG_from_docs', **kwargs)

Create SimpleRAG from a list of documents.

Parameters:
  • documents (list[langchain_core.documents.Document]) – List of documents to create vector store from

  • embedding_config (Any) – Embedding configuration for vector store

  • llm_config (haive.core.engine.aug_llm.AugLLMConfig) – LLM configuration for answer generation

  • name (str) – Name for the RAG agent

  • **kwargs – Additional configuration parameters

Returns:

Configured SimpleRAG instance

Return type:

SimpleRAG

classmethod from_vectorstore(vector_store_config, llm_config, name='SimpleRAG_from_vs', **kwargs)

Create SimpleRAG from existing vector store configuration.

Parameters:
  • vector_store_config (haive.core.engine.vectorstore.VectorStoreConfig) – Vector store configuration

  • llm_config (haive.core.engine.aug_llm.AugLLMConfig) – LLM configuration for answer generation

  • name (str) – Name for the RAG agent

  • **kwargs – Additional configuration parameters

Returns:

Configured SimpleRAG instance

Return type:

SimpleRAG

async generate_answer(query, documents, **kwargs)

Generate answer using the generator agent.

Parameters:
  • query (str) – Original query

  • documents (list[langchain_core.documents.Document]) – Retrieved documents for context

  • **kwargs – Additional generation parameters

Returns:

Generated answer (format depends on structured_output_model)

Return type:

Any

get_generator_agent()

Get the generator agent.

Return type:

haive.agents.simple.agent.SimpleAgent

get_rag_info()

Get information about the RAG configuration.

Return type:

dict[str, Any]

get_retriever_agent()

Get the retriever agent.

Return type:

haive.agents.rag.base.agent.BaseRAGAgent

async retrieve_documents(query, k=None, score_threshold=None, **kwargs)

Retrieve documents using the retriever agent.

Parameters:
  • query (str) – Query string for retrieval

  • k (int | None) – Number of documents to retrieve (defaults to self.top_k)

  • score_threshold (float | None) – Minimum similarity score (defaults to self.similarity_threshold)

  • **kwargs – Additional retrieval parameters

Returns:

List of retrieved documents

Return type:

list[langchain_core.documents.Document]

setup_rag_agents()

Setup the retriever and generator agents after validation.

Return type:

SimpleRAG

classmethod validate_context_template(v)

Validate context template has required placeholders.

Parameters:

v (str)

Return type:

str