Table of Contents

Class ReflectionHandler

Namespace
LMKit.Agents.Planning
Assembly
LM-Kit.NET.dll

Planning handler that implements reflection-based reasoning.

The agent generates an initial response, then critically evaluates and refines it through self-reflection. Improves output quality by catching errors and inconsistencies.

public sealed class ReflectionHandler : PlanningHandlerBase, IPlanningHandler
Inheritance
ReflectionHandler
Implements
Inherited Members

Remarks

Reflection Loop

  1. Generate: Produce an initial response to the task.
  2. Reflect: Critically evaluate the response for errors, gaps, or improvements.
  3. Refine: Produce an improved response based on the reflection.
  4. Optionally repeat until satisfied or max iterations reached.

Constructors

ReflectionHandler()

Initializes a new instance of the ReflectionHandler class.

Properties

Instance

Gets the singleton instance with default settings.

RefinementPrompt

Gets or sets the refinement prompt template.

Use {response} for the original response and {reflection} for the reflection.

ReflectionCycles

Gets or sets the number of reflection cycles to perform.

Default is 1 (one reflection and refinement cycle).

ReflectionPrompt

Gets or sets the reflection prompt template.

Use {response} as a placeholder for the current response.

Strategy

Gets the planning strategy.

Methods

Initialize(PlanningContext)

Initializes the context for reflection.

PrepareInput(PlanningContext, string)

Prepares the input based on the current phase.

ProcessOutput(PlanningContext, string)

Processes the model output based on the current phase.

WithCycles(int)

Creates a handler with the specified number of reflection cycles.