今天來處理 Todo List 記憶結構。
前幾天我們在嘗試 ReAct + Reflection 的流程,已經有一個不錯的「推理-行動-反思」循環。但光有行動和反思還不夠,我希望能讓 Agent 的目標與任務更明確、更結構化。
所以今天來設計 Todo List Memory,讓 LLM 自己管理一份「待辦清單」。
todo list 形式記錄下來。
有幾個好處:
這個 todo list 設計時有幾個 rule:
有一個總目標 [goal]
任務有三種狀態
[todo]
待辦[done]
已完成(必須加上結果)[cancel]
取消(必須加上原因)狀態轉換規則 (呼叫 update 的時候)
實作上我做了一個 TodoListMemory
類別,
它負責:
set_goal()
:設定任務總目標update()
:把最近訊息丟進 LLM,讓它更新 todo listdump()
:輸出最新的 todo list而更新的邏輯就是靠 LLM 的系統提示詞(system prompt)限制格式,
再搭配 user prompt(把當前 todo 與歷史訊息丟進去),
最後直接用 LLM 輸出的結果覆蓋掉 _todos
。
這邊用一個實際範例:
問題:
What is the result of subtracting 8 from the reverse of when the publisher of Qst was founded?
[goal]: What is the result of subtracting 8 from the reverse of when the publisher of Qst was founded?
---
[todo]: Find the founding year of the publisher of Qst magazine
[todo]: Reverse the founding year number
[todo]: Subtract 8 from the reversed year
[todo]: Format and provide the final answer as required
[done]: Find the founding year of the American Radio Relay League (publisher of Qst magazine) → result: ARRL was founded in 1914
[todo]: Reverse the founding year number
[todo]: Subtract 8 from the reversed year
[todo]: Format and provide the final answer as required
[done]: Find the founding year of the American Radio Relay League (publisher of Qst magazine) → result: ARRL was founded in 1914
[done]: Reverse the founding year number → result: 4191
[done]: Subtract 8 from the reversed year → result: 4183
[todo]: Format and provide the final answer as required
這樣就很清楚地看到 agent 的推理過程。
在讀完昨天的 context engineering 後,在設計 todo memory 架構時,單純只想著要簡潔清楚,所以就直接用了一個 text file 來 maintain todo list。
明天跑一下實驗看一下效果。
目前 memory update()
是放在 reflection state 之後,
所以等於「行動 → 反思 → 更新任務」。
感覺後面可以再試試看:如果 reasoning 沒有 action,也能自動觸發一次 todo list 更新。