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
85 changes: 82 additions & 3 deletions services/worker/src/agent/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ pub struct ModelProvider {
pub api_key: String,
pub primary_model: String,
pub heavy_model: String,
/// The team chose its heavy model in Settings. Then every heavy route
/// runs on it; otherwise the routes measured to hold their quality on a
/// lighter model (`MEASURED_LIGHT_MODEL`) run there.
pub heavy_model_chosen: bool,
/// Counts this team's model calls (set by `load_for_team`). Required:
/// there is no provider, so no client, whose calls go uncounted.
pub meter: common::usage::UsageMeter,
Expand Down Expand Up @@ -73,9 +77,10 @@ impl ModelProvider {
.and_then(|v| v.as_s().ok())
.map(|m| common::model_ids::current(m).to_string())
.unwrap_or_else(|| "claude-sonnet-5-5".to_string());
let heavy_model = item
.get("heavy_model")
.and_then(|v| v.as_s().ok())
let heavy_saved = item.get("heavy_model").and_then(|v| v.as_s().ok());
let heavy_model_chosen = heavy_saved.is_some_and(|m| !m.trim().is_empty());
let heavy_model = heavy_saved
.filter(|m| !m.trim().is_empty())
.map(|m| common::model_ids::current(m).to_string())
.unwrap_or_else(|| "claude-opus-5-5".to_string());

Expand All @@ -91,6 +96,7 @@ impl ModelProvider {
api_key,
primary_model,
heavy_model,
heavy_model_chosen,
meter: common::usage::UsageMeter::dynamo(dynamo.clone(), &analytics_table, team_id),
scope: super::policy::PolicyScope {
team: team_id.to_string(),
Expand Down Expand Up @@ -133,6 +139,34 @@ impl ModelProvider {
&self.heavy_model
}

/// The reviewer's reading and writing of a review (`generate_review`).
/// The critic, which decides which findings are kept and so what blocks,
/// stays on [`Self::heavy_model_id`].
pub fn review_model_id(&self) -> &str {
self.heavy_route(Route::ReviewWriting)
}

/// The coder's model for a ticket of this complexity: simple tickets on
/// the primary model, medium on the measured route, complex on heavy.
pub fn implement_model_id(&self, complexity: &str) -> &str {
match complexity {
"simple" => self.primary_model_id(),
"medium" => self.heavy_route(Route::MediumImplement),
_ => self.heavy_model_id(),
}
}

/// A heavy route's model: the team's own heavy model when it chose one,
/// else the lighter model the route was measured on.
fn heavy_route(&self, route: Route) -> &str {
if self.heavy_model_chosen {
return self.heavy_model_id();
}
match route {
Route::ReviewWriting | Route::MediumImplement => MEASURED_LIGHT_MODEL,
}
}

/// Get the Anthropic API key.
pub fn api_key(&self) -> &str {
&self.api_key
Expand All @@ -159,6 +193,20 @@ impl ModelProvider {
}
}

/// The model the routes below were measured on and held their quality
/// (`passes/model_route_eval.rs`, `reviewer-evals.yml` route suites):
/// review writing with the heavy critic kept 40/40 planted defects and
/// blocked 55/56 cases right against 40/40 and 53/56 on the heavy model;
/// medium tickets passed 20/20 on both.
pub const MEASURED_LIGHT_MODEL: &str = "claude-sonnet-5-5";

/// A heavy route that may run on [`MEASURED_LIGHT_MODEL`].
#[derive(Debug, Clone, Copy)]
enum Route {
ReviewWriting,
MediumImplement,
}

#[derive(Debug, PartialEq, Eq)]
enum ClientKind {
Bedrock,
Expand Down Expand Up @@ -246,4 +294,35 @@ mod client_tests {
// No Bedrock client at all: the Anthropic API.
assert_eq!(pick_client(false, false, true), ClientKind::Anthropic);
}
fn provider(heavy: &str, chosen: bool) -> ModelProvider {
ModelProvider {
api_key: String::new(),
primary_model: "claude-haiku-4-5".into(),
heavy_model: heavy.into(),
heavy_model_chosen: chosen,
meter: common::usage::UsageMeter::memory("t").0,
scope: Default::default(),
}
}

#[test]
fn measured_routes_run_light_unless_the_team_chose_its_heavy_model() {
let default = provider("claude-opus-5-5", false);
assert_eq!(default.review_model_id(), MEASURED_LIGHT_MODEL);
assert_eq!(default.implement_model_id("medium"), MEASURED_LIGHT_MODEL);
// Unmeasured routes keep their models: the critic and complex
// tickets on heavy, simple tickets on primary.
assert_eq!(default.heavy_model_id(), "claude-opus-5-5");
assert_eq!(default.implement_model_id("complex"), "claude-opus-5-5");
assert_eq!(default.implement_model_id("simple"), "claude-haiku-4-5");

// A team that set its heavy model keeps it everywhere.
let chosen = provider("claude-opus-4-8", true);
assert_eq!(chosen.review_model_id(), "claude-opus-4-8");
assert_eq!(chosen.implement_model_id("medium"), "claude-opus-4-8");
assert_eq!(chosen.implement_model_id("complex"), "claude-opus-4-8");
assert_eq!(chosen.implement_model_id("simple"), "claude-haiku-4-5");
// The measured model is one this release calls.
assert!(common::model_ids::is_selectable(MEASURED_LIGHT_MODEL));
}
}
7 changes: 2 additions & 5 deletions services/worker/src/passes/implement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -743,11 +743,8 @@ pub async fn run(
}
let mut messages = vec![("user".to_string(), content_blocks)];

// Route simple issues to primary (Sonnet), medium/complex to heavy (Opus)
let model_id = match complexity {
"simple" => provider.primary_model_id(),
_ => provider.heavy_model_id(),
};
// Simple on primary, medium on the measured route, complex on heavy.
let model_id = provider.implement_model_id(complexity);
let opts = llm::ConverseOptions {
max_turns: match complexity {
"simple" => 40,
Expand Down
2 changes: 1 addition & 1 deletion services/worker/src/passes/review_agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1640,7 +1640,7 @@ pub async fn generate_review(
state,
provider,
common::agent_policy::Agent::Reviewer,
provider.heavy_model_id(),
provider.review_model_id(),
&system,
&mut messages,
&tools,
Expand Down
2 changes: 1 addition & 1 deletion services/worker/src/passes/review_pr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2505,7 +2505,7 @@ async fn run_once(
&msg.team_id,
&record_sk,
&reward.arm,
provider.heavy_model_id(),
provider.review_model_id(),
)
.await;
info!(
Expand Down
1 change: 1 addition & 0 deletions services/worker/src/passes/skills.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2203,6 +2203,7 @@ mod tests {
api_key: String::new(),
primary_model: "team-primary".into(),
heavy_model: "team-heavy".into(),
heavy_model_chosen: true,
meter: common::usage::UsageMeter::memory("t").0,
scope: Default::default(),
};
Expand Down
Loading