用途:CodexCont 是位于编码智能体与 OpenAI Responses 兼容 API 之间的 Starlette 代理中间件,用于检测推理截断并自动续接思考过程,把多轮上游流式响应折叠为一条连贯的下游响应。
主要能力:当 usage.output_tokens_details.reasoning_tokens 满足 518 * n - 2 且推理内容呈加密/截断状态时触发续接;支持 commentary(推荐)与 tool_pair 两种续接方式;提供 max_rounds、max_reasoning_tokens、tier_gate_low/high 等安全限制;最终响应附带 proxy_rounds、proxy_billed_usage、proxy_stopped_reason 元数据。
安装与运行:需 Python >= 3.12,推荐 uv。命令:git clone https://github.com/neteroster/CodexCont.git;cd CodexCont;uv sync;cp config.example.toml config.toml;uv run python run.py。也可用 .venv/Scripts/python.exe run.py(Windows/Git Bash)或 .venv/bin/python run.py(Linux/macOS)。
配置:config.toml 中设置 [server] host/port、[upstream] url 与 mode(header|fixed)、[auth] mode(passthrough|inject|passthrough_then_inject)、[continue] enabled/method/max_rounds 等、[repair_followup] mode(off|stateless|stateful)。header 模式允许通过 Responses-API-Base 头按请求覆盖上游。
适用场景:需要长推理且上游会截断的编码智能体调用,可配合 LangChain、OpenAI Python SDK、Cursor/Claude Code 等使用,将 base_url 指向 http://127.0.0.1:8787/v1。
限制:非流式请求不折叠,需 stream=true;inject 模式下带 Responses-API-Base 的请求会被拒绝以防凭据泄露;最终答案文本会缓冲至确认未截断,首 token 延迟较高;stateful 修复状态为进程本地,不适合负载均衡生产部署;tool_pair 的 continue_tool_name 与真实工具冲突时会禁用折叠。测试可运行 uv run python tests/test_middleware.py。