fix(agents): strip unsupported responses store payloads (#39219, thanks @ademczuk)

Co-authored-by: ademczuk <andrew.demczuk@gmail.com>
This commit is contained in:
Peter Steinberger
2026-03-07 22:47:41 +00:00
parent ab704b7aca
commit 3a761fbcf8
3 changed files with 35 additions and 3 deletions

View File

@@ -305,7 +305,14 @@ function createOpenAIResponsesContextManagementWrapper(
return (model, context, options) => {
const forceStore = shouldForceResponsesStore(model);
const useServerCompaction = shouldEnableOpenAIResponsesServerCompaction(model, extraParams);
if (!forceStore && !useServerCompaction) {
// Strip `store` from the payload when the model declares supportsStore=false.
// pi-ai upstream hardcodes `store: false` for Responses API; strict
// OpenAI-compatible endpoints (e.g. Gemini via Cloudflare) reject it.
const stripStore =
!forceStore &&
OPENAI_RESPONSES_APIS.has(String(model.api ?? "")) &&
(model as { compat?: { supportsStore?: boolean } }).compat?.supportsStore === false;
if (!forceStore && !useServerCompaction && !stripStore) {
return underlying(model, context, options);
}
@@ -321,6 +328,9 @@ function createOpenAIResponsesContextManagementWrapper(
if (forceStore) {
payloadObj.store = true;
}
if (stripStore) {
delete payloadObj.store;
}
if (useServerCompaction && payloadObj.context_management === undefined) {
payloadObj.context_management = [
{