Entropic 2.3.8
Local-first agentic inference engine
Loading...
Searching...
No Matches
entropic::ContextManager Class Reference

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.
 

Detailed Description

Handles context management for the agentic loop.

Subsystem of AgentEngine. Manages context limit refresh, tool result pruning, context warning injection, and compaction.

Version
1.8.4

Definition at line 38 of file context_manager.h.

Constructor & Destructor Documentation

◆ ContextManager()

entropic::ContextManager::ContextManager ( CompactionManager compaction,
EngineCallbacks callbacks,
ContextManagerHooks  hooks = {} 
)

Construct a context manager.

Parameters
compactionCompaction manager (shared reference).
callbacksEngine callbacks (shared reference).
hooksEngine-level hooks.
Version
1.8.4
Parameters
compactionCompaction manager reference.
callbacksEngine callbacks reference.
hooksEngine-level hooks.

Definition at line 23 of file context_manager.cpp.

Member Function Documentation

◆ check_compaction()

void entropic::ContextManager::check_compaction ( LoopContext ctx,
bool  force = false 
)

Check and perform compaction if needed.

Parameters
ctxLoop context.
forceBypass threshold check.
Version
1.8.4
Parameters
ctxLoop context.
forceBypass threshold check.

Definition at line 223 of file context_manager.cpp.

◆ fire_post_compact_hooks()

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.

Parameters
ctxLoop context.
old_countToken count before compaction.
new_countToken count after compaction.
ctxLoop context.
old_countToken count before compaction.
new_countToken count after compaction.

Definition at line 277 of file context_manager.cpp.

◆ fire_pre_compact_hook()

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.

Parameters
ctxLoop context.
forceWhether this is a forced compaction.
Returns
true if a hook cancelled compaction.
Parameters
ctxLoop context.
forceWhether this is a forced compaction.
Returns
true if a hook cancelled compaction.

Definition at line 252 of file context_manager.cpp.

◆ inject_context_warning()

void entropic::ContextManager::inject_context_warning ( LoopContext ctx)

Inject context usage warning if over threshold.

Parameters
ctxLoop context.
Version
1.8.4
Parameters
ctxLoop context.

Definition at line 187 of file context_manager.cpp.

◆ prune_old_tool_results()

void entropic::ContextManager::prune_old_tool_results ( LoopContext ctx)

Auto-prune tool results older than TTL iterations.

Parameters
ctxLoop context.
Version
1.8.4

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.

Parameters
ctxLoop context.

Definition at line 123 of file context_manager.cpp.

◆ prune_tool_results()

std::pair< int, int > entropic::ContextManager::prune_tool_results ( LoopContext ctx,
int  keep_recent 
)

Replace old tool results with stubs.

Parameters
ctxLoop context.
keep_recentNumber of recent results to keep.
Returns
(pruned_count, freed_chars).
Version
1.8.4
Parameters
ctxLoop context.
keep_recentNumber of recent results to keep.
Returns
(pruned_count, freed_chars).

Definition at line 60 of file context_manager.cpp.

◆ refresh_context_limit()

void entropic::ContextManager::refresh_context_limit ( LoopContext ctx,
int  context_length 
)

Refresh context limit based on tier config.

Refresh context limit from tier config.

Parameters
ctxLoop context.
context_lengthNew context length (0 = no change).
Version
1.8.4
Parameters
ctxLoop context (unused, kept for interface consistency).
context_lengthNew max tokens (0 = no change).

Definition at line 38 of file context_manager.cpp.

◆ set_hooks()

void entropic::ContextManager::set_hooks ( const HookInterface &  hooks)
inline

Set the hook dispatch interface.

Parameters
hooksHook dispatch interface. @utility
Version
1.9.1

Definition at line 125 of file context_manager.h.


The documentation for this class was generated from the following files: