hive-agent: no hard-coded context window sizes, the window is what the API reports
This commit is contained in:
parent
4a109fa038
commit
1bfee54414
1 changed files with 47 additions and 124 deletions
|
|
@ -262,29 +262,14 @@ pub fn stall_sleep_secs() -> u64 {
|
|||
env_u64_positive("HIVE_STALL_SLEEP_SECS", DEFAULT_STALL_SLEEP_SECS)
|
||||
}
|
||||
|
||||
/// Resolve the effective context-window size for watermark calculations.
|
||||
/// Priority order (first wins):
|
||||
/// 1. API-reported window from the last `result` event's `modelUsage.*.contextWindow`.
|
||||
/// 2. `harness_state::context_window_tokens` (per-model defaults, then the
|
||||
/// `HIVE_CONTEXT_WINDOW_TOKENS` override, then 200 000).
|
||||
///
|
||||
/// The API-reported window is the authoritative per-inference active
|
||||
/// context limit. It reflects what the model actually enforces — which
|
||||
/// for models with large prompt caches (e.g. 1 M total cache) may be
|
||||
/// significantly smaller than the cache capacity (e.g. 200 k active window
|
||||
/// for `claude-sonnet-4-6`).
|
||||
fn effective_context_window(bus: &Bus) -> u64 {
|
||||
bus.api_context_window()
|
||||
.unwrap_or_else(|| crate::harness_state::context_window_tokens(&bus.model()))
|
||||
}
|
||||
|
||||
/// Resolve the auto-reset watermark. Priority order:
|
||||
/// 1. `HIVE_AUTO_RESET_WATERMARK_TOKENS` env var (explicit override).
|
||||
/// 2. 50% of `effective_context_window(bus)`.
|
||||
/// 2. 50% of the window the API last reported, or `0` before one has been.
|
||||
///
|
||||
/// `0` disables auto-reset entirely.
|
||||
fn auto_reset_watermark_tokens(bus: &Bus) -> u64 {
|
||||
env_u64("HIVE_AUTO_RESET_WATERMARK_TOKENS").unwrap_or_else(|| effective_context_window(bus) / 2)
|
||||
env_u64("HIVE_AUTO_RESET_WATERMARK_TOKENS")
|
||||
.unwrap_or_else(|| bus.api_context_window().map_or(0, |window| window / 2))
|
||||
}
|
||||
|
||||
/// Resolve the assumed cache TTL: `HIVE_CACHE_TTL_SECS` if set, else
|
||||
|
|
@ -353,10 +338,9 @@ impl CompactionPolicy for SoftLimitPolicy {
|
|||
/// Construct the agent's durable session, with a percent-of-window compaction
|
||||
/// policy that checkpoints (`CHECKPOINT_PROMPT`) before compacting; on claude
|
||||
/// also a constant title and the on-disk store. Called once at serve-loop start.
|
||||
/// `percent` comes from a boot-time env var and `default_window` is only a
|
||||
/// fallback for turns where the model didn't report a window, so a single
|
||||
/// build at startup is fine; the swarm's soft limit is read from the bus per
|
||||
/// decision.
|
||||
/// `percent` comes from a boot-time env var, so a single build at startup is
|
||||
/// fine; the window is the one each turn reports (no turn that reports none
|
||||
/// compacts), and the swarm's soft limit is read from the bus per decision.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
|
|
@ -365,7 +349,7 @@ pub fn make_session(bus: &Bus) -> Result<AgentSession> {
|
|||
let policy = SoftLimitPolicy {
|
||||
percent: PercentPolicy {
|
||||
percent: compact_percent(),
|
||||
default_window: Some(effective_context_window(bus)),
|
||||
default_window: None,
|
||||
checkpoint_prompt: Some(CHECKPOINT_PROMPT.to_string()),
|
||||
},
|
||||
bus: bus.clone(),
|
||||
|
|
|
|||
Loading…
Reference in a new issue