agents.rag.self_reflective.agent

Self-Reflective Agentic RAG Agent.

from typing import Any Implementation of self-reflective RAG with critique and iterative improvement. Uses reflection loops to assess and enhance answer quality.

Classes

ImprovedAnswer

Result of answer improvement iteration.

ReflectionCritique

Structured critique from reflection.

ReflectionPlan

Plan for iterative improvement based on reflection.

ReflectionType

Types of reflection analysis.

SelfReflectiveRAGAgent

Self-Reflective RAG agent with iterative improvement capabilities.

SelfReflectiveResult

Complete result from self-reflective RAG process.

Functions

create_self_reflective_rag_agent(documents[, ...])

Create a Self-Reflective RAG agent.

get_self_reflective_rag_io_schema()

Get I/O schema for Self-Reflective RAG agents.

Module Contents

class agents.rag.self_reflective.agent.ImprovedAnswer(/, **data)

Bases: pydantic.BaseModel

Result of answer improvement iteration.

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

Bases: pydantic.BaseModel

Structured critique from reflection.

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

Bases: pydantic.BaseModel

Plan for iterative improvement based on reflection.

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.self_reflective.agent.ReflectionType

Bases: str, enum.Enum

Types of reflection analysis.

Initialize self. See help(type(self)) for accurate signature.

class agents.rag.self_reflective.agent.SelfReflectiveRAGAgent

Bases: haive.agents.base.agent.Agent

Self-Reflective RAG agent with iterative improvement capabilities.

This agent uses conditional edges to iterate through reflection loops.

build_graph()

Build the self-reflective graph with conditional edges.

Return type:

haive.core.graph.state_graph.base_graph2.BaseGraph

classmethod from_documents(documents, llm_config=None, max_iterations=3, quality_threshold=0.85, **kwargs)

Create Self-Reflective RAG agent from documents.

Parameters:
  • documents (list[langchain_core.documents.Document]) – Documents to index for retrieval

  • llm_config (haive.core.models.llm.base.LLMConfig | None) – LLM configuration

  • max_iterations (int) – Maximum reflection iterations

  • quality_threshold (float) – Quality threshold to stop iterating

  • **kwargs – Additional arguments

Returns:

SelfReflectiveRAGAgent instance

generate_initial_answer(state)

Generate initial answer.

Parameters:

state (dict[str, Any])

Return type:

dict[str, Any]

improve_answer(state)

Improve the answer based on reflection.

Parameters:

state (dict[str, Any])

Return type:

dict[str, Any]

reflect_and_critique(state)

Generate critiques and plan improvements.

Parameters:

state (dict[str, Any])

Return type:

dict[str, Any]

setup_agent()

Initialize engines.

Return type:

None

should_continue_improving(state)

Determine if improvement should continue.

Parameters:

state (dict[str, Any])

Return type:

str

synthesize_result(state)

Create final self-reflective result.

Parameters:

state (dict[str, Any])

Return type:

dict[str, Any]

class agents.rag.self_reflective.agent.SelfReflectiveResult(/, **data)

Bases: pydantic.BaseModel

Complete result from self-reflective RAG process.

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.self_reflective.agent.create_self_reflective_rag_agent(documents, llm_config=None, reflection_mode='thorough', **kwargs)

Create a Self-Reflective RAG agent.

Parameters:
  • documents (list[langchain_core.documents.Document]) – Documents for retrieval

  • llm_config (haive.core.models.llm.base.LLMConfig | None) – LLM configuration

  • reflection_mode (str) – Mode (“quick”, “balanced”, “thorough”)

  • **kwargs – Additional arguments

Returns:

Configured Self-Reflective RAG agent

Return type:

SelfReflectiveRAGAgent

agents.rag.self_reflective.agent.get_self_reflective_rag_io_schema()

Get I/O schema for Self-Reflective RAG agents.

Return type:

dict[str, list[str]]