Merge pull request #176 from Bartok9/fix-tts-voice-accumulation

fix(gateway): prevent TTS voice messages from accumulating across turns
This commit is contained in:
Teknium 2026-02-28 16:45:52 -08:00 committed by GitHub
commit b4688f10d4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 195 additions and 1 deletions

View file

@ -1739,6 +1739,9 @@ class GatewayRunner:
content = f"[Delivered from {mirror_src}] {content}"
agent_history.append({"role": role, "content": content})
# Track history length to only scan NEW messages for MEDIA tags
history_len = len(agent_history)
result = agent.run_conversation(message, conversation_history=agent_history)
result_holder[0] = result
@ -1759,10 +1762,17 @@ class GatewayRunner:
# doesn't include them. We collect unique tags from tool results and
# append any that aren't already present in the final response, so the
# adapter's extract_media() can find and deliver the files exactly once.
#
# IMPORTANT: Only scan messages from the CURRENT turn (after history_len),
# not the full history. This prevents TTS voice messages from earlier
# turns being re-attached to every subsequent reply. (Fixes #160)
if "MEDIA:" not in final_response:
media_tags = []
has_voice_directive = False
for msg in result.get("messages", []):
all_messages = result.get("messages", [])
# Only process new messages from this turn
new_messages = all_messages[history_len:] if len(all_messages) > history_len else []
for msg in new_messages:
if msg.get("role") == "tool" or msg.get("role") == "function":
content = msg.get("content", "")
if "MEDIA:" in content: