Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

refactor(agent): pass egress ledger explicitly into turn model builders

Steven Enamakel9f74e7e6a807
diff --git a/crates/openhuman-core/src/agent/tinyagents/turn_models.rs b/crates/openhuman-core/src/agent/tinyagents/turn_models.rs
index 389e0f6443..83e2f95af6 100644
--- a/crates/openhuman-core/src/agent/tinyagents/turn_models.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/turn_models.rs
@@ -194,6 +194,14 @@ fn build_turn_models_crate(
) -> anyhow::Result<TurnModels> {
use crate::inference::provider::factory;
+ // One per-turn egress-dedup ledger for the primary, every workload-tier
+ // route and the summarizer: each managed construction resolves through the
+ // same `resolve_managed_backend` chokepoint and would otherwise publish a
+ // separate `ExternalTransferPending` for the same logical destination (codex
+ // P2, PR #4812). The ledger collapses same-destination repeats to one
+ // disclosure per turn while still surfacing each distinct tier model.
+ let egress = crate::security::egress::EgressLedger::per_turn();
+
// The primary honours an explicit provider-string override when the producer's
// effective provider differs from `provider_for_role(role)` (triage #1257).
let build_primary = |m: &str| -> anyhow::Result<TurnChatModel> {
@@ -210,7 +218,9 @@ fn build_turn_models_crate(
.unwrap_or_else(|| factory::resolves_to_managed_backend(role, config));
if managed {
let (backend, _) =
- factory::make_openhuman_backend_model_for_thread(role, config, m, true, thread_id)?;
+ factory::make_openhuman_backend_model_for_thread(
+ role, config, m, true, thread_id, &egress,
+ )?;
return Ok(Arc::new(RouteRecordingModel::new(
crate::agent::attachments::provider::wrap(
backend,
@@ -229,6 +239,7 @@ fn build_turn_models_crate(
m,
temperature,
true,
+ &egress,
),
None => factory::create_turn_chat_model_with_native_tools_and_route(
role,
@@ -236,6 +247,7 @@ fn build_turn_models_crate(
m,
temperature,
true,
+ &egress,
),
}?;
Ok(Arc::new(RouteRecordingModel::new(
@@ -249,14 +261,7 @@ fn build_turn_models_crate(
)))
};
- // Build the primary, every workload-tier route, and the summarizer under one
- // per-turn egress-dedup ledger: each managed construction resolves through the
- // same `resolve_managed_backend` chokepoint and would otherwise publish a
- // separate `ExternalTransferPending` for the same logical destination (codex
- // P2, PR #4812). `dedup_turn_scope` collapses same-destination repeats to one
- // disclosure per turn while still surfacing each distinct tier model.
- let (primary, routes, summarizer): BuiltTurnModels =
- crate::security::egress::dedup_turn_scope(|| {
+ let (primary, routes, summarizer): BuiltTurnModels = (|| {
let primary = build_primary(model)?;
// Additive workload-tier routes: one crate-native model per tier (skipping the
@@ -288,7 +293,7 @@ fn build_turn_models_crate(
}
let route = if factory::resolves_to_managed_backend(tier_role, config) {
factory::make_openhuman_backend_model_for_thread(
- tier_role, config, tier, true, thread_id,
+ tier_role, config, tier, true, thread_id, &egress,
)
.map(|(backend, _)| (backend, "openhuman".to_string(), tier.to_string()))
} else {
@@ -298,6 +303,7 @@ fn build_turn_models_crate(
tier,
temperature,
true,
+ &egress,
)
};
match route {
@@ -338,7 +344,7 @@ fn build_turn_models_crate(
};
anyhow::Ok((primary, routes, summarizer))
- })?;
+ })()?;
let supports_vision = primary.profile().is_some_and(|p| p.modalities.image_in);
Ok(TurnModels {
@@ -677,6 +683,7 @@ impl TurnModelSource {
model,
true,
thread_id,
+ &crate::security::egress::EgressLedger::none(),
)
.map(|(inner, _)| crate::agent::attachments::provider::wrap(inner, cn.config.clone(), model, "openhuman"));
}
diff --git a/crates/openhuman-core/src/inference/host_runtime/ops/agent_chat.rs b/crates/openhuman-core/src/inference/host_runtime/ops/agent_chat.rs
index b164c19de7..8f5666d575 100644
--- a/crates/openhuman-core/src/inference/host_runtime/ops/agent_chat.rs
+++ b/crates/openhuman-core/src/inference/host_runtime/ops/agent_chat.rs
@@ -639,6 +639,7 @@ pub async fn agent_chat_simple(
&default_model,
true,
thread_id.as_deref(),
+ &crate::security::egress::EgressLedger::none(),
)
.map_err(|e| e.to_string())?;
(backend, resolved_model)