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)
packages/ai/src/agent/metacog.ts analyzes user messages for:
- Ambiguity — unclear intent triggers
ask_firstdecision - 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
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
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/summary | Decision distribution, total escalations, recent critiques |
POST /api/metacognition/test | Test assessment with full signal breakdown and confidence |
Web UI
The Metacognition page shows:
- Decision Distribution — bar chart of decision types
- Decision History — timeline with color-coded decisions and escalation badges
- Adversarial Critiques — critique cards showing issues from the adversarial reflection pass
See Also
- Agent Loop — Where metacognition fits in the execution flow
- Pipeline System — Pre/post-assess hook integration
- Sub-Agents — Delegation and parallelization targets