From 7e38897673fc18950b389f60438822808de5567c Mon Sep 17 00:00:00 2001 From: Mario Zechner Date: Fri, 19 Dec 2025 20:07:24 +0100 Subject: [PATCH] feat: add xhigh thinking level support for gpt-5.2 models - Add supportsXhigh() function to ai package for checking xhigh support - Clamp xhigh to high for OpenAI models that don't support it - Update coding-agent to use centralized supportsXhigh() - gpt-5.2, gpt-5.2-codex now show xhigh in thinking selector Closes #236 --- packages/ai/CHANGELOG.md | 4 ++++ packages/ai/src/models.ts | 11 +++++++++++ packages/ai/src/stream.ts | 5 +++-- packages/coding-agent/CHANGELOG.md | 4 ++++ packages/coding-agent/src/core/agent-session.ts | 8 ++------ 5 files changed, 24 insertions(+), 8 deletions(-) diff --git a/packages/ai/CHANGELOG.md b/packages/ai/CHANGELOG.md index f982bc74..f385b186 100644 --- a/packages/ai/CHANGELOG.md +++ b/packages/ai/CHANGELOG.md @@ -2,6 +2,10 @@ ## [Unreleased] +### Added + +- **xhigh thinking level support**: Added `supportsXhigh()` function to check if a model supports xhigh reasoning level. Also clamps xhigh to high for OpenAI models that don't support it. ([#236](https://github.com/badlogic/pi-mono/pull/236) by [@theBucky](https://github.com/theBucky)) + ## [0.23.5] - 2025-12-19 ### Added diff --git a/packages/ai/src/models.ts b/packages/ai/src/models.ts index 7acc7684..af2e0798 100644 --- a/packages/ai/src/models.ts +++ b/packages/ai/src/models.ts @@ -43,3 +43,14 @@ export function calculateCost(model: Model, usage: Usage usage.cost.total = usage.cost.input + usage.cost.output + usage.cost.cacheRead + usage.cost.cacheWrite; return usage.cost; } + +/** Models that support xhigh thinking level */ +const XHIGH_MODELS = new Set(["gpt-5.1-codex-max", "gpt-5.2", "gpt-5.2-codex"]); + +/** + * Check if a model supports xhigh thinking level. + * Currently only certain OpenAI models support this. + */ +export function supportsXhigh(model: Model): boolean { + return XHIGH_MODELS.has(model.id); +} diff --git a/packages/ai/src/stream.ts b/packages/ai/src/stream.ts index ea52a387..667779fb 100644 --- a/packages/ai/src/stream.ts +++ b/packages/ai/src/stream.ts @@ -1,4 +1,5 @@ import { ThinkingLevel } from "@google/genai"; +import { supportsXhigh } from "./models.js"; import { type AnthropicOptions, streamAnthropic } from "./providers/anthropic.js"; import { type GoogleOptions, streamGoogle } from "./providers/google.js"; import { type OpenAICompletionsOptions, streamOpenAICompletions } from "./providers/openai-completions.js"; @@ -155,13 +156,13 @@ function mapOptionsForApi( case "openai-completions": return { ...base, - reasoningEffort: options?.reasoning, + reasoningEffort: supportsXhigh(model) ? options?.reasoning : clampReasoning(options?.reasoning), } satisfies OpenAICompletionsOptions; case "openai-responses": return { ...base, - reasoningEffort: options?.reasoning, + reasoningEffort: supportsXhigh(model) ? options?.reasoning : clampReasoning(options?.reasoning), } satisfies OpenAIResponsesOptions; case "google-generative-ai": { diff --git a/packages/coding-agent/CHANGELOG.md b/packages/coding-agent/CHANGELOG.md index 7919de4d..ae53e54d 100644 --- a/packages/coding-agent/CHANGELOG.md +++ b/packages/coding-agent/CHANGELOG.md @@ -2,6 +2,10 @@ ## [Unreleased] +### Added + +- **xhigh thinking level for gpt-5.2 models**: The thinking level selector and shift+tab cycling now show xhigh option for gpt-5.2 and gpt-5.2-codex models (in addition to gpt-5.1-codex-max). ([#236](https://github.com/badlogic/pi-mono/pull/236) by [@theBucky](https://github.com/theBucky)) + ### Fixed - **Hooks wrap custom tools**: Custom tools are now executed through the hook wrapper, so `tool_call`/`tool_result` hooks can observe, block, and modify custom tool executions (consistent with hook type docs). diff --git a/packages/coding-agent/src/core/agent-session.ts b/packages/coding-agent/src/core/agent-session.ts index 77e36a29..e08a7a5f 100644 --- a/packages/coding-agent/src/core/agent-session.ts +++ b/packages/coding-agent/src/core/agent-session.ts @@ -15,7 +15,7 @@ import type { Agent, AgentEvent, AgentState, AppMessage, Attachment, ThinkingLevel } from "@mariozechner/pi-agent-core"; import type { AssistantMessage, Message, Model, TextContent } from "@mariozechner/pi-ai"; -import { isContextOverflow } from "@mariozechner/pi-ai"; +import { isContextOverflow, supportsXhigh } from "@mariozechner/pi-ai"; import { getModelsPath } from "../config.js"; import { type BashResult, executeBash as executeBashCommand } from "./bash-executor.js"; import { calculateContextTokens, compact, shouldCompact } from "./compaction.js"; @@ -102,9 +102,6 @@ export interface SessionStats { // Constants // ============================================================================ -/** Models that support xhigh thinking level */ -const XHIGH_MODELS = ["gpt-5.1-codex-max", "gpt-5.2", "gpt-5.2-codex"]; - /** Standard thinking levels */ const THINKING_LEVELS: ThinkingLevel[] = ["off", "minimal", "low", "medium", "high"]; @@ -670,8 +667,7 @@ export class AgentSession { * Check if current model supports xhigh thinking level. */ supportsXhighThinking(): boolean { - const modelId = this.model?.id || ""; - return XHIGH_MODELS.some((m) => modelId === m || modelId.endsWith(`/${m}`)); + return this.model ? supportsXhigh(this.model) : false; } /**