mirror of
https://github.com/block/buzz.git
synced 2026-11-28 04:01:45 +00:00
feat(buzz-agent): config parity — thinking effort, model switching, normalized token limits (#1470)
Signed-off-by: Will Pfleger <pfleger.will@gmail.com> Co-authored-by: npub1mn7jgtj4w2pd0g0zeuhxsa6jy6p0rewxz4kujt98my82ahfmp72sxjexk7 <dcfd242e557282d7a1e2cf2e6877522682f1e5c6156dc92ca7d90eaedd3b0f95@sprout-oss.stage.blox.sqprod.co>
This commit is contained in:
@@ -404,6 +404,8 @@ mod tests {
|
||||
config_file_format: Some("yaml"),
|
||||
supports_acp_native_config: true,
|
||||
thinking_env_var: Some("GOOSE_THINKING_EFFORT"),
|
||||
max_tokens_env_var: Some("GOOSE_MAX_TOKENS"),
|
||||
context_limit_env_var: Some("GOOSE_CONTEXT_LIMIT"),
|
||||
required_normalized_fields: &["model", "provider"],
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,6 +44,8 @@ pub(crate) fn read_config_surface(
|
||||
let required_fields: &[&str] = runtime_meta
|
||||
.map(|m| m.required_normalized_fields)
|
||||
.unwrap_or(&[]);
|
||||
let max_tokens_env_var = runtime_meta.and_then(|m| m.max_tokens_env_var);
|
||||
let context_limit_env_var = runtime_meta.and_then(|m| m.context_limit_env_var);
|
||||
|
||||
// Tier 1b: ACP configOptions from session cache.
|
||||
// For unstable/switchable agents, current_model comes from the `models`
|
||||
@@ -95,25 +97,16 @@ pub(crate) fn read_config_surface(
|
||||
is_pre_spawn,
|
||||
session_cache,
|
||||
),
|
||||
max_output_tokens: file_config
|
||||
.max_output_tokens
|
||||
.as_ref()
|
||||
.map(|v| NormalizedField {
|
||||
value: Some(v.clone()),
|
||||
origin: ConfigOrigin::ConfigFile,
|
||||
write_via: ConfigWriteMechanism::ReadOnly,
|
||||
overridden_value: None,
|
||||
overridden_origin: None,
|
||||
is_required: false,
|
||||
}),
|
||||
context_limit: file_config.context_limit.as_ref().map(|v| NormalizedField {
|
||||
value: Some(v.clone()),
|
||||
origin: ConfigOrigin::ConfigFile,
|
||||
write_via: ConfigWriteMechanism::ReadOnly,
|
||||
overridden_value: None,
|
||||
overridden_origin: None,
|
||||
is_required: false,
|
||||
}),
|
||||
max_output_tokens: build_numeric_env_field(
|
||||
max_tokens_env_var,
|
||||
&record.env_vars,
|
||||
&file_config.max_output_tokens,
|
||||
),
|
||||
context_limit: build_numeric_env_field(
|
||||
context_limit_env_var,
|
||||
&record.env_vars,
|
||||
&file_config.context_limit,
|
||||
),
|
||||
system_prompt: build_system_prompt_field(
|
||||
&record
|
||||
.system_prompt
|
||||
@@ -142,6 +135,8 @@ pub(crate) fn read_config_surface(
|
||||
model_env_var,
|
||||
provider_env_var,
|
||||
thinking_env_var,
|
||||
max_tokens_env_var,
|
||||
context_limit_env_var,
|
||||
Some("BUZZ_ACP_SYSTEM_PROMPT"),
|
||||
]
|
||||
.into_iter()
|
||||
@@ -452,6 +447,39 @@ fn build_thinking_field(
|
||||
})
|
||||
}
|
||||
|
||||
/// Numeric fields (max_output_tokens, context_limit) — env-var tier wins over
|
||||
/// config-file tier. When an env var key is given and present in the record's
|
||||
/// env_vars map the field is BuzzExplicit + RespawnWithEnvVar; otherwise if the
|
||||
/// config file supplied a value it is ConfigFile + ReadOnly; otherwise None.
|
||||
fn build_numeric_env_field(
|
||||
env_var: Option<&'static str>,
|
||||
record_env: &std::collections::BTreeMap<String, String>,
|
||||
file_value: &Option<String>,
|
||||
) -> Option<NormalizedField> {
|
||||
if let Some(key) = env_var {
|
||||
if let Some(v) = record_env.get(key) {
|
||||
return Some(NormalizedField {
|
||||
value: Some(v.clone()),
|
||||
origin: ConfigOrigin::BuzzExplicit,
|
||||
write_via: ConfigWriteMechanism::RespawnWithEnvVar {
|
||||
env_key: key.to_string(),
|
||||
},
|
||||
overridden_value: file_value.clone(),
|
||||
overridden_origin: file_value.as_ref().map(|_| ConfigOrigin::ConfigFile),
|
||||
is_required: false,
|
||||
});
|
||||
}
|
||||
}
|
||||
file_value.as_ref().map(|v| NormalizedField {
|
||||
value: Some(v.clone()),
|
||||
origin: ConfigOrigin::ConfigFile,
|
||||
write_via: ConfigWriteMechanism::ReadOnly,
|
||||
overridden_value: None,
|
||||
overridden_origin: None,
|
||||
is_required: false,
|
||||
})
|
||||
}
|
||||
|
||||
/// Record/env prompt wins (BuzzExplicit, respawnable); a config-file prompt it
|
||||
/// shadows is reported as the overridden secondary. A config-file-only prompt
|
||||
/// — no record/env value to shadow it — is surfaced directly (read-only)
|
||||
|
||||
@@ -33,6 +33,8 @@ fn test_runtime() -> &'static KnownAcpRuntime {
|
||||
config_file_format: Some("yaml"),
|
||||
supports_acp_native_config: true,
|
||||
thinking_env_var: Some("GOOSE_THINKING_EFFORT"),
|
||||
max_tokens_env_var: Some("GOOSE_MAX_TOKENS"),
|
||||
context_limit_env_var: Some("GOOSE_CONTEXT_LIMIT"),
|
||||
required_normalized_fields: &["model", "provider"],
|
||||
}
|
||||
}
|
||||
@@ -495,3 +497,165 @@ fn extra_env_var_skipped_when_already_in_file_config_extra() {
|
||||
"normalized thinking key must not appear in advanced"
|
||||
);
|
||||
}
|
||||
|
||||
// ── buzz-agent normalized env-var field tests ───────────────────────────────
|
||||
//
|
||||
// buzz-agent uses env vars (not a config file) for max_output_tokens and
|
||||
// context_limit. build_numeric_env_field must surface these as BuzzExplicit
|
||||
// when the env var is present in record.env_vars, and must not double-surface
|
||||
// them in the advanced tier.
|
||||
|
||||
fn buzz_agent_runtime() -> &'static KnownAcpRuntime {
|
||||
&KnownAcpRuntime {
|
||||
id: "buzz-agent",
|
||||
label: "Buzz Agent",
|
||||
commands: &["buzz-agent"],
|
||||
aliases: &[],
|
||||
avatar_url: "",
|
||||
mcp_command: None,
|
||||
mcp_hooks: false,
|
||||
underlying_cli: None,
|
||||
cli_install_commands: &[],
|
||||
adapter_install_commands: &[],
|
||||
install_instructions_url: "",
|
||||
cli_install_hint: "",
|
||||
adapter_install_hint: "",
|
||||
skill_dir: None,
|
||||
supports_acp_model_switching: true,
|
||||
model_env_var: Some("BUZZ_AGENT_MODEL"),
|
||||
provider_env_var: Some("BUZZ_AGENT_PROVIDER"),
|
||||
provider_locked: false,
|
||||
default_env: &[],
|
||||
config_file_path: None,
|
||||
config_file_format: None,
|
||||
supports_acp_native_config: false,
|
||||
thinking_env_var: Some("BUZZ_AGENT_THINKING_EFFORT"),
|
||||
max_tokens_env_var: Some("BUZZ_AGENT_MAX_OUTPUT_TOKENS"),
|
||||
context_limit_env_var: Some("BUZZ_AGENT_MAX_CONTEXT_TOKENS"),
|
||||
required_normalized_fields: &["model", "provider"],
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn buzz_agent_max_output_tokens_from_env_is_buzz_explicit() {
|
||||
let mut record = test_record();
|
||||
record.env_vars.insert(
|
||||
"BUZZ_AGENT_MAX_OUTPUT_TOKENS".to_string(),
|
||||
"8192".to_string(),
|
||||
);
|
||||
let runtime = buzz_agent_runtime();
|
||||
|
||||
let surface = read_config_surface(&record, Some(runtime), None, None);
|
||||
|
||||
let field = surface.normalized.max_output_tokens.unwrap();
|
||||
assert_eq!(field.value.as_deref(), Some("8192"));
|
||||
assert_eq!(field.origin, ConfigOrigin::BuzzExplicit);
|
||||
assert!(matches!(
|
||||
field.write_via,
|
||||
ConfigWriteMechanism::RespawnWithEnvVar { ref env_key }
|
||||
if env_key == "BUZZ_AGENT_MAX_OUTPUT_TOKENS"
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn buzz_agent_context_limit_from_env_is_buzz_explicit() {
|
||||
let mut record = test_record();
|
||||
record.env_vars.insert(
|
||||
"BUZZ_AGENT_MAX_CONTEXT_TOKENS".to_string(),
|
||||
"100000".to_string(),
|
||||
);
|
||||
let runtime = buzz_agent_runtime();
|
||||
|
||||
let surface = read_config_surface(&record, Some(runtime), None, None);
|
||||
|
||||
let field = surface.normalized.context_limit.unwrap();
|
||||
assert_eq!(field.value.as_deref(), Some("100000"));
|
||||
assert_eq!(field.origin, ConfigOrigin::BuzzExplicit);
|
||||
assert!(matches!(
|
||||
field.write_via,
|
||||
ConfigWriteMechanism::RespawnWithEnvVar { ref env_key }
|
||||
if env_key == "BUZZ_AGENT_MAX_CONTEXT_TOKENS"
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn buzz_agent_max_tokens_absent_when_no_env_var_or_file() {
|
||||
// buzz-agent has no config file, and env var is not set.
|
||||
let record = test_record();
|
||||
let runtime = buzz_agent_runtime();
|
||||
|
||||
let surface = read_config_surface(&record, Some(runtime), None, None);
|
||||
|
||||
assert!(
|
||||
surface.normalized.max_output_tokens.is_none(),
|
||||
"max_output_tokens must be None when env var not set and no config file"
|
||||
);
|
||||
assert!(
|
||||
surface.normalized.context_limit.is_none(),
|
||||
"context_limit must be None when env var not set and no config file"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn buzz_agent_max_tokens_env_var_not_double_surfaced_in_advanced() {
|
||||
let mut record = test_record();
|
||||
record.env_vars.insert(
|
||||
"BUZZ_AGENT_MAX_OUTPUT_TOKENS".to_string(),
|
||||
"4096".to_string(),
|
||||
);
|
||||
record.env_vars.insert(
|
||||
"BUZZ_AGENT_MAX_CONTEXT_TOKENS".to_string(),
|
||||
"50000".to_string(),
|
||||
);
|
||||
let runtime = buzz_agent_runtime();
|
||||
|
||||
let surface = read_config_surface(&record, Some(runtime), None, None);
|
||||
|
||||
let advanced_keys: Vec<&str> = surface.advanced.iter().map(|f| f.key.as_str()).collect();
|
||||
assert!(
|
||||
!advanced_keys.contains(&"BUZZ_AGENT_MAX_OUTPUT_TOKENS"),
|
||||
"max_output_tokens must not appear in advanced when normalized"
|
||||
);
|
||||
assert!(
|
||||
!advanced_keys.contains(&"BUZZ_AGENT_MAX_CONTEXT_TOKENS"),
|
||||
"context_limit must not appear in advanced when normalized"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn buzz_agent_thinking_effort_from_env_is_buzz_explicit() {
|
||||
let mut record = test_record();
|
||||
record
|
||||
.env_vars
|
||||
.insert("BUZZ_AGENT_THINKING_EFFORT".to_string(), "high".to_string());
|
||||
let runtime = buzz_agent_runtime();
|
||||
|
||||
let surface = read_config_surface(&record, Some(runtime), None, None);
|
||||
|
||||
let field = surface.normalized.thinking_effort.unwrap();
|
||||
assert_eq!(field.value.as_deref(), Some("high"));
|
||||
assert_eq!(field.origin, ConfigOrigin::BuzzExplicit);
|
||||
assert!(matches!(
|
||||
field.write_via,
|
||||
ConfigWriteMechanism::RespawnWithEnvVar { ref env_key }
|
||||
if env_key == "BUZZ_AGENT_THINKING_EFFORT"
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn buzz_agent_thinking_effort_env_var_not_double_surfaced_in_advanced() {
|
||||
let mut record = test_record();
|
||||
record.env_vars.insert(
|
||||
"BUZZ_AGENT_THINKING_EFFORT".to_string(),
|
||||
"medium".to_string(),
|
||||
);
|
||||
let runtime = buzz_agent_runtime();
|
||||
|
||||
let surface = read_config_surface(&record, Some(runtime), None, None);
|
||||
|
||||
let advanced_keys: Vec<&str> = surface.advanced.iter().map(|f| f.key.as_str()).collect();
|
||||
assert!(
|
||||
!advanced_keys.contains(&"BUZZ_AGENT_THINKING_EFFORT"),
|
||||
"thinking_effort must not appear in advanced when normalized"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -47,6 +47,11 @@ pub(crate) struct KnownAcpRuntime {
|
||||
pub config_file_format: Option<&'static str>,
|
||||
pub supports_acp_native_config: bool, // tier 1a: config/read+write
|
||||
pub thinking_env_var: Option<&'static str>,
|
||||
/// Env var for normalizing `max_output_tokens`. `None` when the harness
|
||||
/// does not have a first-class env var for this field (config-file only).
|
||||
pub max_tokens_env_var: Option<&'static str>,
|
||||
/// Env var for normalizing `context_limit`. `None` when not applicable.
|
||||
pub context_limit_env_var: Option<&'static str>,
|
||||
/// Normalized field keys that must be set for this harness to function.
|
||||
/// Used by the config bridge to mark fields as required in the UI.
|
||||
/// Keys match the camelCase names used in `NormalizedConfig` (e.g. "model", "provider").
|
||||
@@ -106,6 +111,8 @@ const KNOWN_ACP_RUNTIMES: &[KnownAcpRuntime] = &[
|
||||
config_file_format: Some("yaml"),
|
||||
supports_acp_native_config: true,
|
||||
thinking_env_var: Some("GOOSE_THINKING_EFFORT"),
|
||||
max_tokens_env_var: Some("GOOSE_MAX_TOKENS"),
|
||||
context_limit_env_var: Some("GOOSE_CONTEXT_LIMIT"),
|
||||
required_normalized_fields: &["model", "provider"],
|
||||
},
|
||||
KnownAcpRuntime {
|
||||
@@ -132,6 +139,8 @@ const KNOWN_ACP_RUNTIMES: &[KnownAcpRuntime] = &[
|
||||
config_file_format: Some("json"),
|
||||
supports_acp_native_config: false,
|
||||
thinking_env_var: None,
|
||||
max_tokens_env_var: None,
|
||||
context_limit_env_var: None,
|
||||
required_normalized_fields: &[],
|
||||
},
|
||||
KnownAcpRuntime {
|
||||
@@ -158,6 +167,8 @@ const KNOWN_ACP_RUNTIMES: &[KnownAcpRuntime] = &[
|
||||
config_file_format: Some("toml"),
|
||||
supports_acp_native_config: false,
|
||||
thinking_env_var: None,
|
||||
max_tokens_env_var: None,
|
||||
context_limit_env_var: None,
|
||||
required_normalized_fields: &[],
|
||||
},
|
||||
KnownAcpRuntime {
|
||||
@@ -183,7 +194,9 @@ const KNOWN_ACP_RUNTIMES: &[KnownAcpRuntime] = &[
|
||||
config_file_path: None,
|
||||
config_file_format: None,
|
||||
supports_acp_native_config: false,
|
||||
thinking_env_var: None,
|
||||
thinking_env_var: Some("BUZZ_AGENT_THINKING_EFFORT"),
|
||||
max_tokens_env_var: Some("BUZZ_AGENT_MAX_OUTPUT_TOKENS"),
|
||||
context_limit_env_var: Some("BUZZ_AGENT_MAX_CONTEXT_TOKENS"),
|
||||
required_normalized_fields: &["model", "provider"],
|
||||
},
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user