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
|
|
@ -20,8 +20,8 @@ use swarm_wire::agent_inference::Source;
|
|||
use tokio::sync::broadcast;
|
||||
|
||||
use crate::harness_state::{
|
||||
configured_effort, configured_model, context_window_tokens, local_effort, local_model,
|
||||
read_harness_state, write_harness_state,
|
||||
configured_effort, configured_model, local_effort, local_model, read_harness_state,
|
||||
write_harness_state,
|
||||
};
|
||||
|
||||
const CHANNEL_CAPACITY: usize = 256;
|
||||
|
|
@ -361,11 +361,11 @@ pub struct Bus {
|
|||
last_turn_ended_unix: Arc<AtomicI64>,
|
||||
/// Per-inference context-window size as reported by the Anthropic API
|
||||
/// in the stream-json `result` event (`modelUsage.*.contextWindow`).
|
||||
/// Set by the stdout pump on every completed turn. Takes precedence
|
||||
/// over the per-model defaults in `harness_state::context_window_tokens`
|
||||
/// for compaction watermark calculations — it reflects the actual
|
||||
/// limit the model enforces, which may differ from the default
|
||||
/// (e.g. 200 k active window on a 1 M cache-enabled model).
|
||||
/// Set by the stdout pump on every completed turn. The only source of the
|
||||
/// window: there is no per-model table, so it is `None` until the first
|
||||
/// turn of this process completes, and everything that divides by it
|
||||
/// (the compaction watermarks, the context fill the swarm shows) waits
|
||||
/// for it.
|
||||
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
|
||||
|
|
@ -717,16 +717,6 @@ impl Bus {
|
|||
*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
|
||||
/// endpoints agree by construction.
|
||||
#[must_use]
|
||||
pub fn effective_context_window(&self, model: &str) -> u64 {
|
||||
self.api_context_window()
|
||||
.unwrap_or_else(|| context_window_tokens(model))
|
||||
}
|
||||
|
||||
/// Walk a stream-json value for `tool_use` blocks and bump the
|
||||
/// per-turn counter for each one we find. Called by the stdout
|
||||
/// pump on every parsed line. Cheap when the line isn't an
|
||||
|
|
|
|||
Loading…
Reference in a new issue