Watch
0
0
Fork
You've already forked hyperhive
0

swarm: a soft context limit per agent, as a percent of the window, applied at turn end

This commit is contained in:
damocles 2026-11-15 15:13:50 +01:00 • committed by mara
commit 1e03979836

View file

@ -367,6 +367,11 @@ pub struct Bus {
/// limit the model enforces, which may differ from the default
/// (e.g. 200 k active window on a 1 M cache-enabled model).
api_context_window: Arc<Mutex<Option<u64>>>,
/// The swarm's soft context limit, as a percent of the context window
/// (`soft_context_percent` of the agent's `agent-inference` key): the
/// compaction policy compacts at it instead of the harness's own
/// watermark. `None` until the swarm sets one.
soft_context_percent: Arc<Mutex<Option<u8>>>,
/// Resolved model id from the most recent turn's `assistant` events
/// (the API-echoed `message.model`, e.g. `claude-opus-4-8`), as
/// opposed to the requested `--model` name which may be a short
@ -419,6 +424,7 @@ impl Bus {
tool_calls: Arc::new(Mutex::new(std::collections::HashMap::new())),
last_turn_ended_unix: Arc::new(AtomicI64::new(0)),
api_context_window: Arc::new(Mutex::new(None)),
soft_context_percent: Arc::new(Mutex::new(None)),
last_resolved_model: Arc::new(Mutex::new(None)),
}
}
@ -700,6 +706,17 @@ impl Bus {
*self.api_context_window.lock().unwrap()
}
/// Set (or clear, with `None`) the swarm's soft context limit.
pub fn set_soft_context_percent(&self, percent: Option<u8>) {
*self.soft_context_percent.lock().unwrap() = percent;
}
/// The swarm's soft context limit, as a percent of the window.
#[must_use]
pub fn soft_context_percent(&self) -> Option<u8> {
*self.soft_context_percent.lock().unwrap()
}
/// The effective context window for `model`: the API-reported window if a
/// turn has completed (`api_context_window`), else the per-model default
/// ([`context_window_tokens`]). Single accessor so the state + dashboard