對話輪次終結器
這是什麼
在循環之後持久化輸出、同步記憶並塑造完成結果的後處理層。
白話解釋
想像航空公司機組人員的落地後檢查清單:乘客下機後,仍然需要有人記錄飛行時間、回報任何機械問題,並在飛機獲准過夜前為下一組機組人員標記注意事項。Hermes 的輪次終結器執行同樣的檢查清單。它在 agent 與工具和模型之間的來回對話結束後、在將任何內容回傳給提問者之前執行。
為什麼重要
在一輪的模型呼叫和工具呼叫完成後,finalize_turn 將輸出寫入對話歷史,將值得記憶的內容同步到記憶管理器,並塑造實際回傳給提問者的內容。跳過可靠的終結步驟,cron 任務可能在技術上完成了工作,但沒有留下任何 Hermes 之後可以回想的內容。保留和隱私規則通常在這裡應用,然後一輪的輸出才會成為持久對話狀態的一部分。
How it works
finalize_turn (agent/turn_finalizer.py) runs once the tool-calling loop exits, whatever the reason. It first checks whether the iteration budget ran out; when it has, the turn either keeps an answer a verification step had already composed and was withholding, or — the more common case — asks the model for one extra toolless summary rather than leaving the reply empty. Trajectory save, task-resource cleanup, and session persistence each run inside their own try/except block so one failure — a bad write, a stuck browser teardown — can’t erase a response the other two already secured; problems are collected into a cleanup_errors list instead. It can append a footer flagging file edits that silently failed, or replace a suspiciously short or empty reply with a fallback message before the response is handed back to the caller.