liveBook · Manning

Metacognition

As explained in AI Agents in Action, Second Edition

Metacognitive monitoring is the ongoing assessment of an agent's own knowledge and confidence while producing answers or taking actions.

An agent can retrieve information and produce a fluent answer yet still miss a contradiction or guess when evidence is thin. Metacognition is the agent’s ability to monitor its own reasoning while it works. Cognition concerns understanding and solving the problem; metacognition asks whether the agent is making progress, how well its evidence supports an answer, and whether the answer lies within its knowledge. section 10.0 section 10.1.1 section 10.6

Three checks turn that idea into an engineering practice:

  • Confidence calibration: Compare confidence with signals that help predict correctness, such as token likelihoods, retrieval scores, and consistency of evidence. Simply prompting an agent to say “I’m not sure” does not calibrate it. section 10.1.4
  • Stagnation detection: Notice when repeated attempts produce no new findings, then change strategy instead of retrying until an iteration limit is reached. section 10.1.4
  • Knowledge boundary awareness: Detect weak training or retrieval coverage and shift toward graceful degradation rather than an overcommitted guess. section 10.3.6

Checking a knowledge boundary

A boundary check can inspect a shared cognitive workspace. One implementation averages the relevance scores of retrieved findings, adds a memory-coverage signal, and includes the workspace’s confidence. It uses 0 when there are no findings, 0.8 when memory has a hit, and 0.2 when it does not. An average above 0.6 is classified as within knowledge; the classification also allows edge-of-knowledge and outside-knowledge states. These are inspectable inputs to a decision, not a guarantee that an answer is correct. section 10.3.6

In a cognitive agent architecture, evaluation performs metacognitive monitoring alongside perception, planning, execution, and attention. Shared workspace state gives evaluation something to inspect, while attention can route the agent’s next step. This makes monitoring part of the agentic loop rather than a disclaimer appended to its final answer. Use confidence-gated execution, stagnation checks, and boundary checks when an agent must decide whether to continue, change approach, or acknowledge insufficient knowledge. section 10.6 section 10.1.4 section 10.3.6

Listing 10.11 12_boundary_awareness.py
class KnowledgeBoundary(str, Enum):
    WITHIN = "within_knowledge"
    EDGE = "edge_of_knowledge"
    OUTSIDE = "outside_knowledge"

def assess_knowledge_boundary(
    workspace: CognitiveWorkspace
) -> KnowledgeBoundary:
    signals = []

    # Check retrieval quality
    if workspace.findings:
        avg_relevance = sum(
            f.relevance_score for f in workspace.findings
        ) / len(workspace.findings)
        signals.append(avg_relevance)
    else:
        signals.append(0.0)                         #1

    # Check memory coverage
    if workspace.memory_hits:
        signals.append(0.8)                         #2
    else:
        signals.append(0.2)

    # Check confidence state
    signals.append(workspace.confidence)

    avg_signal = sum(signals) / len(signals)

    if avg_signal > 0.6:
        return KnowledgeBoundary.WITHIN
    elif avg_signal > 0.3:
        return KnowledgeBoundary.EDGE
    else:
        workspace.active_signal = AttentionSignal.LOW_CONFIDENCE
        return KnowledgeBoundary.OUTSIDE

Inspect the boundary-assessment listing for the concrete workspace signals, fallback values, and within-knowledge threshold. section 10.3.6

How AI Agents in Action, Second Edition covers it

How deep it goes
Defines three monitoring functions and shows a boundary-scoring implementation; does not establish that verbal confidence alone is reliable.
Examples
Uses confidently wrong production answers and a workspace-based boundary check using retrieval relevance, memory hits, and confidence.
What it assumes
Introduces cognition and metacognition in agent-engineering terms while building on prior reasoning patterns and the agentic loop.
What you can do after
Build it from scratch as workspace-based monitoring that checks confidence, detects stalled progress, and recognizes knowledge boundaries.
How it connects
Connects cognition, confidence calibration, stagnation detection, knowledge boundary awareness, cognitive workspaces, and attention routing.

Also explained in

Compare how 2 books explain metacognition →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of AI Agents in Action, Second Edition. The section links point to the parts of the book it draws on.