Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors
Rust
fix(llm): handle gpt-6 in the openai provider
Éverton Toffanetto60646d135bec
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex a50c4b8d..d0e49c11 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -8,11 +8,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0## [Unreleased]### Fixed-- The `codex`, `openai-oauth` and `copilot` providers no longer send- `temperature` to `gpt-6-*` models. Codex answered these requests with- `400 Unsupported parameter: temperature`, so any provider or fallback- configured with `gpt-6-luna`, `gpt-6-sol` or `gpt-6-astra` failed on every- call. GPT-6 models now get the same treatment as `gpt-5*` and `o*`. (#851)+- Omitted `temperature` for `gpt-6-*` models in the `codex`,+ `openai-oauth`, `copilot` and `openai` providers. Codex answered GPT-6+ requests that carried `temperature` with `400 Unsupported parameter:+ temperature`, which broke consolidation, lint and bootstrap on a+ provider or fallback configured with `gpt-6-luna`, `gpt-6-sol` or+ `gpt-6-astra`. The `openai` provider now also sends+ `max_completion_tokens` for GPT-6 and no longer applies its local+ 16,384-token cap to it, matching `gpt-5*`. (#851)- `companions/ai-memory-macos/build.sh` no longer fails on machines whoseactive developer directory is Command Line Tools only: SwiftUI `@State`needs the `SwiftUIMacros` plugin shipped with full Xcode, so the scriptdiff --git a/crates/ai-memory-llm/src/copilot.rs b/crates/ai-memory-llm/src/copilot.rsindex 839ad5c2..3abf872d 100644--- a/crates/ai-memory-llm/src/copilot.rs+++ b/crates/ai-memory-llm/src/copilot.rs@@ -21,6 +21,7 @@ use crate::embedding::{};use crate::error::{LlmError, LlmResult};use crate::openai::{STRUCTURED_OUTPUT_SCHEMA_NAME, enforce_strict_object_schemas};+use crate::openai_oauth::model_uses_default_temperature;use crate::provider::LlmProvider;use crate::response::{provider_error_body, response_json_limited, response_text_limited};use crate::text::truncate_for_embedding;@@ -695,11 +696,6 @@ fn build_chat_request<'a>(}}-fn model_uses_default_temperature(model: &str) -> bool {- let m = model.to_ascii_lowercase();- m.starts_with("gpt-5") || m.starts_with("gpt-6") || m.starts_with('o')-}-#[derive(Debug, Clone, Copy, PartialEq, Eq)]enum CopilotEndpoint {ChatCompletions,@@ -1328,6 +1324,19 @@ mod tests {assert!(value.get("temperature").is_none());}+ #[test]+ fn responses_request_omits_gpt6_temperature() {+ let request = ChatRequest {+ system: None,+ messages: vec![crate::types::ChatMessage::user("hello")],+ temperature: Some(0.2),+ max_tokens: 123,+ };+ let value =+ serde_json::to_value(build_responses_request("gpt-6-sol", &request, None)).unwrap();+ assert!(value.get("temperature").is_none());+ }+#[test]fn structured_request_uses_json_schema_format() {let request = ChatRequest::user_prompt("json please");diff --git a/crates/ai-memory-llm/src/openai.rs b/crates/ai-memory-llm/src/openai.rsindex 95d25cbc..88186923 100644--- a/crates/ai-memory-llm/src/openai.rs+++ b/crates/ai-memory-llm/src/openai.rs@@ -65,7 +65,7 @@ fn last_segment_is_version(url: &str) -> bool {////// `Official` targets `api.openai.com` and honours the model-family/// rules that the real OpenAI Chat Completions endpoint enforces:-/// `max_completion_tokens` for gpt-5 / o-series, model-family output+/// `max_completion_tokens` for gpt-5 / gpt-6 / o-series, model-family output/// caps, omitted `temperature` for reasoning models, strict-mode JSON/// schema normalisation.///@@ -388,7 +388,7 @@ impl OpenAiProvider {} else {(Some(capped), None)};- // gpt-5 and o-series reject any non-default temperature+ // gpt-5, gpt-6 and o-series reject any non-default temperature// with `Unsupported value: temperature does not support// 0.2 with this model. Only the default (1) is// supported.` The lint / consolidate / bootstrap call@@ -576,17 +576,21 @@ pub(crate) fn enforce_strict_object_schemas(value: &mut serde_json::Value) {/// Models that require `max_completion_tokens` instead of `max_tokens`./// OpenAI introduced this rename starting with the reasoning-capable o1-/// family and made it mandatory across the gpt-5 line. Sending the legacy+/// family and made it mandatory across the gpt-5 and gpt-6 lines. Sending the legacy/// `max_tokens` to these models returns a 400 with/// `Unsupported parameter: 'max_tokens'`.fn model_requires_max_completion_tokens(model: &str) -> bool {let m = model.to_ascii_lowercase();- m.starts_with("gpt-5") || m.starts_with("o1") || m.starts_with("o3") || m.starts_with("o4")+ m.starts_with("gpt-5")+ || m.starts_with("gpt-6")+ || m.starts_with("o1")+ || m.starts_with("o3")+ || m.starts_with("o4")}/// Models that reject any non-default `temperature` value.///-/// gpt-5 and the o-series reasoning models accept only the model+/// gpt-5, gpt-6 and the o-series reasoning models accept only the model/// default (1.0). Any caller-supplied value — including the 0.1-0.2/// passed by lint / bootstrap / consolidation — returns a 400:/// `Unsupported value: 'temperature' does not support 0.2 with this@@ -653,12 +657,12 @@ impl ReasoningHost {/// model-specific message — at which point the operator can lower/// `max_tokens` or switch model. The cap exists to unblock the/// common case (gpt-4o family at 16384), not to paper over every-/// model. Reasoning models in the gpt-5 / o-series have much larger+/// model. Reasoning models in the gpt-5 / gpt-6 / o-series have much larger/// caps (128K+), so we leave their requests untouched.fn max_output_tokens_for(model: &str) -> u32 {if model_requires_max_completion_tokens(model) {- // gpt-5 / o-series: documented at 128K output. Leave the- // caller's value alone — they know what they're asking for.+ // gpt-5 / o-series: documented at 128K output; gpt-6 gets the+ // same handling. Leave the caller's value alone — they know what they're asking for.u32::MAX} else {// gpt-4o family published cap. gpt-4-turbo / gpt-3.5 have a@@ -1043,6 +1047,7 @@ mod tests {assert!(model_requires_max_completion_tokens("o1-mini"));assert!(model_requires_max_completion_tokens("o3"));assert!(model_requires_max_completion_tokens("o4-mini"));+ assert!(model_requires_max_completion_tokens("gpt-6-luna"));}#[test]@@ -1117,6 +1122,25 @@ mod tests {);}+ #[test]+ fn build_request_omits_temperature_for_gpt6() {+ let p = provider_for("gpt-6-luna");+ let req_input = ChatRequest {+ system: None,+ messages: vec![ChatMessage {+ role: Role::User,+ content: "x".into(),+ }],+ max_tokens: 64_000,+ temperature: Some(0.2),+ };+ let json = serde_json::to_value(p.build_request(&req_input, None)).unwrap();+ assert!(json.get("temperature").is_none());+ assert!(json.get("max_tokens").is_none());+ // Above the 16,384 cap applied to non-reasoning models.+ assert_eq!(json["max_completion_tokens"], 64_000);+ }+#[test]fn build_request_keeps_temperature_for_gpt4() {// gpt-4 family accepts any temperature; forwarding thediff --git a/crates/ai-memory-llm/src/openai_oauth.rs b/crates/ai-memory-llm/src/openai_oauth.rsindex a7632709..a26e7670 100644--- a/crates/ai-memory-llm/src/openai_oauth.rs+++ b/crates/ai-memory-llm/src/openai_oauth.rs@@ -428,7 +428,10 @@ pub(crate) fn parse_sse_response(body: &str) -> LlmResult<CodexResponsesResponseOk(response)}-fn model_uses_default_temperature(model: &str) -> bool {+/// Models on the ChatGPT/Codex and Copilot backends that reject a+/// caller-supplied `temperature`. Shared by the `openai-oauth`, `codex`+/// and `copilot` providers.+pub(crate) fn model_uses_default_temperature(model: &str) -> bool {let m = model.to_ascii_lowercase();m.starts_with("gpt-5") || m.starts_with("gpt-6") || m.starts_with('o')}