執行期

對話輪次循環

從上下文建構到模型呼叫、工具執行和終結化的完整使用者請求路徑。

對話輪次循環

這是什麼

從上下文建構到模型呼叫、工具執行和終結化的完整使用者請求路徑。

白話解釋

每一輛從生產線下線的汽車都會經過相同的焊接檢查站、噴漆車間和最終檢驗區,無論是基本款還是全配版。一條訊息到達 Hermes 後,在答案回傳之前,也會經過一組相同的固定站點,無論它是透過聊天視窗、機器人還是定時器到達的。

為什麼重要

Hermes 中的一個使用者請求遵循固定的路徑:上下文被組裝、模型被呼叫、請求的工具被執行、結果被寫回對話狀態。Cron 任務、閘道訊息和桌面聊天都會匯入同一個循環,因此排程工作和即時對話由完全相同的機制處理,而不是平行的程式碼。偵錯缺少的工具呼叫或不完整的回覆,通常從找出這個循環中哪裡出了問題開始。

How it works

This path runs inside conversation_loop.py’s run_conversation function: it first calls turn_context.py’s build_turn_context to do everything that only needs to happen once — sanitizing the incoming message, restoring the cached system prompt, compressing history if it’s grown too large — before any model call happens. From there it enters a loop bounded by agent.max_iterations and an iteration budget; each pass calls the model, and if the reply asks for tools, those get routed into agent._execute_tool_calls (agent/tool_executor.py) before the result feeds back into the loop for another model call. When the model replies without requesting tools or the iteration budget runs out, the loop exits and passes control to turn_finalizer.py’s finalize_turn, which persists the session, syncs memory, and shapes the final response.