[{"data":1,"prerenderedAt":820},["ShallowReactive",2],{"navigation":3,"\u002Farticles\u002Fllm-to-agent":34,"\u002Farticles\u002Fllm-to-agent-surround":815},[4],{"title":5,"path":6,"stem":7,"children":8,"page":33},"Articles","\u002Farticles","articles",[9,13,17,21,25,29],{"title":10,"path":11,"stem":12},"用 Daily Snapshot 提升統計查詢速度","\u002Farticles\u002Fdaily-snapshot","articles\u002Fdaily-snapshot",{"title":14,"path":15,"stem":16},"GKE 部署","\u002Farticles\u002Fgke-deployment","articles\u002Fgke-deployment",{"title":18,"path":19,"stem":20},"從 LLM 到 Agent：打通底層邏輯","\u002Farticles\u002Fllm-to-agent","articles\u002Fllm-to-agent",{"title":22,"path":23,"stem":24},"資訊安全實踐","\u002Farticles\u002Fsecurity-best-practices","articles\u002Fsecurity-best-practices",{"title":26,"path":27,"stem":28},"單機架構的性能優化","\u002Farticles\u002Fsingle-machine-performance","articles\u002Fsingle-machine-performance",{"title":30,"path":31,"stem":32},"伺服器渲染 SSR","\u002Farticles\u002Fssr","articles\u002Fssr",false,{"id":35,"title":18,"author":36,"body":40,"date":805,"description":806,"extension":807,"externalUrl":808,"image":809,"meta":810,"minRead":811,"navigation":812,"path":19,"seo":813,"stem":20,"__hash__":814},"blog\u002Farticles\u002Fllm-to-agent.md",{"name":37,"avatar":38},"Gary",{"src":39,"alt":37},"\u002Fimages\u002Fselfie.webp",{"type":41,"value":42,"toc":790},"minimark",[43,48,57,60,63,74,85,88,92,99,105,108,111,151,154,156,160,169,172,178,181,184,186,190,193,198,201,207,211,214,220,224,227,233,236,238,242,249,252,258,261,408,411,469,472,475,477,481,484,490,496,499,555,558,560,564,570,573,579,585,588,591,650,652,656,663,669,672,688,691,693,696,699,780,783,786],[44,45,47],"h2",{"id":46},"llm-是什麼","LLM 是什麼？",[49,50,51,52,56],"p",{},"LLM（Large Language Model，大型語言模型）的核心能力只有一件事：",[53,54,55],"strong",{},"預測下一個 token","。",[49,58,59],{},"給定一段輸入文字，模型計算「下一個最可能出現的詞」，再把這個詞接到輸入後面，繼續預測下下一個，如此循環，直到產生完整回覆。",[49,61,62],{},"這個過程看似簡單，但在海量語料上訓練後，模型學會了語言規律、邏輯推理、知識記憶。GPT、Claude、Gemini，背後都是這套機制。",[64,65,70],"pre",{"className":66,"code":68,"language":69},[67],"language-text","輸入：「台灣的首都是」\n預測：「台」→「北」→「市」→「。」\n輸出：「台北市。」\n","text",[71,72,68],"code",{"__ignoreMap":73},"",[49,75,76,77,80,81,84],{},"關鍵在於，LLM ",[53,78,79],{},"沒有記憶","，也",[53,82,83],{},"不會主動做任何事","。它只是一個函式：給輸入，回傳輸出。所有「智能」的外觀，都是在這個函式之上建構的。",[86,87],"hr",{},[44,89,91],{"id":90},"token模型的基本單位","Token：模型的基本單位",[49,93,94,95,98],{},"模型不是逐字元讀文字，而是把文字切成 ",[53,96,97],{},"token","（語言片段）再處理。",[64,100,103],{"className":101,"code":102,"language":69},[67],"\"Hello, world!\" → [\"Hello\", \",\", \" world\", \"!\"]  → 4 tokens\n\"你好世界\"       → [\"你\", \"好\", \"世\", \"界\"]        → 4 tokens\n\"PostgreSQL\"     → [\"Post\", \"gre\", \"SQL\"]          → 3 tokens\n",[71,104,102],{"__ignoreMap":73},[49,106,107],{},"Token 的切分取決於模型使用的 tokenizer，不同語言的效率差很多。英文大約 1 個單字 = 1～2 tokens；中文則通常每個字就是 1 token。",[49,109,110],{},"Token 在工程上有兩個重要影響：",[112,113,114,127],"table",{},[115,116,117],"thead",{},[118,119,120,124],"tr",{},[121,122,123],"th",{},"面向",[121,125,126],{},"影響",[128,129,130,141],"tbody",{},[118,131,132,138],{},[133,134,135],"td",{},[53,136,137],{},"費用",[133,139,140],{},"API 通常按 token 計費（輸入 + 輸出分開算）",[118,142,143,148],{},[133,144,145],{},[53,146,147],{},"限制",[133,149,150],{},"每次呼叫有 context window 上限（例如 200K tokens）",[49,152,153],{},"理解 token 讓你在設計 prompt 時更有感知，知道什麼樣的寫法會讓費用暴增。",[86,155],{},[44,157,159],{"id":158},"context模型唯一能看見的東西","Context：模型唯一能看見的東西",[49,161,162,163,165,166,56],{},"LLM ",[53,164,79],{},"。每次呼叫，模型只能看到你這次傳進去的內容，稱為 ",[53,167,168],{},"context window",[49,170,171],{},"Context 的內容通常包含：",[64,173,176],{"className":174,"code":175,"language":69},[67],"System Prompt   → 角色設定、行為規則\n對話歷史        → 過去幾輪的 user \u002F assistant 訊息\n當前輸入        → 使用者這次說的話\n工具回傳結果    → 如果有用到 tool，結果也會塞進來\n",[71,177,175],{"__ignoreMap":73},[49,179,180],{},"「AI 記得你說過什麼」其實是應用層把歷史對話每次都一起送進去，不是模型真的記得。",[49,182,183],{},"Context window 的大小決定了模型能「記住」多長的對話。超過上限，最早的訊息就會被截掉。這是 AI 應用設計時最常踩的坑之一：對話太長導致模型「忘記」前面的指令或資料。",[86,185],{},[44,187,189],{"id":188},"prompt和模型溝通的介面","Prompt：和模型溝通的介面",[49,191,192],{},"Prompt 是你傳給模型的輸入。寫得好，模型表現好；寫得差，結果一塌糊塗。",[194,195,197],"h3",{"id":196},"system-prompt","System Prompt",[49,199,200],{},"定義模型的角色與行為邊界：",[64,202,205],{"className":203,"code":204,"language":69},[67],"你是一個後端工程師助手，用繁體中文回答問題。\n回答要簡潔，只給關鍵結論，不用解釋廢話。\n如果不確定，就說不知道，不要亂猜。\n",[71,206,204],{"__ignoreMap":73},[194,208,210],{"id":209},"few-shot-prompting","Few-shot Prompting",[49,212,213],{},"提供幾個範例，讓模型學習你期望的輸出格式：",[64,215,218],{"className":216,"code":217,"language":69},[67],"將以下錯誤訊息翻譯成繁體中文，格式如下：\n原文：Connection refused\n翻譯：連線被拒絕\n\n原文：Timeout exceeded\n翻譯：連線逾時\n\n原文：Permission denied\n翻譯：\n",[71,219,217],{"__ignoreMap":73},[194,221,223],{"id":222},"chain-of-thought","Chain-of-Thought",[49,225,226],{},"要求模型逐步推理，再給出答案，對複雜問題準確率明顯提升：",[64,228,231],{"className":229,"code":230,"language":69},[67],"請一步一步思考，然後給出結論。\n",[71,232,230],{"__ignoreMap":73},[49,234,235],{},"Prompt 工程本質上是在告訴模型「你是誰、你要做什麼、你怎麼做」。越清楚，模型越可靠。",[86,237],{},[44,239,241],{"id":240},"tool讓模型有手腳","Tool：讓模型有手腳",[49,243,244,245,248],{},"LLM 本身只能輸出文字，無法執行任何操作。",[53,246,247],{},"Tool（工具調用）"," 讓模型能呼叫外部函式，突破這個限制。",[49,250,251],{},"流程如下：",[64,253,256],{"className":254,"code":255,"language":69},[67],"1. 你定義一組工具（函式簽名 + 描述）\n2. 把工具定義連同 prompt 一起送給模型\n3. 模型決定要呼叫哪個工具，輸出結構化的呼叫指令\n4. 應用層執行這個函式，取得結果\n5. 把結果塞回 context，模型繼續生成回覆\n",[71,257,255],{"__ignoreMap":73},[49,259,260],{},"範例：定義一個查天氣的工具",[64,262,266],{"className":263,"code":264,"language":265,"meta":73,"style":73},"language-json shiki shiki-themes material-theme-lighter material-theme material-theme-palenight","{\n  \"name\": \"get_weather\",\n  \"description\": \"查詢指定城市的目前天氣\",\n  \"parameters\": {\n    \"city\": { \"type\": \"string\", \"description\": \"城市名稱\" }\n  }\n}\n","json",[71,267,268,277,305,326,341,396,402],{"__ignoreMap":73},[269,270,273],"span",{"class":271,"line":272},"line",1,[269,274,276],{"class":275},"sMK4o","{\n",[269,278,280,283,287,290,293,296,300,302],{"class":271,"line":279},2,[269,281,282],{"class":275},"  \"",[269,284,286],{"class":285},"spNyl","name",[269,288,289],{"class":275},"\"",[269,291,292],{"class":275},":",[269,294,295],{"class":275}," \"",[269,297,299],{"class":298},"sfazB","get_weather",[269,301,289],{"class":275},[269,303,304],{"class":275},",\n",[269,306,308,310,313,315,317,319,322,324],{"class":271,"line":307},3,[269,309,282],{"class":275},[269,311,312],{"class":285},"description",[269,314,289],{"class":275},[269,316,292],{"class":275},[269,318,295],{"class":275},[269,320,321],{"class":298},"查詢指定城市的目前天氣",[269,323,289],{"class":275},[269,325,304],{"class":275},[269,327,329,331,334,336,338],{"class":271,"line":328},4,[269,330,282],{"class":275},[269,332,333],{"class":285},"parameters",[269,335,289],{"class":275},[269,337,292],{"class":275},[269,339,340],{"class":275}," {\n",[269,342,344,347,351,353,355,358,360,364,366,368,370,373,375,378,380,382,384,386,388,391,393],{"class":271,"line":343},5,[269,345,346],{"class":275},"    \"",[269,348,350],{"class":349},"sBMFI","city",[269,352,289],{"class":275},[269,354,292],{"class":275},[269,356,357],{"class":275}," {",[269,359,295],{"class":275},[269,361,363],{"class":362},"sbssI","type",[269,365,289],{"class":275},[269,367,292],{"class":275},[269,369,295],{"class":275},[269,371,372],{"class":298},"string",[269,374,289],{"class":275},[269,376,377],{"class":275},",",[269,379,295],{"class":275},[269,381,312],{"class":362},[269,383,289],{"class":275},[269,385,292],{"class":275},[269,387,295],{"class":275},[269,389,390],{"class":298},"城市名稱",[269,392,289],{"class":275},[269,394,395],{"class":275}," }\n",[269,397,399],{"class":271,"line":398},6,[269,400,401],{"class":275},"  }\n",[269,403,405],{"class":271,"line":404},7,[269,406,407],{"class":275},"}\n",[49,409,410],{},"模型收到「台北現在幾度？」，就會輸出：",[64,412,414],{"className":263,"code":413,"language":265,"meta":73,"style":73},"{ \"tool\": \"get_weather\", \"arguments\": { \"city\": \"台北\" } }\n",[71,415,416],{"__ignoreMap":73},[269,417,418,421,423,426,428,430,432,434,436,438,440,443,445,447,449,451,453,455,457,459,462,464,467],{"class":271,"line":272},[269,419,420],{"class":275},"{",[269,422,295],{"class":275},[269,424,425],{"class":285},"tool",[269,427,289],{"class":275},[269,429,292],{"class":275},[269,431,295],{"class":275},[269,433,299],{"class":298},[269,435,289],{"class":275},[269,437,377],{"class":275},[269,439,295],{"class":275},[269,441,442],{"class":285},"arguments",[269,444,289],{"class":275},[269,446,292],{"class":275},[269,448,357],{"class":275},[269,450,295],{"class":275},[269,452,350],{"class":349},[269,454,289],{"class":275},[269,456,292],{"class":275},[269,458,295],{"class":275},[269,460,461],{"class":298},"台北",[269,463,289],{"class":275},[269,465,466],{"class":275}," }",[269,468,395],{"class":275},[49,470,471],{},"應用層執行後把結果傳回去，模型再組合成自然語言回覆給用戶。",[49,473,474],{},"Tool 讓 LLM 從「只會說話」變成「說話 + 做事」。",[86,476],{},[44,478,480],{"id":479},"mcptool-的標準化協議","MCP：Tool 的標準化協議",[49,482,483],{},"當你的系統有幾十個工具，每個都要自己寫定義、串接、維護，會很累。",[49,485,486,489],{},[53,487,488],{},"MCP（Model Context Protocol）"," 是 Anthropic 提出的開放協議，定義了「模型如何和外部工具溝通」的標準格式，讓工具可以被任何支援 MCP 的模型複用。",[64,491,494],{"className":492,"code":493,"language":69},[67],"LLM ←→ MCP Client ←→ MCP Server ←→ 資料庫 \u002F API \u002F 檔案系統\n",[71,495,493],{"__ignoreMap":73},[49,497,498],{},"MCP Server 暴露三種能力：",[112,500,501,514],{},[115,502,503],{},[118,504,505,508,511],{},[121,506,507],{},"類型",[121,509,510],{},"說明",[121,512,513],{},"範例",[128,515,516,529,542],{},[118,517,518,523,526],{},[133,519,520],{},[53,521,522],{},"Tools",[133,524,525],{},"模型可以呼叫的函式",[133,527,528],{},"查資料庫、送 API",[118,530,531,536,539],{},[133,532,533],{},[53,534,535],{},"Resources",[133,537,538],{},"模型可以讀取的資料",[133,540,541],{},"讀檔案、讀文件",[118,543,544,549,552],{},[133,545,546],{},[53,547,548],{},"Prompts",[133,550,551],{},"預設的 prompt 範本",[133,553,554],{},"分析報表的固定格式",[49,556,557],{},"有了 MCP，工具開發者只需要寫一次 MCP Server，任何相容的 AI 應用都能直接使用。類似 USB 統一了硬體接口的概念。",[86,559],{},[44,561,563],{"id":562},"agent自主完成任務的執行者","Agent：自主完成任務的執行者",[49,565,566,567,56],{},"把上面所有東西組合起來，就是 ",[53,568,569],{},"Agent",[49,571,572],{},"Agent 的核心是一個循環（ReAct Loop）：",[64,574,577],{"className":575,"code":576,"language":69},[67],"思考（Think）→ 行動（Act）→ 觀察結果（Observe）→ 再思考 → …\n",[71,578,576],{"__ignoreMap":73},[64,580,583],{"className":581,"code":582,"language":69},[67],"用戶：「幫我分析這週的銷售數據，找出異常。」\n\nAgent 循環：\n  第 1 輪：呼叫 get_sales_data(week=\"this_week\")\n  第 2 輪：讀取資料，呼叫 calculate_stats()\n  第 3 輪：發現週三數字異常低，呼叫 get_order_logs(date=\"週三\")\n  第 4 輪：分析日誌，整理出結論\n  輸出：「週三下午 3 點系統有 2 小時停機，導致 47 筆訂單流失，影響營業額約 NT$12 萬。」\n",[71,584,582],{"__ignoreMap":73},[49,586,587],{},"Agent 不需要人在每一步指示，它會自己決定下一步要做什麼，一直到任務完成。",[49,589,590],{},"與一般的「問答模型」最大的差別：",[112,592,593,604],{},[115,594,595],{},[118,596,597,599,602],{},[121,598],{},[121,600,601],{},"問答模型",[121,603,569],{},[128,605,606,617,628,639],{},[118,607,608,611,614],{},[133,609,610],{},"執行方式",[133,612,613],{},"一問一答",[133,615,616],{},"自主多步執行",[118,618,619,622,625],{},[133,620,621],{},"工具使用",[133,623,624],{},"可以",[133,626,627],{},"可以，且自主決定何時用",[118,629,630,633,636],{},[133,631,632],{},"任務長度",[133,634,635],{},"單輪",[133,637,638],{},"多輪，直到完成",[118,640,641,644,647],{},[133,642,643],{},"需要人介入",[133,645,646],{},"每步都需要",[133,648,649],{},"只需給目標",[86,651],{},[44,653,655],{"id":654},"agent-skill可組合的專業能力","Agent Skill：可組合的專業能力",[49,657,658,659,662],{},"隨著 Agent 的應用越來越複雜，出現了 ",[53,660,661],{},"Agent Skill"," 的概念：把某個專業領域的能力封裝成獨立模組，讓 Agent 可以像呼叫工具一樣呼叫「技能」。",[64,664,667],{"className":665,"code":666,"language":69},[67],"主 Agent（協調者）\n  ├── Skill: 資料分析   → 專門處理數據、統計、圖表\n  ├── Skill: 程式碼生成 → 專門寫 \u002F 審 \u002F 解釋程式碼\n  ├── Skill: 網路搜尋   → 專門搜尋、整理外部資訊\n  └── Skill: 報告撰寫   → 專門把結果整理成文件\n",[71,668,666],{"__ignoreMap":73},[49,670,671],{},"Skill 和 Tool 的差別：",[673,674,675,682],"ul",{},[676,677,678,681],"li",{},[53,679,680],{},"Tool","：一個具體的函式，做一件事（查天氣、送 email）",[676,683,684,687],{},[53,685,686],{},"Skill","：一個包含 prompt + tools + 邏輯的完整能力模組（分析報表、產生程式碼）",[49,689,690],{},"Skill 讓複雜任務可以被分解、分工，不同 Skill 可以平行執行，最後由主 Agent 整合結果。這是目前 AI 應用走向「Multi-Agent 系統」的基礎架構。",[86,692],{},[44,694,695],{"id":695},"總結",[49,697,698],{},"從 LLM 到 Agent，每一層都在解決上一層的限制：",[112,700,701,711],{},[115,702,703],{},[118,704,705,708],{},[121,706,707],{},"層次",[121,709,710],{},"解決的問題",[128,712,713,723,733,743,752,762,771],{},[118,714,715,720],{},[133,716,717],{},[53,718,719],{},"LLM",[133,721,722],{},"理解語言、推理、生成文字",[118,724,725,730],{},[133,726,727],{},[53,728,729],{},"Token \u002F Context",[133,731,732],{},"理解模型的輸入邊界與費用結構",[118,734,735,740],{},[133,736,737],{},[53,738,739],{},"Prompt",[133,741,742],{},"讓模型的行為可預測、可控制",[118,744,745,749],{},[133,746,747],{},[53,748,680],{},[133,750,751],{},"讓模型能操作外部系統",[118,753,754,759],{},[133,755,756],{},[53,757,758],{},"MCP",[133,760,761],{},"標準化工具協議，可重複使用",[118,763,764,768],{},[133,765,766],{},[53,767,569],{},[133,769,770],{},"自主多步執行，完成複雜任務",[118,772,773,777],{},[133,774,775],{},[53,776,661],{},[133,778,779],{},"模組化能力，支撐 Multi-Agent 架構",[49,781,782],{},"理解這條鏈路，才能在實際開發 AI 應用時做出正確的架構決策：什麼情況下用單輪問答就夠了、什麼情況下需要 Agent、工具要怎麼設計、context 要怎麼管理。",[49,784,785],{},"LLM 只是起點，Agent 才是終點。",[787,788,789],"style",{},"html pre.shiki code .sMK4o, html code.shiki .sMK4o{--shiki-light:#39ADB5;--shiki-default:#89DDFF;--shiki-dark:#89DDFF}html pre.shiki code .spNyl, html code.shiki .spNyl{--shiki-light:#9C3EDA;--shiki-default:#C792EA;--shiki-dark:#C792EA}html pre.shiki code .sfazB, html code.shiki .sfazB{--shiki-light:#91B859;--shiki-default:#C3E88D;--shiki-dark:#C3E88D}html pre.shiki code .sBMFI, html code.shiki .sBMFI{--shiki-light:#E2931D;--shiki-default:#FFCB6B;--shiki-dark:#FFCB6B}html pre.shiki code .sbssI, html code.shiki .sbssI{--shiki-light:#F76D47;--shiki-default:#F78C6C;--shiki-dark:#F78C6C}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":73,"searchDepth":279,"depth":279,"links":791},[792,793,794,795,800,801,802,803,804],{"id":46,"depth":279,"text":47},{"id":90,"depth":279,"text":91},{"id":158,"depth":279,"text":159},{"id":188,"depth":279,"text":189,"children":796},[797,798,799],{"id":196,"depth":307,"text":197},{"id":209,"depth":307,"text":210},{"id":222,"depth":307,"text":223},{"id":240,"depth":279,"text":241},{"id":479,"depth":279,"text":480},{"id":562,"depth":279,"text":563},{"id":654,"depth":279,"text":655},{"id":695,"depth":279,"text":695},"2025-07-20","從 Token、Context、Prompt，到 Tool、MCP、Agent，完整梳理 AI 應用開發的核心概念與底層運作原理。","md",null,"\u002Fimages\u002Fdata-flow.jpg",{},12,true,{"title":18,"description":806},"i52aRjvH8JEP_i6dc3uplneiyxvN_ougNgYexSfwOks",[816,818],{"title":14,"path":15,"stem":16,"description":817,"children":-1},"記錄將個人電商（GShop）部署到 GKE Autopilot 的完整流程。",{"title":22,"path":23,"stem":24,"description":819,"children":-1},"整理日常開發中常用的資安觀念與實踐方式。",1781661891873]