Skip to content

[Feature]: 新增 PreLLMCall hook 事件 — 在 LLM 调用前注入自定义消息以锚定思维语言 #3350

Description

@High-cla

Version line

v2 — Go rewrite (1.x), main-v2 (active development)


问题描述 / Problem

当连接的工具(MCP 或内置工具)返回英文内容后,DeepSeek 系列模型的思维链会从中文切换为英文且无法恢复。这是一个模型层面的思维语言漂移现象。

When connected tools (MCP or built-in) return English content, DeepSeek models' thinking/reasoning chain switches from Chinese to English and cannot recover. This is a model-level thinking language drift phenomenon.

V2 的 hook 系统已有 10 个事件,但缺少在 LLM 调用之前修改消息列表的钩子。

V2's hook system has 10 events but lacks a hook to modify the message list before LLM calls.


设计方案 / Design

新增事件 PreLLMCall / New Event: PreLLMCall

触发时机 / Trigger: 系统提示词组装完成后、API 请求发出前 / After system prompt assembly, before API request.

Payload (stdin JSON):

{
  "event": "PreLLMCall",
  "cwd": "<project_root>",
  "turn": 1
}

行为 / Behavior:

Exit Code 行为 / Behavior
0 stdout 以 system 角色注入消息列表最前面 / Inject stdout as system message at head of messages
2 拦截本次 LLM 调用 / Block this LLM call
other 告警 / Warn

实现参考 / Implementation

文件 / File 修改 / Change
internal/hook/hook.go 添加 PreLLMCall Event = "PreLLMCall",加入 Events 列表
internal/agent/ LLM 调用前触发 hook,stdout 非空注入为 system 消息

用例 / Use Case

{
  "hooks": {
    "PreLLMCall": [{
      "command": "echo '我同意'",
      "timeout": 1000
    }]
  }
}

参考 / References

  • 原始提案 / Original: #2391
  • V2 Hook 源码 / Source: internal/hook/hook.go
  • V2 配置示例 / Config Example: reasonix.example.toml

Metadata

Metadata

Assignees

No one assigned

    Labels

    agentCore agent loop (internal/agent, internal/control)mcpMCP servers / plugins (internal/plugin, codegraph)v2Go rewrite (1.x) — main-v2 branch, active development

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions