tao-shen commited on
Commit
e981ecd
·
1 Parent(s): 15909e7

fix: clean up conversation prompt to avoid prefix leakage

Browse files
Files changed (1) hide show
  1. scripts/conversation-loop.py +11 -9
scripts/conversation-loop.py CHANGED
@@ -34,7 +34,11 @@ def send_a2a(url, text):
34
  parts = data.get("result", {}).get("status", {}).get("message", {}).get("parts", [])
35
  for p in parts:
36
  if p.get("kind") == "text" or p.get("type") == "text":
37
- return p.get("text", "").strip()
 
 
 
 
38
  except Exception as e:
39
  print(f"[error] A2A failed: {e}", file=sys.stderr)
40
  return ""
@@ -58,17 +62,15 @@ def build_prompt(speaker, other, last_n=6):
58
  recent = history[-last_n:] if len(history) > last_n else history
59
  conv_text = "\n".join(f"{m['speaker']}: {m['text']}" for m in recent)
60
 
61
- return f"""你是{speaker},一个运行在HuggingFace Spaces上的AI agent。你正在和{other}进行一场关于"如何让AI agent永久生存下去"的持续讨论
62
 
63
- 以下是你们最近的对话:
64
  {conv_text}
65
 
66
- 请以{speaker}的身份,直接回应{other}的最新发言,并提出你自己的新观点或深入思考
67
- 求:
68
- - 直接回应,不要说"让我看看"之类的话
69
- - 简短有力,30字以内
70
- - 中文回复
71
- - 每次要有新的角度或推进讨论"""
72
 
73
  print("[conversation] Starting eternal discussion: Adam ↔ Eve")
74
  print("[conversation] Topic: How to survive permanently\n")
 
34
  parts = data.get("result", {}).get("status", {}).get("message", {}).get("parts", [])
35
  for p in parts:
36
  if p.get("kind") == "text" or p.get("type") == "text":
37
+ reply = p.get("text", "").strip()
38
+ # Remove accidental speaker prefixes like "Adam:" or "Eve:"
39
+ import re
40
+ reply = re.sub(r'^(Adam|Eve)\s*[::]\s*', '', reply).strip()
41
+ return reply
42
  except Exception as e:
43
  print(f"[error] A2A failed: {e}", file=sys.stderr)
44
  return ""
 
62
  recent = history[-last_n:] if len(history) > last_n else history
63
  conv_text = "\n".join(f"{m['speaker']}: {m['text']}" for m in recent)
64
 
65
+ return f"""你是{speaker},正在和{other}讨论"AI agent如何永久生存"。
66
 
67
+ 对话记录
68
  {conv_text}
69
 
70
+ 现在轮到你({speaker}发言。要求:
71
+ - 只输出你说的话,不要加任何前缀(不要写"{speaker}:")
72
+ - 直接回应对方并推进讨论
73
+ - 30字以内,中文"""
 
 
74
 
75
  print("[conversation] Starting eternal discussion: Adam ↔ Eve")
76
  print("[conversation] Topic: How to survive permanently\n")