agents.reflection.multi_agent_reflectionΒΆ

Multi-agent reflection pattern using sequential coordination.

This module implements reflection patterns using the new multi-agent system. It creates a sequential workflow where: 1. ReactAgent performs initial reasoning and action 2. SimpleAgent performs reflection using message transformer post-hooks

The reflection flow follows the pattern discovered in project documentation: Main Agent β†’ Response β†’ Convert to prompt partial β†’ Message Transform β†’ Reflection

ClassesΒΆ

MultiAgentReflection

Multi-agent reflection system using sequential coordination.

ReflectionGrade

Structured output for reflection grading.

ReflectionResult

Result from the reflection multi-agent.

FunctionsΒΆ

create_full_reflection_system([tools, engine_config])

Create a full reflection system with ReactAgent + ReflectionAgent + ImprovementAgent.

create_simple_reflection_system([tools, engine_config])

Create a simple reflection system with ReactAgent + ReflectionAgent.

Module ContentsΒΆ

class agents.reflection.multi_agent_reflection.MultiAgentReflection(name='reflection_system', engine_config=None, tools=None, include_improvement=False, reflection_temperature=0.3, main_temperature=0.7)ΒΆ

Multi-agent reflection system using sequential coordination.

This class creates a coordinated reflection workflow: 1. ReactAgent processes the initial request 2. Reflection agent analyzes and grades the response 3. Optional improvement agent creates enhanced response

The pattern follows the documented message transformer post-hook approach: Main Agent β†’ Response β†’ GradingResult β†’ Convert to prompt partial β†’ Message Transform β†’ Reflection Agent (with grade in prompt context)

Initialize the multi-agent reflection system.

Parameters:
  • name (str) – Name for the multi-agent system

  • engine_config (haive.core.engine.aug_llm.AugLLMConfig | None) – Base engine configuration (will be customized per agent)

  • tools (list[langchain_core.tools.Tool] | None) – Tools available to the main ReactAgent

  • include_improvement (bool) – Whether to include an improvement agent

  • reflection_temperature (float) – Temperature for reflection agents (lower for consistency)

  • main_temperature (float) – Temperature for main agent

async reflect_on_task(task, debug=False)ΒΆ

Perform reflection on a task using the multi-agent system.

Parameters:
  • task (str) – The task to process and reflect on

  • debug (bool) – Whether to enable debug output

Returns:

ReflectionResult with original response, reflection, and optional improvement

Return type:

ReflectionResult

class agents.reflection.multi_agent_reflection.ReflectionGrade(/, **data)ΒΆ

Bases: pydantic.BaseModel

Structured output for reflection grading.

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.reflection.multi_agent_reflection.ReflectionResult(/, **data)ΒΆ

Bases: pydantic.BaseModel

Result from the reflection multi-agent.

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.reflection.multi_agent_reflection.create_full_reflection_system(tools=None, engine_config=None)ΒΆ

Create a full reflection system with ReactAgent + ReflectionAgent + ImprovementAgent.

Parameters:
  • tools (list[langchain_core.tools.Tool] | None) – Tools for the ReactAgent

  • engine_config (haive.core.engine.aug_llm.AugLLMConfig | None) – Base engine configuration

Returns:

MultiAgentReflection system with improvement capability

Return type:

MultiAgentReflection

agents.reflection.multi_agent_reflection.create_simple_reflection_system(tools=None, engine_config=None)ΒΆ

Create a simple reflection system with ReactAgent + ReflectionAgent.

Parameters:
  • tools (list[langchain_core.tools.Tool] | None) – Tools for the ReactAgent

  • engine_config (haive.core.engine.aug_llm.AugLLMConfig | None) – Base engine configuration

Returns:

MultiAgentReflection system ready for use

Return type:

MultiAgentReflection