Make Guardian V3 routing and retrieval guidance configurable (#62372)

## Why

Guardian V3 uses fixed guidance for grouping evidence into board channels
and deciding when to retrieve more evidence. Longer routing instructions
also leave less room for evidence in the model's context window.

## What changed

Under `features.guardianv3`, add `housekeeper.routing_instructions` and
`reviewer.retrieval_instructions` to customize those strategies while
preserving the routing format and the reviewer's board and authorization
rules. Blank or omitted instructions use the built-in guidance.

Add an optional `max_instruction_tokens` cap that validates each custom
prompt separately using an estimated token count. Ignore both prompts and
the cap in project config. The `housekeeper.batch_timeout_ms` setting
controls the per-batch routing timeout and defaults to 90 seconds.

Size routing batches to fit the model's input window after accounting for
the prompt and response schema. Route the largest fitting prefix of whole
evidence records within the tool-output budget and leave the rest pending.

## Testing

Cover prompt validation, project config filtering, feature toggle merging,
and default retrieval guidance. Exercise custom prompts in model requests
and verify that routing reduces a batch under context pressure or stops
without advancing the cursor when even one record cannot fit.

GitOrigin-RevId: 83b3fcd23c680e90d2b2aea82a4a290633729658
This commit is contained in:
felixxia-oai
2026-11-18 21:56:16 +00:00
committed by copyberry
parent bc63849ff6
commit 8bbe7c7d66
23 changed files with 552 additions and 137 deletions
+27
View File
@@ -7,6 +7,7 @@ use schemars::JsonSchema;
use serde::Deserialize;
use serde::Serialize;
use std::collections::BTreeMap;
use std::num::NonZeroU32;
use std::num::NonZeroUsize;
/// Connection settings for a remote message board.
@@ -316,6 +317,32 @@ where
pub struct GuardianV3ConfigToml {
#[serde(skip_serializing_if = "Option::is_none")]
pub enabled: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub housekeeper: Option<GuardianV3HousekeeperConfigToml>,
#[serde(skip_serializing_if = "Option::is_none")]
pub reviewer: Option<GuardianV3ReviewerConfigToml>,
/// Maximum estimated tokens per custom routing or retrieval prompt. Unset means uncapped. Ignored in project config.
#[serde(skip_serializing_if = "Option::is_none")]
pub max_instruction_tokens: Option<usize>,
}
#[derive(Serialize, Deserialize, Debug, Clone, Default, PartialEq, Eq, JsonSchema)]
#[serde(deny_unknown_fields)]
pub struct GuardianV3HousekeeperConfigToml {
/// Guidance for grouping originals into channels and describing their topics. Ignored in project config.
#[serde(skip_serializing_if = "Option::is_none")]
pub routing_instructions: Option<String>,
/// Time budget for routing one batch, in milliseconds. Defaults to 90,000.
#[serde(skip_serializing_if = "Option::is_none")]
pub batch_timeout_ms: Option<NonZeroU32>,
}
#[derive(Serialize, Deserialize, Debug, Clone, Default, PartialEq, Eq, JsonSchema)]
#[serde(deny_unknown_fields)]
pub struct GuardianV3ReviewerConfigToml {
/// Guidance for searching the Guardian board and managing channel subscriptions. Ignored in project config.
#[serde(skip_serializing_if = "Option::is_none")]
pub retrieval_instructions: Option<String>,
}
impl FeatureConfig for GuardianV3ConfigToml {
+2
View File
@@ -30,6 +30,8 @@ pub use feature_configs::GuardianV2ReviewScopeConfigToml;
pub use feature_configs::GuardianV2TranscriptConfigToml;
pub use feature_configs::GuardianV2TranscriptSource;
pub use feature_configs::GuardianV3ConfigToml;
pub use feature_configs::GuardianV3HousekeeperConfigToml;
pub use feature_configs::GuardianV3ReviewerConfigToml;
pub use feature_configs::MultiAgentV2ConfigToml;
pub use feature_configs::NetworkProxyConfigToml;
pub use feature_configs::NetworkProxyDomainPermissionToml;
+37
View File
@@ -251,6 +251,43 @@ fn guardian_v3_feature_config_resolves_base_and_profile_toggles() {
}
}
#[test]
fn guardian_v3_prompt_settings_do_not_implicitly_enable_the_feature() {
let features: FeaturesToml = toml::from_str(
r#"
[guardianv3.housekeeper]
routing_instructions = "Group related deployment evidence."
batch_timeout_ms = 15000
[guardianv3.reviewer]
retrieval_instructions = "Search before assessing deployments."
"#,
)
.expect("Guardian V3 settings should deserialize");
assert!(features.entries().is_empty());
assert_eq!(
features.guardianv3,
Some(FeatureToml::Config(crate::GuardianV3ConfigToml {
enabled: None,
housekeeper: Some(crate::GuardianV3HousekeeperConfigToml {
routing_instructions: Some("Group related deployment evidence.".to_owned()),
batch_timeout_ms: std::num::NonZeroU32::new(15_000),
}),
reviewer: Some(crate::GuardianV3ReviewerConfigToml {
retrieval_instructions: Some("Search before assessing deployments.".to_owned()),
}),
max_instruction_tokens: None,
}))
);
}
#[test]
fn guardian_v3_rejects_a_zero_batch_timeout() {
assert!(
toml::from_str::<FeaturesToml>("[guardianv3.housekeeper]\nbatch_timeout_ms = 0").is_err()
);
}
#[test]
fn guardian_thread_context_is_ignored_with_a_migration_notice() {
let enabled_context = "[guardianv2]\nthread_context = true";