# `Agentic.Loop.Stages.ContextGuard`

Checks context window usage and triggers compaction if needed.

Runs before LLMCall. Estimates the current context size from messages and
tool schemas. When usage exceeds the configured threshold (default 80%),
compacts older messages by summarizing them with a deterministic summary,
then replaces them with a compact handoff message.

Also enforces a per-session cost limit as a safety rail.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
