SelfReflectionModule class

Performs meta-cognitive analysis of the agent's own reasoning process.

Usage

final reflection = SelfReflectionModule(
  memory: agentMemory,
  llm: llmCore,  // optional — enables LLM-powered reflection
);

// Called automatically by AgentLoopController every N iterations
final insight = await reflection.reflect(context, dag);
if (insight != null) {
  print('Reflection: $insight');
}

What it detects

  • Stalled progress — no tasks completed for N iterations
  • Tool call loops — the same tool called repeatedly with the same input
  • Cascade failures — multiple tasks failing in sequence
  • Thought spirals — only think decisions, no tool calls, for N iterations
Implemented types

Constructors

SelfReflectionModule({required AgentMemoryStore memory, LLMCore? llm, SelfReflectionConfig? config, ConsciousnessLogger? logger})

Properties

hashCode → int
The hash code for this object.
no setterinherited
history → List<ReflectionRecord>
All reflection records produced so far.
no setter
lastReflection → ReflectionRecord?
Most recent reflection, or null if none yet.
no setter
reflectionCount → int
Number of reflections performed.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

diagnostics() → String
Returns a diagnostic summary of all reflections so far.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
notifyThinkOnly() → void
Notifies the reflection module of a think-only decision (no tool used).
notifyToolCall(String toolName, Map<String, dynamic> input) → void
Notifies the reflection module about the most recent tool call.
reflect(AgentContext context, ExecutionDAG dag) → Future<String?>
Analyses context and dag and returns an actionable insight, or null.
override
resetTrackers() → void
Resets all tracking state (e.g. after a successful re-plan).
toString() → String
A string representation of this object.
override

Operators

operator ==(Object other) → bool
The equality operator.
inherited