swarm: set the fresh-session threshold per agent
This commit is contained in:
parent
49ee678117
commit
5175d3663e
1 changed files with 154 additions and 32 deletions
|
|
@ -49,6 +49,7 @@ fn settings_view(v: AgentInference) -> InferenceSettings {
|
|||
subagent_models: v.subagent_models,
|
||||
max_subagents: v.max_subagents,
|
||||
soft_context_percent: v.soft_context_percent,
|
||||
fresh_session_percent: v.fresh_session_percent,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -100,12 +101,27 @@ pub(crate) fn into_stored(settings: InferenceSettings) -> Result<AgentInference,
|
|||
"soft_context_percent is {percent}; it is from {MIN_SOFT_CONTEXT_PERCENT} to {MAX_SOFT_CONTEXT_PERCENT}, or left out for the harness's own watermark"
|
||||
));
|
||||
}
|
||||
if let Some(percent) = settings.fresh_session_percent {
|
||||
if !(MIN_SOFT_CONTEXT_PERCENT..=MAX_SOFT_CONTEXT_PERCENT).contains(&percent) {
|
||||
return Err(format!(
|
||||
"fresh_session_percent is {percent}; it is from {MIN_SOFT_CONTEXT_PERCENT} to {MAX_SOFT_CONTEXT_PERCENT}, or left out for the harness's own half"
|
||||
));
|
||||
}
|
||||
if let Some(soft) = settings.soft_context_percent
|
||||
&& percent > soft
|
||||
{
|
||||
return Err(format!(
|
||||
"fresh_session_percent is {percent}, above soft_context_percent {soft}; the agent compacts at the soft limit, so a fresh start above it would never happen"
|
||||
));
|
||||
}
|
||||
}
|
||||
Ok(AgentInference {
|
||||
model: settings.model,
|
||||
effort: settings.effort,
|
||||
subagent_models: settings.subagent_models,
|
||||
max_subagents: settings.max_subagents,
|
||||
soft_context_percent: settings.soft_context_percent,
|
||||
fresh_session_percent: settings.fresh_session_percent,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -261,8 +277,8 @@ pub(crate) async fn get_agent_inference(
|
|||
ones whole", body = InferenceSettings),
|
||||
(status = 400, description = "not an identifier, not declared on any hive, or a \
|
||||
model name is empty, has whitespace, starts with `-`, or is listed \
|
||||
twice, or `max_subagents` is above 32, or `soft_context_percent` is outside \
|
||||
its range (problem+json)",
|
||||
twice, or `max_subagents` is above 32, or `soft_context_percent` or `fresh_session_percent` is outside \
|
||||
its range, or the fresh-session percent is above the soft limit (problem+json)",
|
||||
body = String),
|
||||
(status = 422, description = "an unknown field, or an effort that is not one of \
|
||||
the five levels"),
|
||||
|
|
@ -406,6 +422,7 @@ mod tests {
|
|||
subagent_models: Some(vec!["haiku".to_owned()]),
|
||||
max_subagents: None,
|
||||
soft_context_percent: None,
|
||||
fresh_session_percent: None,
|
||||
}
|
||||
);
|
||||
assert_eq!(
|
||||
|
|
@ -590,6 +607,43 @@ mod tests {
|
|||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fresh_session_percent_outside_its_range_is_refused() {
|
||||
for percent in [
|
||||
0,
|
||||
MIN_SOFT_CONTEXT_PERCENT - 1,
|
||||
MAX_SOFT_CONTEXT_PERCENT + 1,
|
||||
] {
|
||||
let json = format!(r#"{{"fresh_session_percent":{percent}}}"#);
|
||||
assert!(into_stored(settings(&json).unwrap()).is_err(), "{json}");
|
||||
}
|
||||
assert!(settings(r#"{"fresh_session_percent":-1}"#).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fresh_session_percent_in_range_is_stored() {
|
||||
for percent in [MIN_SOFT_CONTEXT_PERCENT, 50, MAX_SOFT_CONTEXT_PERCENT] {
|
||||
let json = format!(r#"{{"fresh_session_percent":{percent}}}"#);
|
||||
let stored = into_stored(settings(&json).unwrap()).unwrap();
|
||||
assert_eq!(stored.fresh_session_percent, Some(percent));
|
||||
}
|
||||
}
|
||||
|
||||
/// The agent compacts at the soft limit, so a fresh-session threshold above
|
||||
/// it could never be reached.
|
||||
#[test]
|
||||
fn fresh_session_percent_above_the_soft_limit_is_refused() {
|
||||
let above = r#"{"soft_context_percent":40,"fresh_session_percent":41}"#;
|
||||
assert!(into_stored(settings(above).unwrap()).is_err());
|
||||
for ok in [
|
||||
r#"{"soft_context_percent":40,"fresh_session_percent":40}"#,
|
||||
r#"{"soft_context_percent":40,"fresh_session_percent":10}"#,
|
||||
r#"{"fresh_session_percent":90}"#,
|
||||
] {
|
||||
assert!(into_stored(settings(ok).unwrap()).is_ok(), "{ok}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn max_subagents_in_range_is_stored() {
|
||||
for max in [0, 1, 3, MAX_SUBAGENTS] {
|
||||
|
|
|
|||
Loading…
Reference in a new issue