之前分享了一个 opencode 的配置,大家也给我提了很多意见,感谢大家!!!

但是我在使用 opencode 的时候当上下文快满的时候自动进行上下文压缩,但是会报错,然后我尝试了手动压缩 /compact 指令,我发现了一个很有意思的现象,当我不使用工具调用的时候可以正常压缩,但是我只要使用工具调用就报错:Bad Request: Improperly formed request. 所以我就猜测是因为思考块里面带了工具调用,致使 CPA 不支持,所以我就开始改 CPA,修复逻辑如下

然后吭哧吭哧改了两天,调了很多次,最后可以正常压缩了,但是工具调用的时候一直循环,无奈宣告失败。。。

但是,我在查文档的时候发现压缩上下文的也是一个子代理,默认使用的是主模型,那既然这样,我换一个模型不就行了,直接开干,因为我设置了 google 的 api 所以我用的是 google 模型。



正常工作,果然,opencode 的高自定义程度名不虚传,好玩爱玩,如果有佬有更好的方法,欢迎分享,在此献上我的 opencode.json 文件,大家可以看看:

{
  "$schema": "https://opencode.ai/config.json",
  "model": "cpa-claude/kiro-claude-opus-4-5-agentic(high)",
  "agent": {
    "compaction": {
      "model": "google/antigravity-gemini-3-pro-low"
    }
  },
  "plugin": [
    "oh-my-opencode",
    "opencode-antigravity-auth@1.2.8",
    "opencode-openai-codex-auth@4.3.0"
  ],
  "provider": {
    "cpa-claude": {
      "npm": "@ai-sdk/anthropic",
      "name": "cpa-claude",
      "options": {
        "baseURL": "http://127.0.0.1:8317/v1"},
      "models": {
        "gemini-claude-opus-4-5-thinking(high)": {
          "name": "gemini-claude-opus-4-5-thinking(high)",
          "limit": {
            "context": 204800,
            "output": 65535
          },
          "modalities": {
            "input": [
              "text",
              "image",
              "pdf"
            ],
            "output": [
              "text"
            ]
          },
          "options": {
            "thinking": {
              "type": "enabled",
              "budgetTokens": 16000
            }
          }
        },
        "gemini-claude-sonnet-4-5-thinking(high)": {
          "name": "gemini-claude-sonnet-4-5-thinking(high)",
          "limit": {
            "context": 204800,
            "output": 65535
          },
          "modalities": {
            "input": [
              "text",
              "image",
              "pdf"
            ],
            "output": [
              "text"
            ]
          },
          "options": {
            "thinking": {
              "type": "enabled",
              "budgetTokens": 16000
            }
          }
        },
        "kiro-claude-sonnet-4-5-agentic": {
          "name": "claude-sonnet-4-5-nothinking",
          "limit": {
            "context": 204800,
            "output": 65535
          },
          "modalities": {
            "input": [
              "text",
              "image",
              "pdf"
            ],
            "output": [
              "text"
            ]
          }
        },
        "kiro-claude-sonnet-4-5-agentic(high)": {
          "name": "claude-sonnet-4-5",
          "limit": {
            "context": 204800,
            "output": 65535
          },
          "modalities": {
            "input": [
              "text",
              "image",
              "pdf"
            ],
            "output": [
              "text"
            ]
          },
          "options": {
            "thinking": {
              "type": "enabled",
              "budgetTokens": 16000
            }
          }
        },
        "kiro-claude-opus-4-5-agentic(high)": {
          "name": "claude-opus-4-5",
          "limit": {
            "context": 204800,
            "output": 65535
          },
          "modalities": {
            "input": [
              "text",
              "image",
              "pdf"
            ],
            "output": [
              "text"
            ]
          },
          "options": {
            "thinking": {
              "type": "enabled",
              "budgetTokens": 16000
            }
          }
        }
      }
    },
    "cpa-gemini": {
      "name": "cpa-gemini",
      "options": {
        "baseURL": "http://127.0.0.1:8317/v1"
      },
      "models": {
        "gemini-3-pro-preview": {
          "name": "gemini-3-pro-preview",
          "limit": {
            "context": 1048576,
            "output": 65535
          },
          "modalities": {
            "input": [
              "text",
              "image",
              "pdf"
            ],
            "output": [
              "text"
            ]
          },
          "options": {
            "thinking": {
              "type": "enabled",
              "budgetTokens": 16000
            }
          }
        },
        "gemini-3-flash-preview": {
          "name": "gemini-3-flash-preview",
          "limit": {
            "context": 1048576,
            "output": 65536
          },
          "modalities": {
            "input": [
              "text",
              "image",
              "pdf"
            ],
            "output": [
              "text"
            ]
          },
          "options": {
            "thinking": {
              "type": "enabled",
              "budgetTokens": 16000
            }
          }
        }
      }
    },
    "google": {
      "name": "Google",
      "models": {
        "antigravity-gemini-3-pro-high": {
          "name": "Gemini 3 Pro High (Antigravity)",
          "thinking": true,
          "attachment": true,
          "limit": {
            "context": 1048576,
            "output": 65535
          },
          "modalities": {
            "input": [
              "text",
              "image",
              "pdf"
            ],
            "output": [
              "text"
            ]
          }
        },
        "antigravity-gemini-3-pro-low": {
          "name": "Gemini 3 Pro Low (Antigravity)",
          "thinking": true,
          "attachment": true,
          "limit": {
            "context": 1048576,
            "output": 65535
          },
          "modalities": {
            "input": [
              "text",
              "image",
              "pdf"
            ],
            "output": [
              "text"
            ]
          }
        },
        "antigravity-gemini-3-flash": {
          "name": "Gemini 3 Flash (Antigravity)",
          "attachment": true,
          "limit": {
            "context": 1048576,
            "output": 65536
          },
          "modalities": {
            "input": [
              "text",
              "image",
              "pdf"
            ],
            "output": [
              "text"
            ]
          }
        }
      }
    },
    "openai": {
      "name": "OpenAI",
      "options": {
        "reasoningEffort": "medium",
        "reasoningSummary": "auto",
        "textVerbosity": "medium",
        "include": [
          "reasoning.encrypted_content"
        ],
        "store": false
      },
      "models": {
        "gpt-5.2": {
          "name": "GPT 5.2 (OAuth)",
          "limit": {
            "context": 272000,
            "output": 128000
          },
          "modalities": {
            "input": [
              "text",
              "image"
            ],
            "output": [
              "text"
            ]
          },
          "variants": {
            "none": {
              "reasoningEffort": "none",
              "reasoningSummary": "auto",
              "textVerbosity": "medium"
            },
            "low": {
              "reasoningEffort": "low",
              "reasoningSummary": "auto",
              "textVerbosity": "medium"
            },
            "medium": {
              "reasoningEffort": "medium",
              "reasoningSummary": "auto",
              "textVerbosity": "medium"
            },
            "high": {
              "reasoningEffort": "high",
              "reasoningSummary": "detailed",
              "textVerbosity": "medium"
            },
            "xhigh": {
              "reasoningEffort": "xhigh",
              "reasoningSummary": "detailed",
              "textVerbosity": "medium"
            }
          }
        },
        "gpt-5.2-codex": {
          "name": "GPT 5.2 Codex (OAuth)",
          "limit": {
            "context": 272000,
            "output": 128000
          },
          "modalities": {
            "input": [
              "text",
              "image"
            ],
            "output": [
              "text"
            ]
          },
          "variants": {
            "low": {
              "reasoningEffort": "low",
              "reasoningSummary": "auto",
              "textVerbosity": "medium"
            },
            "medium": {
              "reasoningEffort": "medium",
              "reasoningSummary": "auto",
              "textVerbosity": "medium"
            },
            "high": {
              "reasoningEffort": "high",
              "reasoningSummary": "detailed",
              "textVerbosity": "medium"
            },
            "xhigh": {
              "reasoningEffort": "xhigh",
              "reasoningSummary": "detailed",
              "textVerbosity": "medium"
            }
          }
        },
        "gpt-5.1-codex-max": {
          "name": "GPT 5.1 Codex Max (OAuth)",
          "limit": {
            "context": 272000,
            "output": 128000
          },
          "modalities": {
            "input": [
              "text",
              "image"
            ],
            "output": [
              "text"
            ]
          },
          "variants": {
            "low": {
              "reasoningEffort": "low",
              "reasoningSummary": "detailed",
              "textVerbosity": "medium"
            },
            "medium": {
              "reasoningEffort": "medium",
              "reasoningSummary": "detailed",
              "textVerbosity": "medium"
            },
            "high": {
              "reasoningEffort": "high",
              "reasoningSummary": "detailed",
              "textVerbosity": "medium"
            },
            "xhigh": {
              "reasoningEffort": "xhigh",
              "reasoningSummary": "detailed",
              "textVerbosity": "medium"
            }
          }
        }
      }
    }
  }
}

除了使用 google/antigravity-gemini-3-pro-low 还可以使用 opencode 提供的免费模型,比如 GLM4.7。

当然,这个只是一个曲线救国的方法,如果有佬有更好的方法,欢迎分享!!!

配置问题可以看看之前那个帖子


📌 转载信息
原作者:
shenning
转载时间:
2026/1/14 18:31:16

标签: OpenCode, 模型配置, 工具调用, CPA, 上下文压缩

添加新评论