mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-30 02:40:18 +00:00
agents: strip unsupported xAI tool strict field
This commit is contained in:
@@ -3,6 +3,7 @@ import type { SimpleStreamOptions } from "@mariozechner/pi-ai";
|
|||||||
import { streamSimple } from "@mariozechner/pi-ai";
|
import { streamSimple } from "@mariozechner/pi-ai";
|
||||||
import type { ThinkLevel } from "../../auto-reply/thinking.js";
|
import type { ThinkLevel } from "../../auto-reply/thinking.js";
|
||||||
import type { OpenClawConfig } from "../../config/config.js";
|
import type { OpenClawConfig } from "../../config/config.js";
|
||||||
|
import { isXaiProvider } from "../schema/clean-for-xai.js";
|
||||||
import {
|
import {
|
||||||
createAnthropicBetaHeadersWrapper,
|
createAnthropicBetaHeadersWrapper,
|
||||||
createAnthropicFastModeWrapper,
|
createAnthropicFastModeWrapper,
|
||||||
@@ -321,6 +322,40 @@ function createParallelToolCallsWrapper(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function stripXaiStrictToolSchemas(payload: unknown): void {
|
||||||
|
if (!payload || typeof payload !== "object") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const payloadObj = payload as { tools?: unknown };
|
||||||
|
if (!Array.isArray(payloadObj.tools)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (const tool of payloadObj.tools) {
|
||||||
|
if (!tool || typeof tool !== "object") {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const functionDef = (tool as { function?: unknown }).function;
|
||||||
|
if (!functionDef || typeof functionDef !== "object") {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
delete (functionDef as Record<string, unknown>).strict;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function createXaiToolSchemaWrapper(baseStreamFn: StreamFn | undefined): StreamFn {
|
||||||
|
const underlying = baseStreamFn ?? streamSimple;
|
||||||
|
return (model, context, options) => {
|
||||||
|
const originalOnPayload = options?.onPayload;
|
||||||
|
return underlying(model, context, {
|
||||||
|
...options,
|
||||||
|
onPayload: (payload) => {
|
||||||
|
stripXaiStrictToolSchemas(payload);
|
||||||
|
return originalOnPayload?.(payload, model);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Apply extra params (like temperature) to an agent's streamFn.
|
* Apply extra params (like temperature) to an agent's streamFn.
|
||||||
* Also adds OpenRouter app attribution headers when using the OpenRouter provider.
|
* Also adds OpenRouter app attribution headers when using the OpenRouter provider.
|
||||||
@@ -437,6 +472,11 @@ export function applyExtraParamsToAgent(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isXaiProvider(provider, modelId)) {
|
||||||
|
log.debug(`removing unsupported function.strict tool fields for ${provider}/${modelId}`);
|
||||||
|
agent.streamFn = createXaiToolSchemaWrapper(agent.streamFn);
|
||||||
|
}
|
||||||
|
|
||||||
// Guard Google payloads against invalid negative thinking budgets emitted by
|
// Guard Google payloads against invalid negative thinking budgets emitted by
|
||||||
// upstream model-ID heuristics for Gemini 3.1 variants.
|
// upstream model-ID heuristics for Gemini 3.1 variants.
|
||||||
agent.streamFn = createGoogleThinkingPayloadWrapper(agent.streamFn, thinkingLevel);
|
agent.streamFn = createGoogleThinkingPayloadWrapper(agent.streamFn, thinkingLevel);
|
||||||
|
|||||||
Reference in New Issue
Block a user