Skip to content

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

Rust

fix(opencode): align default model with Go catalogue

Lucas Oliveira76c04309dc61
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ec2859ee..a1b7c83b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -118,8 +118,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
subagent under its parent's session id, so a subagent's events no longer
mark that session as a subagent: the parent's Stop, SessionEnd, summary and
handoff are kept. (#1041, #1048)
-- The OpenCode provider now selects the published Zen endpoint for supported
+- The OpenCode provider now selects the published wire API for supported Zen
models: Responses, Anthropic Messages, or OpenAI-compatible Chat Completions.
+ Its default model is now `mimo-v2.6-flash`, matching the default Go catalogue;
+ Claude models require an explicit Zen base URL. Configured base URLs remain
+ authoritative, with no automatic switching between Go and Zen billing.
(#1080)
### Docs
diff --git a/crates/ai-memory-cli/src/config.rs b/crates/ai-memory-cli/src/config.rs
index 71e57798..05650059 100644
--- a/crates/ai-memory-cli/src/config.rs
+++ b/crates/ai-memory-cli/src/config.rs
@@ -4565,7 +4565,8 @@ mod tests {
let provider = cfg.llm_provider_config().unwrap().unwrap();
assert_eq!(provider.provider, ProviderChoice::OpenCode, "{spelling}");
- assert_eq!(provider.model, "claude-sonnet-4-6", "{spelling}");
+ assert_eq!(provider.model, "mimo-v2.6-flash", "{spelling}");
+ assert!(provider.base_url.is_none(), "{spelling}");
assert_eq!(
provider.auth.requirement(),
AuthRequirement::RequiredApiKey {
diff --git a/crates/ai-memory-llm/src/opencode.rs b/crates/ai-memory-llm/src/opencode.rs
index b42a7cca..a94cae7d 100644
--- a/crates/ai-memory-llm/src/opencode.rs
+++ b/crates/ai-memory-llm/src/opencode.rs
@@ -38,7 +38,7 @@ pub const OPENCODE_GO_BASE_URL: &str = "https://opencode.ai/zen/go/v1";
pub const OPENCODE_ZEN_BASE_URL: &str = OPENCODE_GO_BASE_URL;
/// Default model when `AI_MEMORY_LLM_MODEL` is not set.
-pub const OPENCODE_DEFAULT_MODEL: &str = "claude-sonnet-4-6";
+pub const OPENCODE_DEFAULT_MODEL: &str = "mimo-v2.6-flash";
/// Session-correlation header OpenCode asks callers to send, on Zen and Go alike.
pub const OPENCODE_SESSION_HEADER: &str = "x-opencode-session";
@@ -679,13 +679,15 @@ mod tests {
}
#[test]
- fn default_model_selects_anthropic_messages_transport() {
+ fn default_model_selects_go_chat_completions_transport() {
let provider =
OpenCodeProvider::new(SecretString::from("sk-test"), OPENCODE_DEFAULT_MODEL).unwrap();
assert!(matches!(
provider.transport,
- OpenCodeTransport::AnthropicMessages(_)
+ OpenCodeTransport::ChatCompletions(_)
));
+ assert_eq!(provider.model(), "mimo-v2.6-flash");
+ assert_eq!(provider.base_url(), OPENCODE_GO_BASE_URL);
}
#[test]
@@ -776,7 +778,7 @@ mod tests {
let provider = OpenCodeProvider::new_with_base_url(
SecretString::from("sk-test"),
- "claude-sonnet-4-6",
+ "claude-sonnet-5",
format!("{}/zen/v1", server.uri()),
)
.unwrap();
@@ -789,6 +791,8 @@ mod tests {
assert_eq!(response.text, "ok");
let requests = server.received_requests().await.unwrap();
assert_eq!(requests.len(), 1);
+ let body: serde_json::Value = serde_json::from_slice(&requests[0].body).unwrap();
+ assert_eq!(body["model"], "claude-sonnet-5");
assert_eq!(header_value(&requests[0], "x-api-key"), Some("sk-test"));
assert_eq!(
header_value(&requests[0], "user-agent"),
@@ -800,6 +804,29 @@ mod tests {
);
}
+ #[tokio::test]
+ async fn default_model_completion_preserves_the_go_catalogue() {
+ let server = MockServer::start().await;
+ Mock::given(method("POST"))
+ .and(path("/zen/go/v1/chat/completions"))
+ .respond_with(ResponseTemplate::new(200).set_body_json(response_with_content("ok")))
+ .mount(&server)
+ .await;
+
+ let provider = OpenCodeProvider::new(SecretString::from("sk-test"), OPENCODE_DEFAULT_MODEL)
+ .unwrap()
+ .with_base_url(format!("{}/zen/go/v1", server.uri()));
+ provider
+ .complete(ChatRequest::user_prompt("hello"))
+ .await
+ .unwrap();
+
+ let requests = server.received_requests().await.unwrap();
+ assert_eq!(requests.len(), 1);
+ let body: serde_json::Value = serde_json::from_slice(&requests[0].body).unwrap();
+ assert_eq!(body["model"], "mimo-v2.6-flash");
+ }
+
#[tokio::test]
async fn luna_structured_completion_uses_responses_api() {
let server = MockServer::start().await;
diff --git a/docs/install.md b/docs/install.md
index dde4a627..4cbc263c 100644
--- a/docs/install.md
+++ b/docs/install.md
@@ -1741,7 +1741,7 @@ If you set only the provider, ai-memory picks a sensible default:
| `AI_MEMORY_LLM_PROVIDER=codex` | `gpt-5.6-luna` | Reuses only `access_token` and `account_id` from Codex's `auth.json`; token renewal is delegated to `codex app-server --stdio`. |
| `AI_MEMORY_LLM_PROVIDER=copilot` | `gpt-5.5` | GitHub Copilot Chat backend. ai-memory stores a GitHub user token in `<data_dir>/auth.json`, exchanges it for a short-lived Copilot API token, and refreshes before expiry. |
| `AI_MEMORY_LLM_PROVIDER=gemini` | `gemini-3.5-flash` | Google's hosted option with a generous free tier. ai-memory disables Gemini 3.5 Flash's default dynamic thinking so hidden thought tokens do not truncate strict JSON. Set `GEMINI_API_KEY` (or `GOOGLE_API_KEY`). |
-| `AI_MEMORY_LLM_PROVIDER=opencode` | `claude-sonnet-4-6` | [OpenCode](https://opencode.ai) cloud API. Defaults to the **Go** endpoint, `opencode.ai/zen/go/v1` — a cost-optimised model subset. GPT-5.6 Luna uses Go's Responses endpoint; other models use Chat Completions. For **Zen**'s full catalogue, set `AI_MEMORY_LLM_BASE_URL=https://opencode.ai/zen/v1` plus an `AI_MEMORY_LLM_MODEL` from it; the default model id is Go's. Requests identify ai-memory by version and reuse one session header across related attempts. Both endpoints take `OPENCODE_API_KEY` (key from `opencode.ai/auth`). Alias: `opencode-zen` — historical, and it selects Go like the others; the endpoint is chosen by the base URL, not the alias. |
+| `AI_MEMORY_LLM_PROVIDER=opencode` | `mimo-v2.6-flash` | [OpenCode](https://opencode.ai) cloud API. Defaults to the **Go** endpoint, `opencode.ai/zen/go/v1` — a cost-optimised model subset. Published Responses models, including GPT-5.6 Luna and GPT-6 Luna, use `/responses`; supported Claude and Qwen Messages models use `/messages`; other models retain Chat Completions. For **Zen**'s full catalogue, set `AI_MEMORY_LLM_BASE_URL=https://opencode.ai/zen/v1` plus an `AI_MEMORY_LLM_MODEL` from it, such as `claude-sonnet-5`; the default model id is Go's. Requests identify ai-memory by version and reuse one session header across related attempts. Both endpoints take `OPENCODE_API_KEY` (key from `opencode.ai/auth`). Alias: `opencode-zen` — historical, and it selects Go like the others; the endpoint is chosen by the base URL, not the alias, with no automatic billing-product switch. |
| `AI_MEMORY_EMBEDDING_PROVIDER=openai` | `text-embedding-3-small` (1536-dim) | 5× cheaper than `-3-large` with marginal recall loss. |
| `AI_MEMORY_EMBEDDING_PROVIDER=openai` + `AI_MEMORY_EMBEDDING_BASE_URL=https://openrouter.ai/api/v1` | `openai/text-embedding-3-small` via [OpenRouter](https://openrouter.ai) | Uses `EMBEDDING_API_KEY`, else reuses `LLM_API_KEY` or `OPENAI_API_KEY`, with the OpenAI-compatible embedding client. |
| `AI_MEMORY_EMBEDDING_PROVIDER=openai` + `AI_MEMORY_EMBEDDING_BASE_URL=https://api.orcarouter.ai/v1` | `openai/text-embedding-3-small` via [OrcaRouter](https://www.orcarouter.ai) | Uses `EMBEDDING_API_KEY`, else reuses `LLM_API_KEY`, with the OpenAI-compatible embedding client. |
diff --git a/docs/llm-providers.md b/docs/llm-providers.md
index 2155b3bd..2c895db9 100644
--- a/docs/llm-providers.md
+++ b/docs/llm-providers.md
@@ -49,7 +49,7 @@ Recommended defaults:
| `codex` | `gpt-5.6-luna` | Reuse the Codex CLI-owned `auth.json`; access-token refresh remains owned by `codex app-server`. |
| `copilot` | `gpt-5.5` | GitHub Copilot Chat backend via `ai-memory auth login copilot` or `COPILOT_GITHUB_TOKEN`; requires a Copilot subscription. |
| `gemini` | `gemini-3.5-flash` | Google-hosted option with a generous free tier. |
-| `opencode` | `claude-sonnet-4-6` | OpenCode Go or Zen via `OPENCODE_API_KEY`. Go is the default endpoint; `AI_MEMORY_LLM_BASE_URL` selects Zen. Set `AI_MEMORY_LLM_MODEL` to an id the chosen endpoint serves. |
+| `opencode` | `mimo-v2.6-flash` | OpenCode Go or Zen via `OPENCODE_API_KEY`. Go is the default endpoint; `AI_MEMORY_LLM_BASE_URL` selects Zen. Set `AI_MEMORY_LLM_MODEL` to an id the chosen endpoint serves. |
| `openai-compat` | no default | OpenRouter, Atlas Cloud, OrcaRouter, Cheaper Inference, API Route, FutureInfra, Ollama, vLLM, LM Studio, and other compatible endpoints. |
| `openai-compat` + `AI_MEMORY_LLM_BASE_URL=https://openrouter.ai/api/v1` | no default (recommended: `anthropic/claude-haiku-4.5`) | Hosted access to a large model catalogue through one key. See [OpenRouter](#openrouter) below and the empirical comparison in [`llm-provider-comparison.md`](llm-provider-comparison.md). |
@@ -91,10 +91,12 @@ allowance rather than per-token billing. Set
`config.toml`) for **Zen**'s pay-per-token catalogue. Model ids are per
catalogue and written plainly (`mimo-v2.5`, `glm-5.3-flash`), not in the
`opencode-go/<model>` form OpenCode's own client config uses. The built-in
-default is `claude-sonnet-4-6`; Go ids such as `mimo-v2.5` or `glm-5.3-flash`
-come from `AI_MEMORY_LLM_MODEL`, so set it to an id the endpoint you chose
-serves. `gpt-5.6-luna` is sent through the Responses endpoint;
-every other model uses Chat Completions. The provider sends the
+default is `mimo-v2.6-flash`, served by Go. When selecting Zen, set
+`AI_MEMORY_LLM_MODEL` to a model from its catalogue, such as `claude-sonnet-5`.
+The provider preserves the chosen catalogue and does not switch billing products
+automatically. Published Responses models, including `gpt-5.6-luna` and
+`gpt-6-luna`, use `/responses`; supported Claude and Qwen Messages models use
+`/messages`; other models retain Chat Completions. The provider sends the
`x-opencode-session` correlation header OpenCode asks for, one id per logical
operation, and its own `User-Agent`; `AI_MEMORY_LLM_HEADERS` overrides
either. `AI_MEMORY_LLM_REASONING_EFFORT` and `AI_MEMORY_LLM_TIMEOUT_SECS`
@@ -105,8 +107,17 @@ chosen by the base URL, not the alias.
```bash
export AI_MEMORY_LLM_PROVIDER=opencode
-export AI_MEMORY_LLM_MODEL=mimo-v2.5
-ai-memory llm-test --provider opencode --model mimo-v2.5 --prompt "Reply with OK"
+export AI_MEMORY_LLM_MODEL=mimo-v2.6-flash
+ai-memory llm-test --provider opencode --model mimo-v2.6-flash --prompt "Reply with OK"
+```
+
+For Claude through Zen:
+
+```bash
+export AI_MEMORY_LLM_PROVIDER=opencode
+export AI_MEMORY_LLM_BASE_URL=https://opencode.ai/zen/v1
+export AI_MEMORY_LLM_MODEL=claude-sonnet-5
+ai-memory llm-test --provider opencode --model claude-sonnet-5 --prompt "Reply with OK"
```
<a id="openrouter"></a>