aquachieh
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Note Insights Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    1
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # [2025李宏毅ML] 第2講:一堂課搞懂 AI Agent 的原理 (AI如何透過經驗調整行為、使用工具和做計劃) :::success :+1: 筆記全集Book 請至: https://hackmd.io/@4j/r1U_UJ_pye/ ::: :::info 2025生成式AI時代下的機器學習_李宏毅 課程網站 https://speech.ee.ntu.edu.tw/~hylee/ml/2025-spring.php video: https://www.youtube.com/watch?v=M2Yg1kwPpts [[ppt]](https://www.youtube.com/redirect?event=video_description&redir_token=QUFFLUhqa2xsZlNOc25FWkdIQzBReDZoLWs4T0xybXFLUXxBQ3Jtc0tuNGkwakdvTG9VdzJaTFVEeEdLS2tmbno5V2I3VEtidkNEQVFYdmwtVFRqWlkwbVZBU2w5S1dVdktQQkctaVlIQXZDNS1ZUTVaUmhsZTl5QW1yNmJSYnV6TFlqRjB6SzhWYy10MEY3VlQ4ekNuZ3lqWQ&q=https%3A%2F%2Fdocs.google.com%2Fpresentation%2Fd%2F1kTxukwlmx2Sc9H7aGPTiNiPdk4zN_NoH%2Fedit%3Fusp%3Dsharing%26ouid%3D115046073158939078465%26rtpof%3Dtrue%26sd%3Dtrue&v=M2Yg1kwPpts) [[pdf]](https://speech.ee.ntu.edu.tw/~hylee/ml/ml2025-course-data/ai_agent.pdf) ::: :::spoiler 目錄 [TOC] ::: ## AI Agent ![image](https://hackmd.io/_uploads/B1q3yZCiJg.png =500x) AI Agent: 人類給予目標, AI自己想辦法達成 若為複雜目標 --> 需要多步驟 靈活調整計畫 ![image](https://hackmd.io/_uploads/rJ7AJWCoyx.png =500x) **目標 Goal**: 人給定目標 做為輸入 **環境 Observation**: agent觀察目前的狀況 **行動 Action**: agent採取行動 ![image](https://hackmd.io/_uploads/rydxeZAokl.png =500x) ▪ **透過 RL 打造 AI Agent** 以下棋為例 agent 把目標定為 **"學習最大化 Reward"** Reward 是人定的(ex:贏棋,+1) 但這有個侷限:不同任務無法通用 ![image](https://hackmd.io/_uploads/rkeMlbRo1e.png =500x) ▪ **新想法:直接把 LLM 當 agent** 目標: 告訴他遊戲規則、目標 環境: 也轉為文字敘述 行動: 把文字轉為真正可執行的行動 持續運作到達成目標 ![image](https://hackmd.io/_uploads/BJsQxZAjkx.png =500x) 從 LLM 角度看, AI Agent其實也是在做接龍 只是一種語言模型的應用~ ![image](https://hackmd.io/_uploads/SyEUIU1nyg.png =400x) 以下所講的都是倚靠 **現有語言模型的能力** 所達成的 !!沒有任何模型被訓練!! ## 以 LLM 運行 AI Agent 的優勢 ![image](https://hackmd.io/_uploads/S1OHxZCiye.png =500x) 行動不再有局限 無限的輸出能力 ![image](https://hackmd.io/_uploads/rk-UgbAj1x.png =500x) 以前:做 RL 時需要通靈定個 reward 現在:提供 compile log 讓他自己修改行為 (log資訊量也比單一數值多) ![image](https://hackmd.io/_uploads/HkfcFZ7n1l.png =500x) ![image](https://hackmd.io/_uploads/B13zqZm21e.png =500x) ![image](https://hackmd.io/_uploads/SyeE9ZXhkl.png =500x) 更真實的互動情境 應要能即時轉換行動的 而非回合制 ex: 語音對話 會被打斷、講話同時會收到對方的回應 ## AI Agent 關鍵能力剖析 ![image](https://hackmd.io/_uploads/Byt9lGm2Jg.png =500x) ### 根據經驗調整行為 ![image](https://hackmd.io/_uploads/Ske8SMm3ye.png =500x) ![image](https://hackmd.io/_uploads/rJoUSzmnJl.png =500x) ▪ **超憶症 (Hyperthymesia)** 記憶太長 算力不足時可能無法得到正確答案 對 agent 不是很好 ![image](https://hackmd.io/_uploads/HJAvSzQ3ye.png =500x) memory:長期記憶 內容太長 :( **▪ read 模組**:從記憶篩選出跟現在情境相關的訊息 讓模型根據相關經驗跟observation來進行決策 --> 用 **Retrival** 打造 如同RAG, 從資料庫中(所有自己的記憶)檢索 ![image](https://hackmd.io/_uploads/B1zPczmnJx.png =500x) **▪ write 模組**:讓資料庫只記下重要的資訊 --> 可用 **語言模型(or agent自己)** 打造,自問這件事需要記下來嗎 ![image](https://hackmd.io/_uploads/SJfdqfmhke.png =500x) **▪ reflection 模組**:反思 對記憶中的資訊做重新整理 (可能產生新想法) --> 可用 **語言模型(or agent自己)** 自問 根據整理推論出的**新想法**做決策 ![image](https://hackmd.io/_uploads/BJGY5MQhye.png =500x) **▪ 建立 Knowledge Graph**:用以前觀察到的經驗 建立經驗間的關係 讓 read 模組根據 Knowledge Graph 來找出相關資訊 ex: GraphRAG, 把資料庫變成 Knowledge Graph, 讓RAG更有效率 ![image](https://hackmd.io/_uploads/SkGfkXmnyg.png =500x) MemGPT、Agent Workflow Memory、A-MEM: Agentic Memory for LLM Agents ### AI 如何使用工具 ![image](https://hackmd.io/_uploads/B1_-bX7n1l.png =500x) 工具:只需要知道怎麼使用,不需要知道內部運作原理 使用工具又叫 ==**"Function Call"**== ![image](https://hackmd.io/_uploads/BkmzZQm2kg.png =500x) ==**System Prompt**==:你在開發應用的 developer 所下的 prompt , 每次都固定放在最前面的敘述(優先級較高) ==**User Prompt**==:此服務的使用者輸入的內容, 每次會不同 --> **在 System Prompt 裡面定義好 如何使用工具、工具的使用方式** 輸出的文字再去呼叫函示(開發者需自己設定好流程 不給使用者看到) ![image](https://hackmd.io/_uploads/H1ofQX7hyl.png =500x) (模型的內心是思考了很多步 才輸出給使用者的) ▪ **使用工具的一些例子** ![image](https://hackmd.io/_uploads/S1aMV7mhyl.png =300x) ![image](https://hackmd.io/_uploads/Hkv7N7Q31g.png =300x) ![image](https://hackmd.io/_uploads/B1TvNX721l.png =500x) ▪ **工具很多怎麼辦** ![image](https://hackmd.io/_uploads/BJdUBQXhyg.png =500x) 把 工具說明書 全部存到 memory 打造 **工具選擇模組** 協助選出合適的工具 ![image](https://hackmd.io/_uploads/Hk1YSQ7hyx.png =500x) 模型也可以自己打造工具 並放到工具包中 ▪ **判斷是否相信工具** ![image](https://hackmd.io/_uploads/ByYqu7mn1e.png =500x) 希望 不因過度相信工具而犯錯 ![image](https://hackmd.io/_uploads/H1xnO773ke.png =300x) ![image](https://hackmd.io/_uploads/HJeA_Qmn1g.png =300x) 發現模型其實有自己的判斷力的! 內外部知識會拉扯 ![image](https://hackmd.io/_uploads/rJT5tmX2kx.png =500x) 什麼樣的外部知識比較容易說服AI呢 --> 若跟內部知識**差距太大** 就不會相信 還有發現**日期較新**的也比較相信 ![image](https://hackmd.io/_uploads/HkcFsQ73ke.png =500x) 就算工具是對的 也不代表模型一定不會犯錯 ex: 有RAG, 還是把兩個李宏毅(藝人跟老師)混再一起了 ![image](https://hackmd.io/_uploads/r1hsommnkx.png =500x) 使用工具不一定比較有效率 ### AI 能不能做計畫 ![image](https://hackmd.io/_uploads/ByRJdSX2yl.png =500x) 請他先產生 plan,再去執行,可能會產生得更好 but 與預期不同,導致原有的計畫行不通! ![image](https://hackmd.io/_uploads/BkAedBmhyg.png =500x) 解法:當模型看到新的obs時 就再想想新的計劃~ ![image](https://hackmd.io/_uploads/ry0onS7nkl.png =300x) ![image](https://hackmd.io/_uploads/B1dnhB7h1e.png =300x) 可試著 實際跟現實世界互動 找出最佳路徑! 太長的話走的時候要邊判斷是否要繼續 以減少搜索 ![image](https://hackmd.io/_uploads/rkVT2SXnyl.png =500x) but 有些動作無法回溯>< --> 讓一切都發生在 **腦內小劇場**! ![image](https://hackmd.io/_uploads/SJq8prXh1l.png =300x) ![image](https://hackmd.io/_uploads/S1bw6rQnke.png =300x) 需要一個 World Model 模擬環境的變化 ex: 模型自導自演 ![image](https://hackmd.io/_uploads/Hk4saBX2kx.png =500x) ![image](https://hackmd.io/_uploads/Byns6HQhye.png =500x) **reasoning 腦內小劇場** 即是做驗證做規劃嗎 未來研究:模型有時也會想太多 而不試著去做一下 -- END --

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully