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
|
|
@ -224,47 +224,11 @@ pub fn configured_effort() -> Option<&'static str> {
|
|||
.map(|s| &*Box::leak(s.into_boxed_str()))
|
||||
}
|
||||
|
||||
/// Context-window size in tokens per model family, keyed by a substring
|
||||
/// of the model name (`"sonnet"` matches `"claude-sonnet-4-5"`).
|
||||
const CONTEXT_WINDOW_DEFAULTS: [(&str, u64); 3] = [
|
||||
("haiku", 200_000),
|
||||
("sonnet", 1_000_000),
|
||||
("opus", 1_000_000),
|
||||
];
|
||||
|
||||
/// Context-window size in tokens for a given model name, used until a
|
||||
/// completed turn reports the real window (`Bus::effective_context_window`
|
||||
/// prefers that one).
|
||||
///
|
||||
/// Resolution order (first match wins):
|
||||
/// 1. [`CONTEXT_WINDOW_DEFAULTS`] — the family key, case-insensitively,
|
||||
/// is a substring of the model name.
|
||||
/// 2. `HIVE_CONTEXT_WINDOW_TOKENS` — single global override (any model).
|
||||
/// 3. Hard fallback: `200_000`.
|
||||
#[must_use]
|
||||
pub fn context_window_tokens(model: &str) -> u64 {
|
||||
let m = model.to_ascii_lowercase();
|
||||
if let Some((_, tokens)) = CONTEXT_WINDOW_DEFAULTS
|
||||
.iter()
|
||||
.find(|(family, _)| m.contains(family))
|
||||
{
|
||||
return *tokens;
|
||||
}
|
||||
// Global override (single value, any model).
|
||||
if let Ok(s) = std::env::var("HIVE_CONTEXT_WINDOW_TOKENS")
|
||||
&& let Ok(v) = s.trim().parse::<u64>()
|
||||
&& v > 0
|
||||
{
|
||||
return v;
|
||||
}
|
||||
200_000
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{
|
||||
DEFAULT_EFFORT, DEFAULT_MODEL, Source, context_window_tokens, effort_from, model_from,
|
||||
read_harness_state, write_harness_state,
|
||||
DEFAULT_EFFORT, DEFAULT_MODEL, Source, effort_from, model_from, read_harness_state,
|
||||
write_harness_state,
|
||||
};
|
||||
|
||||
/// A state file an older harness wrote, with the `active_model` nothing
|
||||
|
|
@ -310,17 +274,6 @@ mod tests {
|
|||
assert_eq!(stored["needs_login"], true);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn context_window_defaults_per_model_family() {
|
||||
assert_eq!(context_window_tokens("claude-haiku-4-5"), 200_000);
|
||||
assert_eq!(context_window_tokens("haiku"), 200_000);
|
||||
assert_eq!(context_window_tokens("claude-sonnet-4-5"), 1_000_000);
|
||||
assert_eq!(context_window_tokens("Claude-Sonnet-4-6"), 1_000_000);
|
||||
assert_eq!(context_window_tokens("sonnet"), 1_000_000);
|
||||
assert_eq!(context_window_tokens("claude-opus-4-1"), 1_000_000);
|
||||
assert_eq!(context_window_tokens("opus"), 1_000_000);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn compiled_default_effort_matches_claude_settings() {
|
||||
// The value baked into prompts/claude-settings.json.
|
||||
|
|
|
|||
Loading…
Reference in a new issue