Skip to content

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

refactor(agent): extract per-call inference route into shared helper

Steven Enamakel85b3e3961da9
diff --git a/crates/openhuman-embed/src/agent/compact.rs b/crates/openhuman-embed/src/agent/compact.rs
index 28408c340a..1e405a51c6 100644
--- a/crates/openhuman-embed/src/agent/compact.rs
+++ b/crates/openhuman-embed/src/agent/compact.rs
@@ -47,6 +47,12 @@ impl Agent {
}
.into());
}
+ // The provider route and model a turn on this agent runs with.
+ let turn = self.turn(String::new());
+ let request = turn.request();
+ let route = crate::turn::inference_route(request);
+ let model_override = request.model_override.clone();
+ let temperature = request.temperature;
let ctx = inner.ctx.clone();
let runtime = inner.runtime.clone();
let thread_id = thread_id.to_owned();
@@ -65,10 +71,14 @@ impl Agent {
observer: None,
attachments: &[],
};
+ let mut config = agent.config.clone();
openhuman_core::agent_runs::agent_chat::compact_thread_for(
- &agent.config,
+ &mut config,
target,
&thread_id,
+ model_override,
+ temperature,
+ route,
options,
)
.await
diff --git a/crates/openhuman-embed/src/turn.rs b/crates/openhuman-embed/src/turn.rs
index 92789ba881..b17927ae7c 100644
--- a/crates/openhuman-embed/src/turn.rs
+++ b/crates/openhuman-embed/src/turn.rs
@@ -677,18 +677,7 @@ async fn dispatch(
agent_chat_reply_for_controlled, AgentChatTarget,
};
let mut config = inner.config.clone();
- let route = openhuman_core::config::schema::EphemeralRoute::from_params(
- request.inference_url,
- request.api_key,
- )
- .map(|route| route.with_headers(request.inference_headers));
- let route = route
- .map(|route| {
- route.with_provider_options(request.inference_provider_options)
- })
- .map(|route| {
- route.with_reasoning_effort(request.inference_reasoning_effort)
- });
+ let route = inference_route(&request);
let host = options.tools.or_else(|| inner.composed_host_tools());
let target = AgentChatTarget::Definition {
definition: &inner.definition,
@@ -786,6 +775,21 @@ async fn dispatch(
}
}
+/// The per-call inference route `request` names (endpoint, bearer, headers,
+/// provider options, reasoning effort), applied to the agent's config in
+/// memory for that call alone.
+pub(crate) fn inference_route(
+ request: &TurnRequest,
+) -> Option<openhuman_core::config::schema::EphemeralRoute> {
+ openhuman_core::config::schema::EphemeralRoute::from_params(
+ request.inference_url.clone(),
+ request.api_key.clone(),
+ )
+ .map(|route| route.with_headers(request.inference_headers.clone()))
+ .map(|route| route.with_provider_options(request.inference_provider_options.clone()))
+ .map(|route| route.with_reasoning_effort(request.inference_reasoning_effort.clone()))
+}
+
fn map_agent_chat_error(
error: anyhow::Error,
usage: Option<tinyagents_harness::middleware::ResponseUsage>,