Skip to content

Metacognition

scarecr0w12 edited this page Jun 19, 2026 · 1 revision

Metacognition

CortexPrism assesses every user task before execution and reflects on every agent turn afterwards. The metacognition system scores confidence, classifies task types, escalates low-confidence assessments, and runs adversarial second-pass critiques.

Task Assessment (assessTask)

src/agent/metacog.ts analyzes user messages for:

  • Ambiguity — unclear intent triggers ask_first decision
  • Complexity — multi-step tasks trigger plan_with_rollback
  • Code tasks — patterns like "fix bug", "implement", "refactor"
  • Destructive intent — patterns like "rm", "delete", "drop"
  • Independent subtasks — "and also", "then after" triggers parallelize

Decisions

Decision Meaning
direct Execute immediately
ask_first Request clarification before proceeding
delegate Hand off to a sub-agent
plan_with_rollback Generate a plan artifact before executing
parallelize Fan out to multiple sub-agents concurrently

Confidence Escalation (#53)

When confidence falls below 0.35 for a direct decision, the system auto-escalates to ask_first:

if confidence < 0.35 and decision === 'direct':
    escalate to ask_first with clarification prompt
    log escalation event to lens_events

Escalation events appear in the Metacognition page history with a red ⚡ escalated badge.

Adversarial Self-Critique (#52)

After each turn (when reflection is enabled), a second-pass critique runs using a skeptical/adversarial system prompt that actively looks for:

  • Missed edge cases and error handling gaps
  • Validation omissions
  • Security concerns the agent may have overlooked
  • Alternative approaches

Results are stored in reflection_memory with category adversarial and surfaced as critique cards in the Metacognition web UI.

API Endpoints

Endpoint Description
GET /api/metacognition/history Recent assessments, reflections, and escalations (limit 80)
GET /api/metacognition/decisions?sessionId= Session-scoped decision timeline
GET /api/metacognition/summary Decision distribution, total escalations, recent critiques

Web UI

The Metacognition page shows:

  • Decision Distribution — bar chart of decision types (direct, ask_first, delegate, plan_with_rollback, parallelize)
  • Decision History — timeline with color-coded decisions and escalation badges
  • Adversarial Critiques — critique cards showing issues from the adversarial reflection pass

Clone this wiki locally