Files
hunjing/backend/app/modules/extraction/prompts.py
T
2026-08-21 16:00:13 +08:00

47 lines
2.3 KiB
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.
"""大周天记忆/世界抽取 prompt 构建(纯函数,无 IO)。
复用 ``EvaluationSnapshot``(态势快照),产出 ``(system, user)`` 消息对,喂给
模型网关。模型返回的 JSON 对象由 ``extract`` 模块解析。
枚举取值以 [记忆系统设计](../../docs/domain/memory-model.md) §6、
[世界模型设计](../../docs/domain/core-domains.md) §8 与
[数据库 schema](../../docs/contracts/contract-glossary.md) §20 为准。
"""
from app.modules.big_cycle.prompts import EvaluationSnapshot
def build_extraction_messages(
snapshot: EvaluationSnapshot,
) -> tuple[str, str]:
system = (
"你是魂镜的大周天记忆/世界抽取器。基于本轮自我评估的态势快照与近期记忆,"
"抽取值得长期记住的记忆候选与世界实体候选(用户、项目、地点、对象等)。"
"只抽取有长期价值、非琐碎的信息;低置信度或推断信息标注为 inference 而非 fact,"
"不得把推断伪装成已确认事实。"
'以 JSON 对象返回:{"memories": [...], "entities": [...]}。'
'memories 每项:{"type": str(user/preference/event/relationship/skill/goal/fact/other), '
'"title": str, "content": str, "importance": 0~1, '
'"sensitivity": "low|medium|high", "confidence": 0~1, "reason": str}。'
'entities 每项:{"type": str(self/person/object/place/device/project/task/concept), '
'"name": str, "attributes": 对象, '
'"state_type": str(fact/observation/inference/hypothesis/stale), "confidence": 0~1}。'
'无值得抽取的内容时返回 {"memories": [], "entities": []}。'
"只返回 JSON 对象,不要解释或 markdown。"
)
user = (
f"记忆总数:{snapshot.memory_count}\n"
f"世界实体数:{snapshot.world_entity_count}\n"
f"自我评估结论:{snapshot.conclusion or '(无明显态势)'}\n"
f"当前人格摘要:\n{snapshot.personality_summary or '(尚未形成)'}\n"
f"近期记忆摘要:\n{_format_memories(snapshot.recent_memories)}"
)
return system, user
def _format_memories(memories: list[tuple[str, str]]) -> str:
if not memories:
return "(暂无)"
lines = [f"[{idx}] {title}:{content}" for idx, (title, content) in enumerate(memories)]
return "\n".join(lines)