Remove mid-stream flush on newlines: prevents split multi-turn responses

This commit is contained in:
daniel
2026-05-07 19:13:02 -05:00
parent fd479b8c00
commit fa74ea784f

View File

@@ -245,11 +245,8 @@ def handler(event, context):
token = delta.get('text', '')
if token:
text_buffer += token
flush = (
text_buffer.rstrip().endswith(('\n\n', '.\n', '!\n', '?\n'))
or len(text_buffer) > 800
)
if flush and text_buffer.strip():
# Only flush if buffer is very large — prevents splitting multi-turn responses
if len(text_buffer) > 1200:
print(f'[agent-runner] send chunk {len(text_buffer)}c to {chat_id}')
send_telegram_direct(str(chat_id), bot_token, text_buffer.strip())
text_buffer = ''