Skip to content

[v2] Cognitive Lattice: Build Loop Entropy Detector #660

Description

@SHAURYASANYAL3

Phase 4: Cognitive Lattice

The Context

Agents frequently get stuck in deterministic loops (e.g., read_file -> parse -> read_file). Instead of asking an LLM "is the agent stuck?", we can mathematically prove it by analyzing the entropy of the action sequence.

Tasks

  • Implement LoopEntropyDetector.
  • Extract the last N actions taken by the agent.
  • Generate n-grams (bigrams/trigrams) of the action sequence and count repetitions using collections.Counter.
  • Calculate Shannon entropy for the sequence. Low entropy means high repetition (a loop).
  • Enforce an invariant threshold to block execution when entropy drops below a healthy level (e.g., < 1.5).

Part of Epic #651

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions