编辑 config.yml,确保以下配置正确:
# LLM 配置
llm:
enabled: true
provider: "deepseek" # 或 openai, azure
model: "deepseek-chat"
api_key: "sk-your-api-key-here" # 替换为你的实际 API Key
base_url: "https://api.deepseek.com" # DeepSeek 的 API 地址
# 钉钉配置
dingtalk:
enabled: true
mode: "stream"
app_key: "your-app-key"
app_secret: "your-app-secret"
agent_id: "your-agent-id"
# 启用 LLM 对话
enable_llm_conversation: true
# 卡片配置(可选)
enable_stream_card: false # 建议先测试文本模式
card_template_id: "" # 暂不配置确保日志级别设置为 debug 以便查看详细信息:
logging:
level: "debug"# 编译
make build
# 或直接运行
go build -o bin/zenops .
# 启动服务
./bin/zenops预期日志输出:
INFO LLM client initialized successfully
INFO DingTalk stream handler initialized with LLM support
如果看到以下日志,说明配置正确:
DEBUG LLM config: provider=deepseek, model=deepseek-chat
在钉钉中 @机器人,发送:
你好
预期行为:
- 终端日志显示:
Using LLM to process message - 机器人返回 LLM 的回复(不调用工具)
预期日志:
INFO Using LLM to process message
DEBUG Processing LLM message: 你好
DEBUG LLM response received (no tools called)
在钉钉中发送需要查询数据的问题:
帮我查询一下阿里云有多少台 ECS 服务器
预期行为:
- 机器人显示 "正在思考中..."
- 调用
aliyun_ecs_list工具 - 返回查询结果和分析
预期日志:
INFO Using LLM to process message
DEBUG Processing LLM message: 帮我查询一下阿里云有多少台 ECS 服务器
DEBUG LLM requesting tool call: aliyun_ecs_list
INFO Calling MCP tool: aliyun_ecs_list
DEBUG Tool execution result: [...]
DEBUG LLM final response: 根据查询结果...
发送需要调用多个工具的问题:
对比一下阿里云和腾讯云的服务器数量
预期行为:
- LLM 调用
aliyun_ecs_list - LLM 调用
tencent_cvm_list - LLM 综合分析并返回对比结果
预期日志:
DEBUG LLM requesting tool call: aliyun_ecs_list
INFO Calling MCP tool: aliyun_ecs_list
DEBUG LLM requesting tool call: tencent_cvm_list
INFO Calling MCP tool: tencent_cvm_list
DEBUG LLM final response: 对比结果...
如果你已配置卡片模板ID,编辑配置:
dingtalk:
enable_stream_card: true
card_template_id: "your-template-id.schema"重启服务后,发送相同的问题,观察卡片是否实时更新。
预期日志:
DEBUG Creating stream card
INFO Card created successfully, trackID: xxx
DEBUG Streaming update: 0/500 chars
DEBUG Streaming update: 500/1000 chars
DEBUG Streaming update: finalized
原因: LLM 未被调用,仍在使用意图解析器
检查:
# 查看日志,应该看到:
INFO Using LLM to process message
# 如果看到以下内容,说明 LLM 未启用:
DEBUG Intent parsing result: unknown解决:
- 确认
config.yml中llm.enabled: true - 确认
dingtalk.enable_llm_conversation: true - 重启服务
错误日志:
ERROR Failed to call LLM: ...
检查:
- API Key 是否正确
- Base URL 是否正确
- 网络是否可达
- API 额度是否充足
测试 API 连接:
# DeepSeek 测试
curl https://api.deepseek.com/v1/models \
-H "Authorization: Bearer sk-your-key"
# OpenAI 测试
curl https://api.openai.com/v1/models \
-H "Authorization: Bearer sk-your-key"症状: LLM 回复了问题,但没有调用工具获取数据
原因:
- 提问不够明确
- MCP 工具未注册
- 工具定义不清晰
检查工具列表: 查看启动日志中的工具列表:
DEBUG Available MCP tools: [aliyun_ecs_list, tencent_cvm_list, ...]
改进提问:
- ❌ "有多少服务器?" (太模糊)
- ✅ "查询阿里云 ECS 列表" (明确)
- ✅ "帮我看看腾讯云有多少台 CVM" (明确)
错误日志:
ERROR Failed to create card, fallback to text reply
解决:
- 检查
card_template_id是否正确 - 确认应用有卡片权限
- 暂时禁用卡片:
enable_stream_card: false
原因: LLM API 延迟或工具执行时间长
优化方案:
- 切换到响应更快的 LLM 提供商
- 使用流式卡片提升体验感
- 检查工具执行效率
✅ LLM 功能正常的标志:
- 日志中看到
Using LLM to process message - 简单对话能正常回复
- 明确的查询请求会调用对应的 MCP 工具
- 工具执行结果被 LLM 正确处理和分析
- 最终回复准确且自然
✅ 流式更新正常的标志:
- 回复内容逐步显示(文本模式)或卡片实时更新
- 日志中看到
Streaming update记录 - 最终内容完整
正常响应时间:
- 简单对话: 2-5 秒
- 单工具调用: 5-10 秒
- 多工具调用: 10-20 秒
如果响应时间过长:
- 检查 LLM API 延迟
- 检查工具执行时间
- 考虑优化或缓存
测试通过后,可以:
- 配置流式卡片获得更好体验
- 添加更多 MCP 工具
- 优化系统提示词
- 配置权限控制
- 启用使用统计
如果遇到问题:
- 查看完整日志:
logging.level: "debug" - 检查配置文件:
config.yml - 参考文档:
祝测试顺利! 🎉