refine heartbeat session retention boundaries

This commit is contained in:
Xubin Ren
2026-03-24 00:33:43 +08:00
committed by Xubin Ren
parent ba0a3d14d9
commit 2056061765
5 changed files with 90 additions and 4 deletions
+5 -4
View File
@@ -619,12 +619,13 @@ def gateway(
chat_id=chat_id,
on_progress=_silent,
)
# Clear the heartbeat session to prevent token overflow from accumulated tasks
# Keep a small tail of heartbeat history so the loop stays bounded
# without losing all short-term context between runs.
session = agent.sessions.get_or_create("heartbeat")
session.clear()
session.retain_recent_legal_suffix(hb_cfg.keep_recent_messages)
agent.sessions.save(session)
return resp.content if resp else ""
async def on_heartbeat_notify(response: str) -> None: