Skip to content

Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors

Rust

fix(anthropic): cover Mythos sampling compatibility

AkitaOnRails11883ddf6091
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3caff100..6cc34690 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -35,18 +35,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
session starts, user prompts, and pre-tool events now advance shared or
identity-only fallbacks; other events refresh exact session mappings, and
dropped-subagent preflight no longer publishes scope (#372).
-- The Anthropic provider no longer sends `temperature` to models that
- rejected it. Claude 5 (Opus / Sonnet / Fable) and Opus 4.7+ answer any
- request carrying a sampling parameter with a 400 reporting `temperature`
- as deprecated for that model, which the server surfaced as a 502 — so
- `bootstrap`, consolidation, `lint`, and the auto-improvement loop all
- failed on those models, since every structured call site sets 0.1-0.2.
- The field is now omitted for the affected models (the API applies its own
- default) and forwarded unchanged everywhere else, mirroring the existing
- gpt-5 / o-series handling in the OpenAI provider. Affects both
- `anthropic` and `anthropic-oauth`. Note that `llm-test` sends no
- `temperature`, so it reported these models as healthy while every real
- pipeline call failed ([#377]).
+- The Anthropic provider stopped sending `temperature` to Claude 4.7 and later
+ models, including the Claude 5 families, and to Claude Mythos Preview. Those
+ models reject non-default sampling parameters, which made `bootstrap`,
+ consolidation, `lint`, and auto-improvement fail with an upstream 400. Both
+ `anthropic` and `anthropic-oauth` now omit the field for affected models and
+ preserve it elsewhere. `llm-test` also sends a representative 0.2 value
+ before provider normalization, so it exercises the same compatibility path
+ as the real pipeline (#377).
- Both wrappers (`bin/ai-memory` and `bin/ai-memory.ps1`) now forward
`ANTHROPIC_OAUTH_TOKEN` and `CLAUDE_CODE_OAUTH_TOKEN` to the helper
container. Their API-key counterparts were already in the passthrough list,
diff --git a/README.md b/README.md
index 7aaf4aa2..71c3a689 100644
--- a/README.md
+++ b/README.md
@@ -884,6 +884,13 @@ setup-token` writes automatically). No `ANTHROPIC_API_KEY` is needed. The Docker
wrappers forward either token by name to short-lived helper commands such as
`llm-test`; configure the long-lived server container separately as shown in the
installation guide.
+
+For both Anthropic providers, ai-memory omits `temperature` for Claude
+4.7 and later models and Claude Mythos Preview because those models reject
+non-default sampling parameters. `llm-test` sends the same representative 0.2
+value as the normal pipeline before the provider applies that compatibility
+rule.
+
**⚠️ Unofficial and against Anthropic's usage policies — use at your own risk;
it may get your account rate-limited or banned. See
[the warning in `docs/install.md`](docs/install.md#anthropic-via-claude-subscription-oauth).**
diff --git a/crates/ai-memory-cli/src/commands/llm_test.rs b/crates/ai-memory-cli/src/commands/llm_test.rs
index 1521ebee..140b0396 100644
--- a/crates/ai-memory-cli/src/commands/llm_test.rs
+++ b/crates/ai-memory-cli/src/commands/llm_test.rs
@@ -32,7 +32,7 @@ pub async fn run(config: &Config, args: LlmTestArgs) -> Result<()> {
"sending prompt",
);
let resp = client
- .complete(ChatRequest::user_prompt(args.prompt))
+ .complete(representative_request(args.prompt))
.await
.context("calling provider")?;
@@ -47,6 +47,14 @@ pub async fn run(config: &Config, args: LlmTestArgs) -> Result<()> {
Ok(())
}
+/// Use the same sampling value as bootstrap and consolidation so this smoke
+/// test exercises provider-specific request normalization.
+fn representative_request(prompt: String) -> ChatRequest {
+ let mut request = ChatRequest::user_prompt(prompt);
+ request.temperature = Some(0.2);
+ request
+}
+
impl From<LlmProviderChoice> for ProviderChoice {
fn from(value: LlmProviderChoice) -> Self {
match value {
@@ -73,4 +81,12 @@ mod tests {
ProviderChoice::AnthropicOAuth
);
}
+
+ #[test]
+ fn llm_test_exercises_pipeline_sampling_compatibility() {
+ let request = representative_request("diagnostic".into());
+
+ assert_eq!(request.temperature, Some(0.2));
+ assert_eq!(request.messages[0].content, "diagnostic");
+ }
}
diff --git a/crates/ai-memory-llm/src/anthropic.rs b/crates/ai-memory-llm/src/anthropic.rs
index dc1da732..a04aea5d 100644
--- a/crates/ai-memory-llm/src/anthropic.rs
+++ b/crates/ai-memory-llm/src/anthropic.rs
@@ -236,8 +236,8 @@ impl AnthropicProvider {
),
None => (None, None),
};
- // Newer models reject any caller-supplied `temperature` with a 400;
- // omit the field so the API applies its own default.
+ // Newer models reject ai-memory's non-default `temperature` with a
+ // 400; omit the field so the API applies its own default.
let temperature = if model_rejects_temperature(&self.model) {
None
} else {
@@ -295,14 +295,13 @@ impl AnthropicProvider {
}
}
-/// Models that reject any caller-supplied `temperature`.
+/// Models that reject ai-memory's non-default `temperature`.
///
/// Anthropic deprecated sampling parameters on the newer models: sending
-/// `temperature` to Claude 5 (Opus / Sonnet / Fable) or to Opus 4.7+ returns a
+/// `temperature` to Claude 4.7+ or to Claude Mythos Preview returns a
/// 400 with `` `temperature` is deprecated for this model. `` Every structured
/// call site — bootstrap, consolidation, lint, auto-improve — passes 0.1-0.2,
-/// so without this the whole LLM pipeline is unusable on those models while
-/// `llm-test` (which sends no temperature) still reports the model as healthy.
+/// so without this the whole LLM pipeline is unusable on those models.
/// Omitting the field lets the API apply its own default, the same escape
/// hatch `openai.rs::model_requires_default_temperature` uses for gpt-5 /
/// o-series.
@@ -313,12 +312,31 @@ impl AnthropicProvider {
/// proxying a non-Claude model behind this wire format must not be silently
/// stripped either.
fn model_rejects_temperature(model: &str) -> bool {
+ if is_mythos_preview(model) {
+ return true;
+ }
match claude_family_version(model) {
Some((major, minor)) => major >= 5 || (major == 4 && minor >= 7),
None => false,
}
}
+/// Match the dateless preview id, including vendor-prefixed variants.
+fn is_mythos_preview(model: &str) -> bool {
+ let lower = model.to_ascii_lowercase();
+ let Some(rest) = lower
+ .find("claude-")
+ .map(|start| &lower[start + "claude-".len()..])
+ else {
+ return false;
+ };
+ let mut parts = rest.split(|c: char| !c.is_ascii_alphanumeric());
+ matches!(
+ (parts.next(), parts.next()),
+ (Some("mythos"), Some("preview"))
+ )
+}
+
/// Parse the `<major>[-<minor>]` version following the family name of a modern
/// Claude id (`claude-opus-5`, `claude-sonnet-4-6`, `claude-opus-5@20260115`,
/// `anthropic.claude-opus-5-v1:0`). Returns `None` for the legacy
@@ -330,7 +348,10 @@ fn claude_family_version(model: &str) -> Option<(u32, u32)> {
// the same `claude-<family>-<version>` core.
let rest = &lower[lower.find("claude-")? + "claude-".len()..];
let mut parts = rest.split(|c: char| !c.is_ascii_alphanumeric());
- if !matches!(parts.next()?, "opus" | "sonnet" | "haiku" | "fable") {
+ if !matches!(
+ parts.next()?,
+ "opus" | "sonnet" | "haiku" | "fable" | "mythos"
+ ) {
return None;
}
let major = version_segment(parts.next()?)?;
@@ -444,6 +465,9 @@ mod tests {
"claude-opus-5",
"claude-sonnet-5",
"claude-fable-5",
+ "claude-mythos-5",
+ "claude-mythos-preview",
+ "anthropic.claude-mythos-preview-v1:0",
"claude-opus-4-7",
"claude-opus-4-8",
"anthropic.claude-opus-5-v1:0",
diff --git a/docs/install.md b/docs/install.md
index a3a25fc2..2ba7aab1 100644
--- a/docs/install.md
+++ b/docs/install.md
@@ -1254,6 +1254,12 @@ Docker rather than placed in the wrapper's command line. The long-lived server
container still needs the provider and token variables in its own environment,
as in the example above.
+For both Anthropic providers, ai-memory omits `temperature` for Claude
+4.7 and later models and Claude Mythos Preview because those models reject
+non-default sampling parameters. `llm-test` deliberately starts with the same
+representative 0.2 value as bootstrap and consolidation, then exercises the
+provider's compatibility normalization before sending the request.
+
> [!TIP]
> **Pick a small, fast model.** ai-memory's LLM work — session
> consolidation, lint, and explore — is summarisation/extraction, not hard