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

@ -50,6 +50,10 @@ pub struct AgentInference {
/// cap.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub max_subagents: Option<u32>,
/// The percent of the model's context window at which the agent compacts,
/// in place of the harness's own watermark. `None` keeps the harness's.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub soft_context_percent: Option<u8>,
}
/// A claude `--effort` level, ascending.
@ -142,11 +146,12 @@ mod tests {
effort: Some(Effort::Xhigh),
subagent_models: Some(vec!["haiku".to_owned(), "sonnet".to_owned()]),
max_subagents: Some(3),
soft_context_percent: Some(20),
};
let encoded = serde_json::to_string(&value).unwrap();
assert_eq!(
encoded,
r#"{"model":"opus","effort":"xhigh","subagent_models":["haiku","sonnet"],"max_subagents":3}"#
r#"{"model":"opus","effort":"xhigh","subagent_models":["haiku","sonnet"],"max_subagents":3,"soft_context_percent":20}"#
);
assert_eq!(
serde_json::from_str::<AgentInference>(&encoded).unwrap(),
@ -171,13 +176,15 @@ mod tests {
);
}
/// A value written before `max_subagents` existed decodes with no cap.
/// A value written before `max_subagents` or `soft_context_percent`
/// existed decodes with neither set.
#[test]
fn a_value_without_max_subagents_has_no_cap() {
fn a_value_without_the_caps_has_neither_set() {
let decoded: AgentInference =
serde_json::from_str(r#"{"model":"opus","effort":"high","subagent_models":["haiku"]}"#)
.unwrap();
assert_eq!(decoded.max_subagents, None);
assert_eq!(decoded.soft_context_percent, None);
assert_eq!(decoded.model.as_deref(), Some("opus"));
}