agents.rag.simple.sequential_agentΒΆ

SimpleRAG - Sequential MultiAgent Implementation (BaseRAG β†’ SimpleAgent).

This is the correct SimpleRAG implementation following the sequential multi-agent pattern:

SimpleRAG = Sequential[BaseRAGAgent, SimpleAgent]

Architecture: 1. BaseRAGAgent: Performs document retrieval from vector store 2. SimpleAgent: Generates structured answers from retrieved documents 3. Sequential Execution: BaseRAG output β†’ SimpleAgent input

Key Features: - Sequential Multi-Agent Pattern: Proper composition of specialized agents - Pydantic Best Practices: No __init__ overrides, field validation, inheritance - Type Safety: Full type hints and proper agent composition - Real Component Integration: Uses actual BaseRAGAgent and SimpleAgent - Structured Output: Support for custom response models - Comprehensive Documentation: Google-style docstrings with examples

Design Philosophy: - Composition over Monolith: Uses existing proven agents - Clear Separation of Concerns: Retrieval vs Generation - Reusable Components: Each agent can be used independently - Testable Architecture: Easy to test each component separately

Examples

Basic usage:

from haive.agents.rag.simple import SimpleRAG
from haive.core.engine.aug_llm import AugLLMConfig
from haive.core.engine.vectorstore import VectorStoreConfig

rag = SimpleRAG(
    name="qa_assistant",
    retriever_config=VectorStoreConfig(vector_store=your_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=AugLLMConfig(),
    structured_output_model=QAResponse
)

ClassesΒΆ

RAGResponse

Comprehensive RAG response model.

SimpleRAG

SimpleRAG - Sequential composition of BaseRAGAgent and SimpleAgent.

Module ContentsΒΆ

class agents.rag.simple.sequential_agent.RAGResponse(/, **data)ΒΆ

Bases: pydantic.BaseModel

Comprehensive RAG response model.

Contains the generated answer along with comprehensive metadata about the retrieval and generation process, including sources, confidence scores, and execution metrics.

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)

model_configΒΆ

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class agents.rag.simple.sequential_agent.SimpleRAG(/, **data)ΒΆ

Bases: pydantic.BaseModel

SimpleRAG - Sequential composition of BaseRAGAgent and SimpleAgent.

This implementation properly composes two specialized agents: 1. BaseRAGAgent: Handles document retrieval from vector stores 2. SimpleAgent: Generates answers from retrieved documents

The sequential flow is: Query β†’ BaseRAG β†’ Documents β†’ SimpleAgent β†’ Answer

This follows the multi-agent pattern established in the Haive framework where complex capabilities are built by composing simpler, focused agents.

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?")

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()
)

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)

async arun(input_data, debug=False, **kwargs)ΒΆ

Execute RAG pipeline with sequential agent composition.

Flow: 1. Extract query from input 2. Use BaseRAGAgent to retrieve relevant documents 3. Format documents as context 4. Use SimpleAgent to generate answer from context 5. Return formatted response

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:

  • str: Simple answer string (default)

  • RAGResponse: Full response with metadata (if debug=True)

  • BaseModel: Custom structured output (if structured_output_model set)

Return type:

Generated response - format depends on structured_output_model

Raises:
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

get_agent_info()ΒΆ

Get information about the composed agents.

Return type:

dict[str, Any]

run(input_data, debug=False, **kwargs)ΒΆ

Synchronous execution wrapper.

Parameters:
Return type:

str | RAGResponse | pydantic.BaseModel

setup_agents()ΒΆ

Setup internal agent instances after validation.

Return type:

SimpleRAG

classmethod validate_context_template(v)ΒΆ

Validate context template has required placeholders.

Parameters:

v (str)

Return type:

str

model_configΒΆ

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].