agents.rag.agentic.agent

Agentic RAG Agent - ReAct + Retrieval with Proper Haive Patterns.

This implementation follows the LangChain/LangGraph agentic RAG tutorial but uses proper Haive base agent infrastructure: - Inherits from ReActAgent for reasoning/acting patterns - Uses ToolRouteMixin for automatic tool routing - Proper Pydantic patterns (no __init__, model validators) - Generic type safety with bounds - Multiple engines (LLM + Retriever + Grader)

Classes

AgenticRAGAgent

Agentic RAG agent combining ReAct reasoning with intelligent retrieval.

AgenticRAGState

State schema for agentic RAG with retrieval metadata.

DocumentGrade

Grade for document relevance.

QueryRewrite

Rewritten query for better retrieval.

Functions

create_agentic_rag_agent(documents, llm_config[, ...])

Create agentic RAG agent with sensible defaults.

create_memory_aware_agentic_rag(documents, llm_config)

Create agentic RAG with long-term memory capabilities.

Module Contents

class agents.rag.agentic.agent.AgenticRAGAgent(/, **data)

Bases: haive.agents.react.agent.ReactAgent, haive.core.common.mixins.tool_route_mixin.ToolRouteMixin

Agentic RAG agent combining ReAct reasoning with intelligent retrieval.

This agent can: - Decide when to retrieve vs respond directly (agentic behavior) - Grade retrieved documents for relevance - Rewrite queries when documents are not relevant - Loop until relevant documents are found or max attempts reached

Key features: - Proper Pydantic patterns (no __init__) - Multiple engines with proper typing - Automatic tool routing via ToolRouteMixin - Generic type safety

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)

classmethod from_documents(documents, llm_config, embedding_config=None, **kwargs)

Create agentic RAG agent from documents using proper factory pattern.

This follows Pydantic best practices by using a classmethod factory instead of complex __init__ logic.

Parameters:
  • documents (list[langchain_core.documents.Document])

  • llm_config (haive.core.models.llm.base.LLMConfig)

  • embedding_config (Any | None)

Return type:

AgenticRAGAgent

setup_agentic_rag()

Setup agentic RAG with multiple engines and tools.

This follows proper Pydantic patterns using model_validator instead of __init__ for post-initialization setup.

Return type:

AgenticRAGAgent

property state_schema: type[AgenticRAGState]

Computed property for agentic RAG state schema.

Return type:

type[AgenticRAGState]

class agents.rag.agentic.agent.AgenticRAGState(/, **data)

Bases: pydantic.BaseModel

State schema for agentic RAG with retrieval metadata.

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.agentic.agent.DocumentGrade(/, **data)

Bases: pydantic.BaseModel

Grade for document relevance.

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.agentic.agent.QueryRewrite(/, **data)

Bases: pydantic.BaseModel

Rewritten query for better retrieval.

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.agentic.agent.create_agentic_rag_agent(documents, llm_config, embedding_config=None, **kwargs)

Create agentic RAG agent with sensible defaults.

Parameters:
  • documents (list[langchain_core.documents.Document])

  • llm_config (haive.core.models.llm.base.LLMConfig)

  • embedding_config (Any | None)

Return type:

AgenticRAGAgent

agents.rag.agentic.agent.create_memory_aware_agentic_rag(documents, llm_config, memory_config=None, **kwargs)

Create agentic RAG with long-term memory capabilities.

Parameters:
  • documents (list[langchain_core.documents.Document])

  • llm_config (haive.core.models.llm.base.LLMConfig)

  • memory_config (Any | None)

Return type:

AgenticRAGAgent