fix: emit runtime LLM request metadata#23
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
线上诊断会话中出现了模型未调用工具、直接以文本完成的情况。现有 Runtime 事件和日志只能看到最终
finish_reason=stop、tool_calls=null、tool_turns=0,但无法确认当时发给 provider 的请求是否包含工具 schema、tool_choice是什么,也无法直接看到 provider 返回的工具调用数量。范围
本 PR 只在 Runtime worker 外层增加安全取证事件,不改变 Hermes Agent 的工具调用策略、Agent loop、Prompt/Skill 逻辑或 provider 行为。
主要改动
pre_api_request/post_api_requesthook,run 结束后移除。llm.request.metadata事件,记录非敏感请求摘要:skills_count/skill_names/skill_prompt_presencesystem_prompt_chars/system_prompt_sha256enabled_toolsets/disabled_toolsetstools_count/tool_names/tool_choicellm.response.metadata事件,记录非敏感响应摘要:finish_reasonassistant_tool_calls_count/assistant_tool_names验证
uv run pytest tests/runtime_manager/test_registry.py -k "llm_request_metadata or llm_response_metadata"uv run pytest tests/runtime_manager/test_registry.pyuv run pytest tests/runtime_manageruv run ruff check runtime_manager/worker_main.py tests/runtime_manager/test_registry.pypython3 -m py_compile runtime_manager/worker_main.pygit diff --check && git diff --check origin/apecloud-base...HEAD风险与边界