Expand description
OllamaCtx — 为本地小窗口 Ollama 模型优化的上下文策略。
§与 [DefaultCtx] 的三点差异
- 更早触发压缩:总 tokens 超过窗口 35% 就压,而非默认的 50%。 8K 窗口下 ~2800 tokens 即启动压缩,给后续 turn 留呼吸空间。
- 工具输出更紧:单条 tool_result 上限 =
ctx/8clamp[2K, 6K]字节,显著低于 Default 的[8K, 32K]。本地模型 8K 窗口下一条 bash 输出占一半预算是主要失败模式。 - 窗口默认值降低:若
provider.context_window未设,fallback 到 8000(Default 是 128000)。匹配 Ollama CLI 的num_ctx常见值。
§不做的事(明确范围)
- 不砍 system prompt:tool schema 作为独立参数传给 LLM API,
不在
system_prompt: &str里。真要简化 system prompt 需要在 [crate::agent::prompt] 层面做。 - 不改工具集筛选:哪些工具暴露给模型是
crate::tool::ToolRegistry的职责,与 ctx 无关。 - 不重写 render/microcompact/replace_stale_reads:
build_messages直接透传给crate::ctx::render::build_messages—— 与默认行为同 pipeline,只是 ctx_window 更小、配合更紧的 tool-output 截断。 想要 render pipeline 级别的定制,完全重写自己的build_messages即可,不必受这里影响。
需要以上行为时,在上层扩展相应模块,不在 ctx 里做。
Structs§
- Ollama
Ctx - 本地 Ollama 模型的上下文策略。