core/metacognition/¶
Overview¶
The metacognition/ submodule provides self-reflection, loop detection, and prompt management for the agent.
Files¶
- metacognition.py: Contains the
MetaCognitionclass for internal monologue, task analysis, and intelligent stopping decisions. - loop_detector.py: Implements the
LoopDetectorclass for detecting and breaking repetitive loops in agent behavior. - prompts.py: Centralizes all prompt templates and formatting logic for system, metacognitive, and loop-breaking messages.
Key Classes¶
- MetaCognition: Analyzes tasks, reflects on actions, and decides when to continue or stop.
- LoopDetector: Detects exact and semantic repetition, confusion, and no-action loops.
Responsibilities¶
- Enable the agent to reflect on its own progress
- Detect and break out of unproductive loops
- Centralize and manage all prompt templates
How Metacognition Works¶
- Task Analysis: The agent thinks about what the user really wants and what success looks like.
- Action Reflection: After each step, the agent reflects on what it just did and how much progress it made.
- Loop Detection: The agent checks if it's repeating itself or getting stuck.
- Stopping Decision: The agent decides if it should keep going or stop, based on progress and confidence.
Example: Avoiding a Loop¶
- The agent notices it's giving the same answer multiple times.
- It triggers a loop-breaking prompt and tries a new approach or stops.
In Plain English¶
- This part of the agent is like an inner voice: it thinks about the task, checks its own work, and knows when to stop or try something different.