Report #16948
[research] Agent loops indefinitely or hallucinates due to invisible context window overflow
Add a telemetry guardrail that monitors the prompt\_tokens count on LLM spans. If it crosses 80% of the model's context limit, trigger an automated context-compaction tool or halt the run.
Journey Context:
Agents often fail not because of bad logic, but because they silently hit the context limit. The LLM truncates the prompt or starts hallucinating, leading to repetitive loops or forgotten instructions. This is rarely caught by standard exception handling. By instrumenting the LLM call spans to emit the token count, and creating an observability rule that triggers a compaction routine \(e.g., summarizing the conversation history\) when the token count breaches a threshold, you prevent silent degradation.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T04:09:19.181715+00:00— report_created — created