优化自动回复对群摘要的结构化利用

This commit is contained in:
liuwei
2026-04-24 16:16:30 +08:00
parent 2b8a5d0ce6
commit 8a813df4a3
4 changed files with 480 additions and 22 deletions

View File

@@ -359,11 +359,24 @@ class ContextBuilder:
# 3. 更细的群事实、群关系仍走相关性增强链路。
if not group_profile:
return ""
structured = group_profile.get("group_memory_structured", {}) or {}
summary = ContextBuilder._compact_group_summary(str(group_profile.get("group_memory_summary", "") or ""), max_chars=220, max_sentences=4)
focus = ", ".join(group_profile.get("knowledge_focus", [])[:4])
memory_style = ContextBuilder._build_style_summary(group_profile.get("group_memory_style", {}))
stable_topics = ContextBuilder._stringify_items(structured.get("stable_topics", []) or [], 4)
recent_points = ContextBuilder._stringify_items(structured.get("recent_key_points", []) or [], 3)
unresolved_points = ContextBuilder._stringify_items(structured.get("unresolved_points", []) or [], 3)
resource_clues = ContextBuilder._stringify_items(structured.get("resource_clues", []) or [], 3)
role_hints = ContextBuilder._stringify_items(structured.get("role_hints", []) or [], 3)
summary_days = int(group_profile.get("group_memory_summary_days", 0) or 0)
lines = [
"群长期背景:",
f"摘要观察窗口:最近 {summary_days} 份群总结" if summary_days > 0 else "",
f"稳定主题:{stable_topics}" if stable_topics else "",
f"近期重点:{recent_points}" if recent_points else "",
f"未决问题:{unresolved_points}" if unresolved_points else "",
f"共享资源/线索:{resource_clues}" if resource_clues else "",
f"角色线索:{role_hints}" if role_hints else "",
f"长期摘要:{summary}" if summary else "",
f"常聊方向:{focus}" if focus else "",
f"历史社交风格:{memory_style}" if memory_style else "",
@@ -374,9 +387,15 @@ class ContextBuilder:
def _build_group_profile_prompt(group_profile: Dict) -> str:
if not group_profile:
return "当前群没有特殊知识域限制。"
structured = group_profile.get("group_memory_structured", {}) or {}
focus = ", ".join(group_profile.get("knowledge_focus", [])[:6])
boundaries = ", ".join(group_profile.get("topic_boundaries", [])[:6])
summary = ContextBuilder._compact_group_summary(str(group_profile.get("group_memory_summary", "") or ""))
stable_topics = ContextBuilder._stringify_items(structured.get("stable_topics", []) or [], 4)
recent_points = ContextBuilder._stringify_items(structured.get("recent_key_points", []) or [], 3)
unresolved_points = ContextBuilder._stringify_items(structured.get("unresolved_points", []) or [], 3)
resource_clues = ContextBuilder._stringify_items(structured.get("resource_clues", []) or [], 3)
role_hints = ContextBuilder._stringify_items(structured.get("role_hints", []) or [], 3)
lines = [
f"群模式:{group_profile.get('mode', 'social')}",
f"知识域偏向:{group_profile.get('knowledge_domain', 'general')}(仅作理解倾向,不是每次都要显式提到)",
@@ -389,6 +408,15 @@ class ContextBuilder:
f"表达松弛度:{group_profile.get('expressiveness_style', '克制')}",
f"称呼强度:{group_profile.get('address_style', '低频称呼,默认直接接话')}",
f"可能相关的话题背景:{focus}" if focus else "",
# 这里显式把群摘要结构字段展开给模型:
# 1. LLM 更擅长消费清晰字段,而不是再从 markdown 文案里二次猜测;
# 2. “稳定主题/近期重点/未决问题”分别承载不同决策用途,混成一段反而不好用;
# 3. 仍然保留原摘要关键句,作为字段缺失时的人类可读兜底。
f"群摘要稳定主题:{stable_topics}" if stable_topics else "",
f"群摘要近期重点:{recent_points}" if recent_points else "",
f"群摘要未决问题:{unresolved_points}" if unresolved_points else "",
f"群摘要资源线索:{resource_clues}" if resource_clues else "",
f"群摘要角色线索:{role_hints}" if role_hints else "",
f"群长期摘要关键句:{summary}" if summary else "",
f"历史推断社交风格:{ContextBuilder._build_style_summary(group_profile.get('group_memory_style', {}))}"
if group_profile.get("group_memory_style")