Try   HackMD

[2025李宏毅ML] 第2講:一堂課搞懂 AI Agent 的原理 (AI如何透過經驗調整行為、使用工具和做計劃)

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
筆記全集Book 請至: https://hackmd.io/@4j/r1U_UJ_pye/

2025生成式AI時代下的機器學習_李宏毅
課程網站 https://speech.ee.ntu.edu.tw/~hylee/ml/2025-spring.php

video: https://www.youtube.com/watch?v=M2Yg1kwPpts
[ppt] [pdf]

目錄

AI Agent

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

AI Agent: 人類給予目標, AI自己想辦法達成
若為複雜目標 > 需要多步驟 靈活調整計畫

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

目標 Goal: 人給定目標 做為輸入
環境 Observation: agent觀察目前的狀況
行動 Action: agent採取行動

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

透過 RL 打造 AI Agent
以下棋為例
agent 把目標定為 "學習最大化 Reward"
Reward 是人定的(ex:贏棋,+1)
但這有個侷限:不同任務無法通用

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

▪ **新想法:直接把 LLM 當 agent **
目標: 告訴他遊戲規則、目標
環境: 也轉為文字敘述
行動: 把文字轉為真正可執行的行動
持續運作到達成目標

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

從 LLM 角度看, AI Agent其實也是在做接龍
只是一種語言模型的應用~

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

以下所講的都是倚靠 現有語言模型的能力 所達成的
!!沒有任何模型被訓練!!

以 LLM 運行 AI Agent 的優勢

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

行動不再有局限 無限的輸出能力

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

以前:做 RL 時需要通靈定個 reward
現在:提供 compile log 讓他自己修改行為 (log資訊量也比單一數值多)
Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

更真實的互動情境 應要能即時轉換行動的 而非回合制
ex: 語音對話 會被打斷、講話同時會收到對方的回應

AI Agent 關鍵能力剖析

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

根據經驗調整行為

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

超憶症 (Hyperthymesia)
記憶太長 算力不足時可能無法得到正確答案
對 agent 不是很好

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

memory:長期記憶 內容太長 :(
▪ read 模組:從記憶篩選出跟現在情境相關的訊息
讓模型根據相關經驗跟observation來進行決策
> 用 Retrival 打造
如同RAG, 從資料庫中(所有自己的記憶)檢索

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

▪ write 模組:讓資料庫只記下重要的資訊
> 可用 語言模型(or agent自己) 打造,自問這件事需要記下來嗎

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

▪ reflection 模組:反思 對記憶中的資訊做重新整理 (可能產生新想法)
> 可用 語言模型(or agent自己) 自問
根據整理推論出的新想法做決策

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

▪ 建立 Knowledge Graph:用以前觀察到的經驗 建立經驗間的關係
讓 read 模組根據 Knowledge Graph 來找出相關資訊

ex: GraphRAG, 把資料庫變成 Knowledge Graph, 讓RAG更有效率

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

MemGPT、Agent Workflow Memory、A-MEM: Agentic Memory for LLM Agents

AI 如何使用工具

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

工具:只需要知道怎麼使用,不需要知道內部運作原理
使用工具又叫 "Function Call"

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

System Prompt:你在開發應用的developer所下的prompt, 每次都固定放在最前面的敘述(優先級較高)
User Prompt:此服務的使用者輸入的內容, 每次會不同

> 在 System Prompt 裡面定義好 如何使用工具、工具的使用方式
輸出的文字再去呼叫函示(開發者需自己設定好流程 不給使用者看到)

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

(模型的內心是思考了很多步 才輸出給使用者的)

使用工具的一些例子

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →
Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

工具很多怎麼辦

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

把 工具說明書 全部存到 memory
打造工具選擇模組 協助選出合適的工具

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

模型也可以自己打造工具 並放到工具包中

判斷是否相信工具

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

希望 不因過度相信工具而犯錯

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →
Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

發現模型其實有自己的判斷力的!
內外部知識會拉扯

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

什麼樣的外部知識比較容易說服AI呢
> 若跟內部知識差距太大 就不會相信

還有發現日期較新的也比較相信

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

就算工具是對的 也不代表模型一定不會犯錯
ex: 有RAG, 還是把兩個李宏毅(藝人跟老師)混再一起了
Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

使用工具不一定比較有效率

AI 能不能做計畫

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

請他先產生plan,再去執行,可能會產生得更好
but 與預期不同,導致原有的計畫行不通!
Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

解法:當模型看到新的obs時 就再想想新的計劃~

image
image

可試著 實際跟現實世界互動 找出最佳路徑!
太長的話走的時候要邊判斷是否要繼續 以減少搜索

image
but 有些動作無法回溯><
> 讓一切都發生在 腦內小劇場!
image
image

需要一個 World Model 模擬環境的變化
ex: 模型自導自演

image
image

reasoning 腦內小劇場 即是做驗證做規劃嗎
未來研究:模型有時也會想太多 而不試著去做一下

END