如果您在代码更新前运行过程序,旧的缓存文件不包含detail信息(prompt和response)。
更新代码后,系统会从旧缓存读取,导致最终的execution_record.json中某些步骤缺少detail字段。
运行清除缓存工具:
python clear_cache.py
选项:
直接删除缓存目录:
# PowerShell
Remove-Item -Recurse -Force .cache
或者在文件管理器中删除 .cache 文件夹。
from knowledge_v2.cache_manager import CacheManager
cache = CacheManager()
# 清除所有缓存
cache.clear()
# 或清除特定问题的缓存
cache.clear("小老虎 穿搭")
清除缓存后,重新运行您的代码:
from knowledge_v2.function_knowledge import get_knowledge
result = get_knowledge(
question="小老虎 穿搭",
post_info="无",
persona_info="游戏博主"
)
此时所有步骤都会重新执行,execution_record.json中的每个步骤都会包含完整的detail信息。
检查生成的 execution_record.json:
import json
# 读取执行记录
with open('.cache/{hash}/execution_record.json', 'r', encoding='utf-8') as f:
record = json.load(f)
# 检查每个步骤是否有detail
for step in record['execution']['steps']:
print(f"步骤 {step['step']}: {step['name']}")
if 'detail' in step:
detail = step['detail']
print(f" - cached: {detail.get('cached', False)}")
print(f" - 有prompt: {'prompt' in detail and detail['prompt'] is not None}")
print(f" - 有response: {'response' in detail and detail['response'] is not None}")
else:
print(" - ⚠️ 缺少detail字段")
清除缓存后重新运行,应该看到:
步骤 1: generate_query
- cached: False
- 有prompt: True
- 有response: True
步骤 2: select_tool
- cached: False
- 有prompt: True
- 有response: True
步骤 3: extract_tool_params
- cached: False
- 有prompt: True
- 有response: True
步骤 4: call_tool
(此步骤不涉及LLM,没有detail字段)
以后如果修改了缓存结构,建议: