Skip to content
Closed
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
54 changes: 25 additions & 29 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,18 @@ 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) => {}
// The intent pass asks no model; its receipt is the session
// evidence's deterministic decision.
(
ContextScoutRouteV1::SessionIntent,
ContextScoutModelOutcomeV1::NotRequested,
None,
) => {}
_ => return Err(ContextScoutErrorV1::InvalidCandidate),
}
// Session evidence is produced only by the intent pass.
if self.envelope.candidate.evidence.as_session().is_some()
!= (self.route == ContextScoutRouteV1::DecisionEngine)
!= (self.route == ContextScoutRouteV1::SessionIntent)
{
return Err(ContextScoutErrorV1::InvalidCandidate);
}
Expand Down Expand Up @@ -1599,14 +1596,13 @@ 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 selection = if is_intent_pass_selection(input)? {
// Intent-pass candidates carry deterministic session evidence;
// selection among them is deterministic and asks no model.
ContextScoutSelectionV1 {
route: ContextScoutRouteV1::DecisionEngine,
route: ContextScoutRouteV1::SessionIntent,
decision: select_deterministic_context_scout(input, limits)?,
model_outcome,
model_outcome: ContextScoutModelOutcomeV1::NotRequested,
model_receipt: None,
}
} else {
Expand All @@ -1624,7 +1620,7 @@ where
}
};
self.last_route = Some(selection.route);
if selection.route != ContextScoutRouteV1::DecisionEngine {
if selection.route != ContextScoutRouteV1::SessionIntent {
self.last_model_outcome = Some(selection.model_outcome);
self.last_model_receipt.clone_from(&selection.model_receipt);
}
Expand Down Expand Up @@ -1725,19 +1721,19 @@ 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(
/// Whether every candidate carries intent-pass session evidence. A mix of
/// session and code evidence is refused; an empty input is not intent work.
fn is_intent_pass_selection(
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);
) -> Result<bool, ContextScoutErrorV1> {
let mut sessions = input
.candidates
.iter()
.map(|candidate| candidate.evidence.as_session().is_some());
let Some(first) = sessions.next() else {
return Ok(false);
};
if outcomes.any(|outcome| outcome != first) {
if sessions.any(|session| session != first) {
return Err(ContextScoutErrorV1::InvalidCandidate);
}
Ok(first)
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