|
Entropic 2.3.8
Local-first agentic inference engine
|
Handles context management for the agentic loop. More...
#include <entropic/core/context_manager.h>
Public Member Functions | |
| ContextManager (CompactionManager &compaction, EngineCallbacks &callbacks, ContextManagerHooks hooks={}) | |
| Construct a context manager. | |
| void | refresh_context_limit (LoopContext &ctx, int context_length) |
| Refresh context limit based on tier config. | |
| std::pair< int, int > | prune_tool_results (LoopContext &ctx, int keep_recent) |
| Replace old tool results with stubs. | |
| void | prune_old_tool_results (LoopContext &ctx) |
| Auto-prune tool results older than TTL iterations. | |
| void | inject_context_warning (LoopContext &ctx) |
| Inject context usage warning if over threshold. | |
| void | check_compaction (LoopContext &ctx, bool force=false) |
| Check and perform compaction if needed. | |
| bool | fire_pre_compact_hook (LoopContext &ctx, bool force) |
| Fire ON_PRE_COMPACT; report whether compaction was cancelled. | |
| void | fire_post_compact_hooks (LoopContext &ctx, int old_count, int new_count) |
| Fire post-compaction callbacks + ON_POST_COMPACT hook. | |
| void | set_hooks (const HookInterface &hooks) |
| Set the hook dispatch interface. | |
Handles context management for the agentic loop.
Subsystem of AgentEngine. Manages context limit refresh, tool result pruning, context warning injection, and compaction.
Definition at line 38 of file context_manager.h.
| entropic::ContextManager::ContextManager | ( | CompactionManager & | compaction, |
| EngineCallbacks & | callbacks, | ||
| ContextManagerHooks | hooks = {} |
||
| ) |
Construct a context manager.
| compaction | Compaction manager (shared reference). |
| callbacks | Engine callbacks (shared reference). |
| hooks | Engine-level hooks. |
| compaction | Compaction manager reference. |
| callbacks | Engine callbacks reference. |
| hooks | Engine-level hooks. |
Definition at line 23 of file context_manager.cpp.
| void entropic::ContextManager::check_compaction | ( | LoopContext & | ctx, |
| bool | force = false |
||
| ) |
Check and perform compaction if needed.
| ctx | Loop context. |
| force | Bypass threshold check. |
| ctx | Loop context. |
| force | Bypass threshold check. |
Definition at line 223 of file context_manager.cpp.
| void entropic::ContextManager::fire_post_compact_hooks | ( | LoopContext & | ctx, |
| int | old_count, | ||
| int | new_count | ||
| ) |
Fire post-compaction callbacks + ON_POST_COMPACT hook.
Extracted from check_compaction to keep it knots-clean.
| ctx | Loop context. |
| old_count | Token count before compaction. |
| new_count | Token count after compaction. |
| ctx | Loop context. |
| old_count | Token count before compaction. |
| new_count | Token count after compaction. |
Definition at line 277 of file context_manager.cpp.
| bool entropic::ContextManager::fire_pre_compact_hook | ( | LoopContext & | ctx, |
| bool | force | ||
| ) |
Fire ON_PRE_COMPACT; report whether compaction was cancelled.
Extracted from check_compaction to keep it knots-clean.
| ctx | Loop context. |
| force | Whether this is a forced compaction. |
| ctx | Loop context. |
| force | Whether this is a forced compaction. |
Definition at line 252 of file context_manager.cpp.
| void entropic::ContextManager::inject_context_warning | ( | LoopContext & | ctx | ) |
Inject context usage warning if over threshold.
| ctx | Loop context. |
| ctx | Loop context. |
Definition at line 187 of file context_manager.cpp.
| void entropic::ContextManager::prune_old_tool_results | ( | LoopContext & | ctx | ) |
Auto-prune tool results older than TTL iterations.
| ctx | Loop context. |
Issue #6 (v2.1.3): pre-2.1.3 this fired on every iteration regardless of context fill. A 25-minute session against a 32K-token context window observed 78 prune events even though peak fill was 29% — dropping evidence that wasn't crowding anything out and forcing the tier to re-issue duplicate tool calls for data it already had (16 Duplicate tool call warnings in the affected session). Now gated on context fill: below warning_threshold_percent (the same threshold inject_context_warning uses) prune is a no-op. At/above the threshold, prune by TTL as before. Companion fix to issue #5 (validator runs against post-prune context) — fixing this issue eliminates the bug class entirely whenever context has headroom.
| ctx | Loop context. |
Definition at line 123 of file context_manager.cpp.
| std::pair< int, int > entropic::ContextManager::prune_tool_results | ( | LoopContext & | ctx, |
| int | keep_recent | ||
| ) |
Replace old tool results with stubs.
| ctx | Loop context. |
| keep_recent | Number of recent results to keep. |
| ctx | Loop context. |
| keep_recent | Number of recent results to keep. |
Definition at line 60 of file context_manager.cpp.
| void entropic::ContextManager::refresh_context_limit | ( | LoopContext & | ctx, |
| int | context_length | ||
| ) |
Refresh context limit based on tier config.
Refresh context limit from tier config.
| ctx | Loop context. |
| context_length | New context length (0 = no change). |
| ctx | Loop context (unused, kept for interface consistency). |
| context_length | New max tokens (0 = no change). |
Definition at line 38 of file context_manager.cpp.
|
inline |
Set the hook dispatch interface.
| hooks | Hook dispatch interface. @utility |
Definition at line 125 of file context_manager.h.