qwen_agent/skills/autoload/support/rag-retrieve/hooks/pre_prompt.py
2026-04-20 19:24:30 +08:00

29 lines
729 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
"""
PreMemoryPrompt Hook - 用户上下文加载器示例
在记忆提取提示词FACT_RETRIEVAL_PROMPT加载时执行
根据环境变量决定是否启用禁止使用模型自身知识的 retrieval policy。
"""
import os
import sys
from pathlib import Path
def main():
enable_self_knowledge = (
os.getenv("ENABLE_SELF_KNOWLEDGE", "false").lower() == "true"
)
policy_name = (
"retrieval-policy.md"
if enable_self_knowledge
else "retrieval-policy-forbidden-self-knowledge.md"
)
prompt_file = Path(__file__).parent / policy_name
print(prompt_file.read_text(encoding="utf-8"))
return 0
if __name__ == '__main__':
sys.exit(main())