Make Codex and Claude Code subscriptions go further: a local model router that gives routine agent work to economical models and keeps your strongest model for the hard parts.
Rust ai-agentsai-gatewayclaude-codecodexcoding-agentcost-optimizationdeepseekllm-gatewayllm-routerlocal-firstmodel-routingrusttask-routingtauri
use std::collections::BTreeSet;
use hiroute_domain::{
AGENT_PROFILE_SCHEMA_V1, AgentIngressProtocolV1, AgentKindV1, AgentProfileV1, ConfigLayerV1,
FunctionToolV1, ManagedLaunchProfileV1, OwnedConfigFieldV1, SpawnGuidanceProfileV1,
};
use serde_json::json;
#[cfg(test)]
pub const CLAUDE_CODE_VERIFIED_VERSION_V1: &str = "2.1.0";
#[cfg(test)]
pub const CLAUDE_CODE_VERIFIED_VERSION_2_1_231_V1: &str = "2.1.231";
pub const CODEX_PROFILE_ID_V1: &str = "codex-responses-v1";
pub const CLAUDE_PROFILE_ID_V1: &str = "claude-messages-v1";
pub const QODER_PROFILE_ID_V1: &str = "qoder-collaboration-v1";
pub const CODEX_INTEGRATION_PROFILE_REF_V1: &str = "builtin/codex-responses/v1";
pub const CLAUDE_INTEGRATION_PROFILE_REF_V1: &str = "builtin/claude-messages/v1";
pub const QODER_INTEGRATION_PROFILE_REF_V1: &str = "builtin/qoder-collaboration/v1";
pub fn builtin_agent_profiles() -> Vec<AgentProfileV1> {
vec![
codex_profile_v1(),
claude_code_profile_v1(),
qoder_collaboration_profile_v1(),
pi_profile_v1(),
dsh_profile_v1(),
opencode_profile_v1(),
hermes_profile_v1(),
]
}
pub fn codex_profile_v1() -> AgentProfileV1 {
let tool = codex_spawn_agent_tool_v1();
AgentProfileV1 {
schema: AGENT_PROFILE_SCHEMA_V1.to_owned(),
profile_id: CODEX_PROFILE_ID_V1.to_owned(),
integration_profile_ref: CODEX_INTEGRATION_PROFILE_REF_V1.to_owned(),
kind: AgentKindV1::Codex,
// Codex versions are diagnostic only. MVP admission never uses a binary-version
// allowlist; concrete Desktop and CLI surfaces locate and launch their actual engine.
legacy_exact_versions: BTreeSet::new(),
ingress_protocol: Some(AgentIngressProtocolV1::Responses),
config_precedence: AgentKindV1::Codex.config_precedence().to_vec(),
owned_config_fields: vec![
field("provider", "model_provider"),
field("default_model", "model"),
field("base_endpoint", "model_providers.hiroute.base_url"),
field("wire_api", "model_providers.hiroute.wire_api"),
field("static_catalog", "model_catalog_json"),
],
dynamic_catalog: true,
static_catalog_fallback: true,
native_subagent_routing: true,
spawn_guidance: Some(SpawnGuidanceProfileV1 {
tool_name: "spawn_agent".to_owned(),
registration_id: tool.registration_id.clone(),
begin_marker:
"Available model overrides (optional; inherited parent model is preferred):"
.to_owned(),
end_marker: "Spawn arguments:".to_owned(),
expected_shape_digest: tool
.shape_digest()
.expect("built-in tool shape is serializable"),
}),
managed_launch: None,
}
}
pub fn claude_code_profile_v1() -> AgentProfileV1 {
AgentProfileV1 {
schema: AGENT_PROFILE_SCHEMA_V1.to_owned(),
profile_id: CLAUDE_PROFILE_ID_V1.to_owned(),
integration_profile_ref: CLAUDE_INTEGRATION_PROFILE_REF_V1.to_owned(),
kind: AgentKindV1::ClaudeCode,
legacy_exact_versions: BTreeSet::new(),
ingress_protocol: Some(AgentIngressProtocolV1::Messages),
config_precedence: AgentKindV1::ClaudeCode.config_precedence().to_vec(),
owned_config_fields: vec![
field("base_endpoint", "env.ANTHROPIC_BASE_URL"),
field("default_model", "env.ANTHROPIC_MODEL"),
field("default_opus_model", "env.ANTHROPIC_DEFAULT_OPUS_MODEL"),
field("default_sonnet_model", "env.ANTHROPIC_DEFAULT_SONNET_MODEL"),
field("default_haiku_model", "env.ANTHROPIC_DEFAULT_HAIKU_MODEL"),
field("small_fast_model", "env.ANTHROPIC_SMALL_FAST_MODEL"),
// These are adapter-semantic paths. The Claude renderer maps them to the native
// apiKeyHelper field and the complete auth/provider environment family without ever
// placing the prior helper command or credential bytes in an Operation journal.
field("auth_helper", "apiKeyHelper"),
field("auth_environment", "hiroute.auth_environment"),
],
dynamic_catalog: false,
static_catalog_fallback: false,
native_subagent_routing: false,
spawn_guidance: None,
managed_launch: Some(ManagedLaunchProfileV1::claude_code()),
}
}
/// Keep the original collaboration identity so accepted Skill ownership remains valid.
/// Model routing adds one scoped provider; it never claims native defaults or account auth.
pub fn qoder_collaboration_profile_v1() -> AgentProfileV1 {
AgentProfileV1 {
schema: AGENT_PROFILE_SCHEMA_V1.to_owned(),
profile_id: QODER_PROFILE_ID_V1.to_owned(),
integration_profile_ref: QODER_INTEGRATION_PROFILE_REF_V1.to_owned(),
kind: AgentKindV1::Qoder,
legacy_exact_versions: BTreeSet::new(),
ingress_protocol: Some(AgentIngressProtocolV1::Responses),
config_precedence: AgentKindV1::Qoder.config_precedence().to_vec(),
// Adapter-semantic ownership: only the context-specific provider inside this map.
owned_config_fields: vec![field("additional_provider", "hiroute.additional_provider")],
dynamic_catalog: false,
static_catalog_fallback: false,
native_subagent_routing: false,
spawn_guidance: None,
managed_launch: None,
}
}
/// Pi owns a single additional provider in models.json; defaults and auth stay native.
pub const PI_PROFILE_ID_V1: &str = "pi-responses-v1";
pub const PI_INTEGRATION_PROFILE_REF_V1: &str = "builtin/pi-responses/v1";
pub fn pi_profile_v1() -> AgentProfileV1 {
AgentProfileV1 {
schema: AGENT_PROFILE_SCHEMA_V1.into(),
profile_id: "pi-responses-v1".into(),
integration_profile_ref: "builtin/pi-responses/v1".into(),
kind: AgentKindV1::Pi,
legacy_exact_versions: BTreeSet::new(),
ingress_protocol: Some(AgentIngressProtocolV1::Responses),
config_precedence: AgentKindV1::Pi.config_precedence().to_vec(),
owned_config_fields: vec![field("additional_provider", "hiroute.additional_provider")],
dynamic_catalog: false,
static_catalog_fallback: false,
native_subagent_routing: false,
spawn_guidance: None,
managed_launch: None,
}
}
pub const DSH_PROFILE_ID_V1: &str = "dsh-responses-v1";
pub const DSH_INTEGRATION_PROFILE_REF_V1: &str = "builtin/dsh-responses/v1";
pub fn dsh_profile_v1() -> AgentProfileV1 {
AgentProfileV1 {
schema: AGENT_PROFILE_SCHEMA_V1.into(),
profile_id: DSH_PROFILE_ID_V1.into(),
integration_profile_ref: DSH_INTEGRATION_PROFILE_REF_V1.into(),
kind: AgentKindV1::DeepseekHarness,
legacy_exact_versions: BTreeSet::new(),
ingress_protocol: Some(AgentIngressProtocolV1::Responses),
config_precedence: AgentKindV1::DeepseekHarness.config_precedence().to_vec(),
owned_config_fields: vec![field("additional_provider", "hiroute.additional_provider")],
dynamic_catalog: false,
static_catalog_fallback: false,
native_subagent_routing: false,
spawn_guidance: None,
managed_launch: None,
}
}
pub fn codex_spawn_agent_tool_v1() -> FunctionToolV1 {
FunctionToolV1 {
registration_id: "codex.builtin.spawn-agent.v1".to_owned(),
name: "spawn_agent".to_owned(),
kind: "function".to_owned(),
description: concat!(
"Delegate bounded work to a native subagent.\n\n",
"Available model overrides (optional; inherited parent model is preferred):",
"\nbuilt-in defaults\n\n",
"Spawn arguments: task, fork_turns, and optional model."
)
.to_owned(),
parameters: json!({
"additionalProperties": false,
"properties": {
"fork_turns": {"type": "string"},
"model": {"type": "string"},
"task": {"type": "string"}
},
"required": ["task"],
"type": "object"
}),
}
}
fn field(field_id: &str, path: &str) -> OwnedConfigFieldV1 {
OwnedConfigFieldV1::new(field_id, path, ConfigLayerV1::User)
.expect("built-in config path is valid")
}
/// Hermes has a main default route and independent management resources; no Worker capability.
pub const HERMES_PROFILE_ID_V1: &str = "hermes-main-v1";
pub const HERMES_INTEGRATION_PROFILE_REF_V1: &str = "builtin/hermes-main/v1";
pub fn hermes_profile_v1() -> AgentProfileV1 {
AgentProfileV1 {
schema: AGENT_PROFILE_SCHEMA_V1.into(),
profile_id: HERMES_PROFILE_ID_V1.into(),
integration_profile_ref: HERMES_INTEGRATION_PROFILE_REF_V1.into(),
kind: AgentKindV1::Hermes,
legacy_exact_versions: BTreeSet::new(),
ingress_protocol: Some(AgentIngressProtocolV1::Responses),
config_precedence: AgentKindV1::Hermes.config_precedence().to_vec(),
owned_config_fields: vec![
field("default_model", "model.default"),
field("provider", "model.provider"),
],
dynamic_catalog: false,
static_catalog_fallback: false,
native_subagent_routing: false,
spawn_guidance: None,
managed_launch: None,
}
}
pub const OPENCODE_PROFILE_ID_V1: &str = "opencode-responses-v1";
pub const OPENCODE_INTEGRATION_PROFILE_REF_V1: &str = "builtin/opencode-responses/v1";
pub fn opencode_profile_v1() -> AgentProfileV1 {
AgentProfileV1 {
schema: AGENT_PROFILE_SCHEMA_V1.into(),
profile_id: OPENCODE_PROFILE_ID_V1.into(),
integration_profile_ref: OPENCODE_INTEGRATION_PROFILE_REF_V1.into(),
kind: AgentKindV1::OpenCode,
legacy_exact_versions: BTreeSet::new(),
ingress_protocol: Some(AgentIngressProtocolV1::Responses),
config_precedence: AgentKindV1::OpenCode.config_precedence().to_vec(),
owned_config_fields: vec![field("additional_provider", "hiroute.additional_provider")],
dynamic_catalog: false,
static_catalog_fallback: false,
native_subagent_routing: false,
spawn_guidance: None,
managed_launch: None,
}
}