mirror of
https://github.com/openclaw/openclaw.git
synced 2026-02-08 21:09:23 +08:00
feat(agent): auto-enable GLM-4.7 thinking mode
Add automatic thinking mode support for Z.AI GLM-4.x models:
- GLM-4.7: Preserved thinking (clear_thinking: false)
- GLM-4.5/4.6: Interleaved thinking (clear_thinking: true)
Uses Z.AI Cloud API format: thinking: { type: "enabled", clear_thinking: boolean }
Includes patches for pi-ai, pi-agent-core, and pi-coding-agent to pass
extraParams through the stream pipeline. User can override via config
or disable via --thinking off.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
committed by
Peter Steinberger
parent
3f93781b4b
commit
f7b32195cb
46
patches/@mariozechner__pi-agent-core.patch
Normal file
46
patches/@mariozechner__pi-agent-core.patch
Normal file
@@ -0,0 +1,46 @@
|
||||
diff --git a/dist/agent.js b/dist/agent.js
|
||||
index 0000000..1111111 100644
|
||||
--- a/dist/agent.js
|
||||
+++ b/dist/agent.js
|
||||
@@ -42,6 +42,8 @@ export class Agent {
|
||||
this.followUpMode = opts.followUpMode || "one-at-a-time";
|
||||
this.streamFn = opts.streamFn || streamSimple;
|
||||
this.getApiKey = opts.getApiKey;
|
||||
+ // PATCH: Support extraParams for provider-specific features (e.g., GLM-4.7 thinking mode)
|
||||
+ this.extraParams = opts.extraParams;
|
||||
}
|
||||
get state() {
|
||||
return this._state;
|
||||
@@ -193,6 +195,8 @@ export class Agent {
|
||||
convertToLlm: this.convertToLlm,
|
||||
transformContext: this.transformContext,
|
||||
getApiKey: this.getApiKey,
|
||||
+ // PATCH: Pass extraParams through to stream function
|
||||
+ extraParams: this.extraParams,
|
||||
getSteeringMessages: async () => {
|
||||
if (this.steeringMode === "one-at-a-time") {
|
||||
if (this.steeringQueue.length > 0) {
|
||||
diff --git a/dist/agent.d.ts b/dist/agent.d.ts
|
||||
index 0000000..1111111 100644
|
||||
--- a/dist/agent.d.ts
|
||||
+++ b/dist/agent.d.ts
|
||||
@@ -33,6 +33,10 @@ export interface AgentOptions {
|
||||
* Useful for expiring tokens (e.g., GitHub Copilot OAuth).
|
||||
*/
|
||||
getApiKey?: (provider: string) => Promise<string | undefined> | string | undefined;
|
||||
+ /**
|
||||
+ * Extra params to pass to the provider API (e.g., Z.AI GLM thinking mode params).
|
||||
+ */
|
||||
+ extraParams?: Record<string, unknown>;
|
||||
}
|
||||
export declare class Agent {
|
||||
private _state;
|
||||
@@ -45,6 +49,8 @@ export declare class Agent {
|
||||
private followUpMode;
|
||||
streamFn: StreamFn;
|
||||
getApiKey?: (provider: string) => Promise<string | undefined> | string | undefined;
|
||||
+ /** Extra params to pass to the provider API. */
|
||||
+ extraParams?: Record<string, unknown>;
|
||||
private runningPrompt?;
|
||||
private resolveRunningPrompt?;
|
||||
constructor(opts?: AgentOptions);
|
||||
@@ -241,3 +241,41 @@ diff --git a/dist/providers/google-gemini-cli.js b/dist/providers/google-gemini-
|
||||
lastError = error instanceof Error ? error : new Error(String(error));
|
||||
// Network errors are retryable
|
||||
if (attempt < MAX_RETRIES) {
|
||||
diff --git a/dist/stream.js b/dist/stream.js
|
||||
--- a/dist/stream.js
|
||||
+++ b/dist/stream.js
|
||||
@@ -105,6 +105,8 @@ function mapOptionsForApi(model, options, apiKey) {
|
||||
maxTokens: options?.maxTokens || Math.min(model.maxTokens, 32000),
|
||||
signal: options?.signal,
|
||||
apiKey: apiKey || options?.apiKey,
|
||||
+ // PATCH: Pass extraParams through to provider-specific API handlers
|
||||
+ extraParams: options?.extraParams,
|
||||
};
|
||||
// Helper to clamp xhigh to high for providers that don't support it
|
||||
const clampReasoning = (effort) => (effort === "xhigh" ? "high" : effort);
|
||||
diff --git a/dist/providers/openai-completions.js b/dist/providers/openai-completions.js
|
||||
--- a/dist/providers/openai-completions.js
|
||||
+++ b/dist/providers/openai-completions.js
|
||||
@@ -333,6 +333,11 @@ function buildParams(model, context, options) {
|
||||
if (options?.reasoningEffort && model.reasoning && compat.supportsReasoningEffort) {
|
||||
params.reasoning_effort = options.reasoningEffort;
|
||||
}
|
||||
+ // PATCH: Support arbitrary extra params for provider-specific features
|
||||
+ // (e.g., Z.AI GLM-4.7 thinking: { type: "enabled", clear_thinking: boolean })
|
||||
+ if (options?.extraParams && typeof options.extraParams === 'object') {
|
||||
+ Object.assign(params, options.extraParams);
|
||||
+ }
|
||||
return params;
|
||||
}
|
||||
function convertMessages(model, context, compat) {
|
||||
diff --git a/dist/providers/openai-completions.d.ts b/dist/providers/openai-completions.d.ts
|
||||
--- a/dist/providers/openai-completions.d.ts
|
||||
+++ b/dist/providers/openai-completions.d.ts
|
||||
@@ -7,5 +7,7 @@ export interface OpenAICompletionsOptions extends StreamOptions {
|
||||
};
|
||||
};
|
||||
reasoningEffort?: "minimal" | "low" | "medium" | "high" | "xhigh";
|
||||
+ /** Extra params to pass directly to the API (e.g., Z.AI GLM thinking mode params) */
|
||||
+ extraParams?: Record<string, unknown>;
|
||||
}
|
||||
export declare const streamOpenAICompletions: StreamFunction<"openai-completions">;
|
||||
|
||||
28
patches/@mariozechner__pi-coding-agent.patch
Normal file
28
patches/@mariozechner__pi-coding-agent.patch
Normal file
@@ -0,0 +1,28 @@
|
||||
diff --git a/dist/core/sdk.js b/dist/core/sdk.js
|
||||
index 0000000..1111111 100644
|
||||
--- a/dist/core/sdk.js
|
||||
+++ b/dist/core/sdk.js
|
||||
@@ -441,6 +441,8 @@ export async function createAgentSession(options = {}) {
|
||||
}
|
||||
return key;
|
||||
},
|
||||
+ // PATCH: Pass extraParams through for provider-specific features (e.g., GLM-4.7 thinking mode)
|
||||
+ extraParams: options.extraParams,
|
||||
});
|
||||
time("createAgent");
|
||||
// Restore messages if session has existing data
|
||||
diff --git a/dist/core/sdk.d.ts b/dist/core/sdk.d.ts
|
||||
index 0000000..1111111 100644
|
||||
--- a/dist/core/sdk.d.ts
|
||||
+++ b/dist/core/sdk.d.ts
|
||||
@@ -79,6 +79,10 @@ export interface CreateAgentSessionOptions {
|
||||
sessionManager?: SessionManager;
|
||||
/** Settings manager. Default: SettingsManager.create(cwd, agentDir) */
|
||||
settingsManager?: SettingsManager;
|
||||
+ /**
|
||||
+ * Extra params to pass to the provider API (e.g., Z.AI GLM thinking mode params).
|
||||
+ */
|
||||
+ extraParams?: Record<string, unknown>;
|
||||
}
|
||||
/** Result from createAgentSession */
|
||||
export interface CreateAgentSessionResult {
|
||||
Reference in New Issue
Block a user