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ΒΆ
Comprehensive RAG response model. |
|
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:
- 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:
ValueError β If input validation fails
RuntimeError β If critical pipeline components fail
- 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:
- 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:
- run(input_data, debug=False, **kwargs)ΒΆ
Synchronous execution wrapper.
- classmethod validate_context_template(v)ΒΆ
Validate context template has required placeholders.
- model_configΒΆ
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].