Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 20 additions & 41 deletions crates/tracedecay-agent-hosts/src/agents/context_scout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ use tracedecay_runtime_core::cancellation::{CancellationToken, MonotonicDeadline
use tracedecay_tokenizer::o200k_base;

pub mod address_registry;
pub mod decision_engine;
pub mod intent_pass;
pub mod model;
pub mod owner;
Expand Down Expand Up @@ -1282,20 +1281,14 @@ impl ContextScoutDurableQueueEntryExt for ContextScoutDurableQueueEntryV1 {
| ContextScoutModelOutcomeV1::InvalidOutput,
None,
) => {}
// The intent pass records its engine outcome in the session
// evidence's decision receipt, never in a Codex model receipt.
(ContextScoutRouteV1::DecisionEngine, outcome, None)
if self
.envelope
.candidate
.evidence
.as_session()
.is_some_and(|evidence| evidence.decision.outcome == outcome) => {}
_ => return Err(ContextScoutErrorV1::InvalidCandidate),
}
// Session evidence is produced only by the intent pass.
// Session evidence is produced only by the deterministic intent pass,
// which never asks a model backend.
if self.envelope.candidate.evidence.as_session().is_some()
!= (self.route == ContextScoutRouteV1::DecisionEngine)
&& (self.route != ContextScoutRouteV1::Deterministic
|| self.model_outcome != ContextScoutModelOutcomeV1::NotRequested
|| self.model_receipt.is_some())
{
return Err(ContextScoutErrorV1::InvalidCandidate);
}
Expand Down Expand Up @@ -1383,7 +1376,7 @@ pub struct ContextScoutControlV1 {
}

/// Behavior pin of the configured intent pass: whether it runs and the digest
/// of its whole settings block (engine, window, questions, lifecycle bounds).
/// of its whole settings block (window, scoring, lifecycle bounds).
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct ContextScoutIntentControlV1 {
Expand Down Expand Up @@ -1599,14 +1592,21 @@ where
mode: ContextScoutRuntimeModeV1,
model_execution: ContextScoutModelExecutionV1,
) -> Result<ContextScoutRuntimeOutcomeV1, ContextScoutErrorV1> {
let selection = if let Some(model_outcome) = intent_pass_model_outcome(input)? {
// Intent-pass candidates were judged by the decision engine when
// they were built; selection among them is deterministic, and the
// route records the engine outcome their receipts carry.
let session_evidence = input
.candidates
.iter()
.map(|candidate| candidate.evidence.as_session().is_some())
.collect::<BTreeSet<_>>();
if session_evidence.len() > 1 {
return Err(ContextScoutErrorV1::InvalidCandidate);
}
let selection = if session_evidence.contains(&true) {
// Intent-pass candidates carry only deterministic action facts;
// they never enter the configured authoring-model route.
ContextScoutSelectionV1 {
route: ContextScoutRouteV1::DecisionEngine,
route: ContextScoutRouteV1::Deterministic,
decision: select_deterministic_context_scout(input, limits)?,
model_outcome,
model_outcome: ContextScoutModelOutcomeV1::NotRequested,
model_receipt: None,
}
} else {
Expand All @@ -1624,7 +1624,7 @@ where
}
};
self.last_route = Some(selection.route);
if selection.route != ContextScoutRouteV1::DecisionEngine {
if !session_evidence.contains(&true) {
self.last_model_outcome = Some(selection.model_outcome);
self.last_model_receipt.clone_from(&selection.model_receipt);
}
Expand Down Expand Up @@ -1722,27 +1722,6 @@ where
}
}

/// The engine outcome of an intent-pass selection, `None` for code-evidence
/// selections. One intent pass offers session evidence only, all of it from
/// one engine exchange; mixing evidence kinds is a malformed input.
fn intent_pass_model_outcome(
input: &ContextScoutSelectionInputV1,
) -> Result<Option<ContextScoutModelOutcomeV1>, ContextScoutErrorV1> {
let mut outcomes = input.candidates.iter().map(|candidate| {
candidate
.evidence
.as_session()
.map(|evidence| evidence.decision.outcome)
});
let Some(first) = outcomes.next() else {
return Ok(None);
};
if outcomes.any(|outcome| outcome != first) {
return Err(ContextScoutErrorV1::InvalidCandidate);
}
Ok(first)
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1302,29 +1302,22 @@ mod tests {
intent: None,
};
let with_intent = ContextScoutSettingsV1 {
intent: Some(tracedecay_domain::configuration::ContextScoutIntentSettingsV1 {
enabled: true,
engine: tracedecay_domain::configuration::DecisionEngineSettingsV1 {
base_url: "http://127.0.0.1:8088".to_owned(),
model: None,
timeout_ms: 250,
max_concurrent: 2,
max_state_bytes: 64 * 1024,
},
window: tracedecay_domain::configuration::IntentWindowSettingsV1 {
max_user_turns: 3,
max_messages: 12,
max_bytes: 16 * 1024,
max_age_secs: 1_800,
freshen_budget_ms: 150,
intent: Some(
tracedecay_domain::configuration::ContextScoutIntentSettingsV1 {
enabled: true,
window: tracedecay_domain::configuration::IntentWindowSettingsV1 {
max_user_turns: 3,
max_messages: 12,
max_bytes: 16 * 1024,
max_age_secs: 1_800,
freshen_budget_ms: 150,
},
action_fact_score_permille: 700,
ttl_secs: 600,
min_delivery_gap_secs: 30,
prompt_lookup_deadline_ms: 200,
},
questions:
tracedecay_domain::configuration::ContextScoutIntentSettingsV1::reference_questions(),
action_fact_score_permille: 700,
ttl_secs: 600,
min_delivery_gap_secs: 30,
prompt_lookup_deadline_ms: 200,
}),
),
..configured.clone()
};
let configured = ContextScoutConfigurationPinV1::from_current(&configuration(
Expand Down
Loading
Loading