Skip to content

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

fix: preserve Anthropic temperature suppression

Steven Enamakeld4575cebac2d
diff --cc src/core/jsonrpc_tests.rs
index 6f6263c39c,2643b94c80..a4ec3aaeaf
--- a/src/core/jsonrpc_tests.rs
+++ b/src/core/jsonrpc_tests.rs
@@@ -177,6 -177,25 +177,24 @@@ fn learning_subscriber_registration_is_
assert!(!learning_first_time_when_bus_ready(&completed, true));
}
+ #[test]
+ fn domain_subscriber_registration_readiness_helper_is_idempotent() {
+ use crate::core::all::DomainGroup;
+ use std::collections::HashSet;
+ use std::sync::Mutex;
+
+ let completed = Mutex::new(HashSet::new());
+ assert!(group_first_time_when_bus_ready(
+ &completed,
+ DomainGroup::Media,
+ true
+ ));
+ assert!(!group_first_time_when_bus_ready(
+ &completed,
+ DomainGroup::Media,
+ true
+ ));
+ }
-
/// #5027 — the tool-execution timeout must be seeded on the always-on core boot
/// path (`register_domain_subscribers`), NOT inside
/// `channels::runtime::startup::start_channels`, which is skipped for
diff --cc src/openhuman/inference/provider/crate_anthropic.rs
index a29d4d768c,0000000000..778a8d1a4c
mode 100644,000000..100644
--- a/src/openhuman/inference/provider/crate_anthropic.rs
+++ b/src/openhuman/inference/provider/crate_anthropic.rs
@@@ -1,59 -1,0 +1,118 @@@
+//! Crate-native Anthropic Messages API client construction.
+//!
+//! A `cloud_providers` entry with `auth_style = "anthropic"` used to be served
+//! by the crate `OpenAiModel` in its Anthropic-auth flavour — Chat Completions
+//! against Anthropic's OpenAI-compatibility endpoint. That endpoint documents
+//! prompt caching as **unsupported** and reports `prompt_tokens_details` as
+//! always empty, so every turn on a BYOK Claude key re-billed the entire system
+//! prompt, tool catalogue, and conversation at full price, and the host's
+//! `[cache]` diagnostics could never show a hit.
+//!
+//! This module is the boundary where that entry becomes the crate's native
+//! [`AnthropicModel`] instead: the Messages API with `cache_control`
+//! breakpoints on the tool set, the system prompt, and the tail of the
+//! conversation (see the crate adapter's docs for the placement rule), native
+//! `tool_use` / `tool_result` blocks, signed thinking replay, and SSE streaming.
+//! The harness's `PromptCacheSegmentMiddleware` already declares the stable
+//! prefix on every request; this is what turns those declarations into wire
+//! markers on the one provider that needs them explicitly.
+
+use std::sync::Arc;
+
- use tinyinference::model::ChatModel;
++use tinyinference::model::{ChatModel, ModelRequest, ModelResponse, ModelStream};
+use tinyinference::providers::anthropic::AnthropicModel;
+
+/// The resolved config for one Anthropic Messages API provider.
+pub(crate) struct CrateAnthropicConfig<'a> {
+ /// Base URL (`https://api.anthropic.com/v1` for the hosted API; a
+ /// Messages-compatible proxy otherwise). `/messages` is appended unless
+ /// the URL already ends in it.
+ pub endpoint: &'a str,
+ /// API credential, sent as `x-api-key`.
+ pub api_key: &'a str,
+ /// Default model id baked onto the client (a per-call `ModelRequest.model`
+ /// still overrides it).
+ pub model: &'a str,
+ /// Fixed temperature override for every call, when set (the `@<temp>`
+ /// provider-string suffix).
+ pub temperature_override: Option<f64>,
++ /// Model-id `*`-glob patterns whose targets reject a `temperature` param.
++ pub temperature_unsupported_models: &'a [String],
++}
++
++struct TemperatureUnsupportedAnthropicModel {
++ inner: Arc<dyn ChatModel<()>>,
++ default_model: String,
++ patterns: Vec<String>,
++}
++
++impl TemperatureUnsupportedAnthropicModel {
++ fn suppress_temperature(&self, request: &mut ModelRequest) {
++ let model = request.model.as_deref().unwrap_or(&self.default_model);
++ if self
++ .patterns
++ .iter()
++ .any(|pattern| crate::openhuman::inference::temperature::glob_match(pattern, model))
++ {
++ request.temperature = None;
++ }
++ }
++}
++
++#[async_trait::async_trait]
++impl ChatModel<()> for TemperatureUnsupportedAnthropicModel {
++ fn profile(&self) -> Option<&tinyinference::model::ModelProfile> {
++ self.inner.profile()
++ }
++
++ fn cache_identity(&self) -> Option<String> {
++ self.inner.cache_identity()
++ }
++
++ async fn invoke(
++ &self,
++ state: &(),
++ mut request: ModelRequest,
++ ) -> tinyinference::Result<ModelResponse> {
++ self.suppress_temperature(&mut request);
++ self.inner.invoke(state, request).await
++ }
++
++ async fn stream(
++ &self,
++ state: &(),
++ mut request: ModelRequest,
++ ) -> tinyinference::Result<ModelStream> {
++ self.suppress_temperature(&mut request);
++ self.inner.stream(state, request).await
++ }
+}
+
+/// Build a crate-native [`AnthropicModel`] (`ChatModel`) for the given config.
+pub(crate) fn build_crate_anthropic_model(
+ config: CrateAnthropicConfig<'_>,
+) -> Arc<dyn ChatModel<()>> {
+ log::debug!(
+ "[providers][chat-factory] building native Anthropic Messages client endpoint={} model={} temperature_override={:?}",
+ config.endpoint,
+ config.model,
+ config.temperature_override
+ );
+ let model = AnthropicModel::with_base_url(config.api_key, config.endpoint)
+ .with_model(config.model)
+ .with_temperature_override(config.temperature_override);
- Arc::new(model)
++ let model: Arc<dyn ChatModel<()>> = Arc::new(model);
++ if config.temperature_unsupported_models.is_empty() {
++ model
++ } else {
++ Arc::new(TemperatureUnsupportedAnthropicModel {
++ inner: model,
++ default_model: config.model.to_string(),
++ patterns: config.temperature_unsupported_models.to_vec(),
++ })
++ }
+}
+
+#[cfg(test)]
+#[path = "crate_anthropic_tests.rs"]
+mod tests;
diff --cc src/openhuman/inference/provider/crate_anthropic_tests.rs
index e4d7cd99fb,0000000000..98c83bdb12
mode 100644,000000..100644
--- a/src/openhuman/inference/provider/crate_anthropic_tests.rs
+++ b/src/openhuman/inference/provider/crate_anthropic_tests.rs
@@@ -1,23 -1,0 +1,24 @@@
+use super::*;
+
+#[test]
+fn builds_a_native_anthropic_model_with_the_configured_profile() {
+ let model = build_crate_anthropic_model(CrateAnthropicConfig {
+ endpoint: "https://api.anthropic.com/v1",
+ api_key: "sk-ant-secret",
+ model: "claude-sonnet-4-6",
+ temperature_override: Some(0.2),
++ temperature_unsupported_models: &[],
+ });
+ let profile = model.profile().expect("anthropic models expose a profile");
+ assert_eq!(profile.provider.as_deref(), Some("anthropic"));
+ assert_eq!(profile.model.as_deref(), Some("claude-sonnet-4-6"));
+ assert!(profile.tool_calling, "the native adapter speaks tool_use");
+ assert!(profile.streaming, "the native adapter streams SSE");
+ // The identity the response cache scopes on names the endpoint + model and
+ // never the credential.
+ let identity = model
+ .cache_identity()
+ .expect("anthropic models identify themselves");
+ assert!(identity.contains("api.anthropic.com"));
+ assert!(!identity.contains("sk-ant-secret"));
+}
diff --cc src/openhuman/inference/provider/factory_part_04.rs
index d1bcefe6bf,fac969c7af..1f95a594d2
--- a/src/openhuman/inference/provider/factory_part_04.rs
+++ b/src/openhuman/inference/provider/factory_part_04.rs
@@@ -390,38 -390,7 +390,41 @@@ fn try_create_cloud_slug_chat_model_fro
let mut responses_omit_max_output_tokens = false;
let auth = match entry.auth_style {
- AuthStyle::Anthropic => CompatAuthStyle::Anthropic,
+ AuthStyle::Anthropic => {
+ // Anthropic's OpenAI-compatibility endpoint does not support prompt
+ // caching (and reports `prompt_tokens_details` as always empty), so
+ // a BYOK Claude key served through Chat Completions re-billed the
+ // whole prefix on every call. Native tool calling is the normal
+ // case and routes to the crate's Messages API adapter, which
+ // places `cache_control` breakpoints. Text mode (prompt-guided
+ // tools) is only implemented on the Chat Completions adapter, so
+ // that rare case keeps the compat path.
+ if native_tool_calling {
+ crate::openhuman::security::egress::emit_external_transfer(
+ crate::openhuman::security::egress::EgressDescriptor::inference(
+ &slug,
+ &effective_model,
+ true,
+ ),
+ );
+ let chat = super::crate_anthropic::build_crate_anthropic_model(
+ super::crate_anthropic::CrateAnthropicConfig {
+ endpoint: endpoint.as_str(),
+ api_key: key.as_str(),
+ model: effective_model.as_str(),
+ temperature_override,
++ temperature_unsupported_models: config
++ .temperature_unsupported_models
++ .as_slice(),
+ },
+ );
+ return Some(Ok((chat, effective_model)));
+ }
+ log::debug!(
+ "[providers][chat-factory] slug={slug} auth_style=anthropic native_tools=false → OpenAI-compatible text-mode path (no prompt caching)"
+ );
+ CompatAuthStyle::Anthropic
+ }
AuthStyle::None => CompatAuthStyle::None,
AuthStyle::OpenhumanJwt => {
#[cfg(not(test))]