diff --git a/cat-plugins/discord_bridge/discord_bridge.py b/cat-plugins/discord_bridge/discord_bridge.py index 764674b..6fb22e1 100644 --- a/cat-plugins/discord_bridge/discord_bridge.py +++ b/cat-plugins/discord_bridge/discord_bridge.py @@ -160,6 +160,31 @@ def before_cat_recalls_declarative_memories(declarative_recall_config, cat): return declarative_recall_config +@hook(priority=80) +def before_cat_recalls_episodic_memories(episodic_recall_config, cat): + """ + Keep episodic recall focused to prevent Miku's own responses from being + immediately recalled into context on the very next user message. + + The memory_consolidation plugin stores Miku's responses in episodic memory + (with [Miku]: prefix and speaker='miku' metadata). Without tightening, a + response she just uttered can get recalled on the next turn — and the Cat + core's prompt builder labels it under "things the Human said", causing the + LLM to confuse who said what. + + Default Cat settings (k=3, threshold=0.7) are reasonable; we keep them. + """ + # k=3 is the default — stays tight + # threshold=0.75 is very slightly stricter than the 0.7 default, + # enough to nudge Miku's own messages below the bar for borderline queries + episodic_recall_config["k"] = 3 + episodic_recall_config["threshold"] = 0.75 + + print(f"🔧 [Discord Bridge] Adjusted episodic recall: k={episodic_recall_config['k']}, threshold={episodic_recall_config['threshold']}") + + return episodic_recall_config + + @hook(priority=50) def after_cat_recalls_memories(cat): """ @@ -220,6 +245,20 @@ def before_agent_starts(agent_input, cat) -> dict: tools_output = agent_input.get('tools_output', '') user_input = agent_input.get('input', '') + # Fix misleading header in episodic memory context. + # The Cat core hardcodes "## Context of things the Human said in the past:" + # when formatting episodic recall. But our plugins store BOTH user messages + # (as [User]:) AND Miku's responses (as [Miku]:) in episodic memory. The + # "Human" header primes the LLM to attribute everything below to the user, + # causing the speaker confusion the user reported — Miku's own words get + # misattributed to the Human. + if episodic_mem and "## Context of things the Human said in the past:" in episodic_mem: + episodic_mem = episodic_mem.replace( + "## Context of things the Human said in the past:", + "## Past conversation excerpts (prefixed by who said what):" + ) + agent_input['episodic_memory'] = episodic_mem + print(f"\U0001f50d [Discord Bridge] before_agent_starts called") print(f" input: {user_input[:80]}") print(f" declarative_mem length: {len(declarative_mem)}") diff --git a/cat-plugins/evil_miku_personality/evil_miku_personality.py b/cat-plugins/evil_miku_personality/evil_miku_personality.py index 0ff3f80..834f8be 100644 --- a/cat-plugins/evil_miku_personality/evil_miku_personality.py +++ b/cat-plugins/evil_miku_personality/evil_miku_personality.py @@ -114,7 +114,8 @@ def agent_prompt_suffix(suffix, cat): [Current mood: {mood_name.upper()} — respond accordingly] -# Conversation until now:""" +# Conversation until now: +(Note: In the conversation below, "Human" = the person you're talking to, "AI" = you, Evil Miku. Pay attention to who said what.)""" @hook(priority=100) diff --git a/cat-plugins/miku_personality/miku_personality.py b/cat-plugins/miku_personality/miku_personality.py index ed1dda4..de531c5 100644 --- a/cat-plugins/miku_personality/miku_personality.py +++ b/cat-plugins/miku_personality/miku_personality.py @@ -86,7 +86,8 @@ def agent_prompt_suffix(suffix, cat): {tools_output} -# Conversation until now:""" +# Conversation until now: +(Note: In the conversation below, "Human" = the person you're talking to, "AI" = you, Miku. Pay attention to who said what.)""" @hook(priority=100)