chore/ 精简展示AI活动的日志
This commit is contained in:
@@ -6,6 +6,10 @@ Agent / LLM 诊断日志:耗时、输入输出规模、截断预览。
|
||||
便于生产环境在不把全局日志调到 DEBUG 的情况下排查 Agent 性能与路径。
|
||||
|
||||
敏感内容:DEBUG 下会记录用户相关文本截断预览,生产环境请勿长期开启 DEBUG。
|
||||
|
||||
配置(节选):``AGENT_LOG_OMIT_SYSTEM_MESSAGE_BODY``(默认 true)省略聊天 System 正文,仅打 len+sha12;
|
||||
``AGENT_LOG_JSON_PROMPT_PREFIX_CHARS`` + ``AGENT_LOG_JSON_PROMPT_PREFIX_ONLY_IF_LEN_GT`` 在 DEBUG 下跳过
|
||||
超长单段 prompt 的前缀再预览。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -96,10 +100,23 @@ def log_agent_payload(
|
||||
"""在 DEBUG 下记录文本长度与截断预览。"""
|
||||
if not agent_verbose_enabled():
|
||||
return
|
||||
preview = truncate_for_log(text, max_chars=max_chars)
|
||||
raw = text or ""
|
||||
total_len = len(raw)
|
||||
preview_source = raw
|
||||
extra_note = ""
|
||||
if (
|
||||
label.endswith(".prompt")
|
||||
and settings.agent_log_json_prompt_prefix_chars > 0
|
||||
and total_len > settings.agent_log_json_prompt_prefix_only_if_len_gt
|
||||
):
|
||||
skip = settings.agent_log_json_prompt_prefix_chars
|
||||
preview_source = raw[skip:]
|
||||
extra_note = f" skipped_prefix_chars={skip}"
|
||||
preview = truncate_for_log(preview_source, max_chars=max_chars)
|
||||
logger.debug(
|
||||
"agent_payload {} total_len={} preview={}",
|
||||
"agent_payload {} total_len={}{} preview={}",
|
||||
label,
|
||||
len(text or ""),
|
||||
total_len,
|
||||
extra_note,
|
||||
preview,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user