一文读懂大模型技术栈:从LLM、Token到Agent与MCP
前言
大语言模型(LLM)正在重塑人机交互的方式,但它的技术体系远不止“聊天机器人”那么简单。从底层的数学函数、Token切分,到上层的上下文记忆、检索增强,再到工具调用、自主智能体——每一层都有其核心概念与工程挑战。
本文将以分层递进的方式,系统梳理LLM相关的关键术语与技术架构,并配以流程图和对比表格,帮助你建立完整的知识图谱。无论你是AI初学者还是应用开发者,都能从中找到清晰的答案。
第一层:核心引擎与数据单元(LLM & Token)
1.1 LLM:大语言模型
- 底层架构:基于2017年Google提出的 Transformer 架构(具体为Decoder-only变体)。
- 运行本质:一个超级复杂的 文字接龙游戏 —— 不断预测下一个Token,自回归地生成内容。
1.2 Token与Tokenizer:人类与模型的“中间人”
大模型本质上是一个庞大的数学函数,内部全是矩阵运算,它只认识数字,不认识任何文字。因此,我们需要一个“翻译官”。
- Token:模型处理文本的最小单元。它不是单词,而是模型自己学到的切分规则(例如 "unhappiness" → ["un", "happiness"])。
- Tokenizer:执行 编码(文本→Token ID) 与 解码(Token ID→文本) 的组件。
1.3 工作流完整拆解:编码与解码
#mermaid-svg-BywKfq3oNPPHueYh{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-BywKfq3oNPPHueYh .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-BywKfq3oNPPHueYh .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-BywKfq3oNPPHueYh .error-icon{fill:#552222;}#mermaid-svg-BywKfq3oNPPHueYh .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-BywKfq3oNPPHueYh .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-BywKfq3oNPPHueYh .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-BywKfq3oNPPHueYh .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-BywKfq3oNPPHueYh .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-BywKfq3oNPPHueYh .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-BywKfq3oNPPHueYh .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-BywKfq3oNPPHueYh .marker{fill:#333333;stroke:#333333;}#mermaid-svg-BywKfq3oNPPHueYh .marker.cross{stroke:#333333;}#mermaid-svg-BywKfq3oNPPHueYh svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-BywKfq3oNPPHueYh p{margin:0;}#mermaid-svg-BywKfq3oNPPHueYh .label{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;color:#333;}#mermaid-svg-BywKfq3oNPPHueYh .cluster-label text{fill:#333;}#mermaid-svg-BywKfq3oNPPHueYh .cluster-label span{color:#333;}#mermaid-svg-BywKfq3oNPPHueYh .cluster-label span p{background-color:transparent;}#mermaid-svg-BywKfq3oNPPHueYh .label text,#mermaid-svg-BywKfq3oNPPHueYh span{fill:#333;color:#333;}#mermaid-svg-BywKfq3oNPPHueYh .node rect,#mermaid-svg-BywKfq3oNPPHueYh .node circle,#mermaid-svg-BywKfq3oNPPHueYh .node ellipse,#mermaid-svg-BywKfq3oNPPHueYh .node polygon,#mermaid-svg-BywKfq3oNPPHueYh .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-BywKfq3oNPPHueYh .rough-node .label text,#mermaid-svg-BywKfq3oNPPHueYh .node .label text,#mermaid-svg-BywKfq3oNPPHueYh .image-shape .label,#mermaid-svg-BywKfq3oNPPHueYh .icon-shape .label{text-anchor:middle;}#mermaid-svg-BywKfq3oNPPHueYh .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-BywKfq3oNPPHueYh .rough-node .label,#mermaid-svg-BywKfq3oNPPHueYh .node .label,#mermaid-svg-BywKfq3oNPPHueYh .image-shape .label,#mermaid-svg-BywKfq3oNPPHueYh .icon-shape .label{text-align:center;}#mermaid-svg-BywKfq3oNPPHueYh .node.clickable{cursor:pointer;}#mermaid-svg-BywKfq3oNPPHueYh .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-BywKfq3oNPPHueYh .arrowheadPath{fill:#333333;}#mermaid-svg-BywKfq3oNPPHueYh .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-BywKfq3oNPPHueYh .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-BywKfq3oNPPHueYh .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-BywKfq3oNPPHueYh .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-BywKfq3oNPPHueYh .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-BywKfq3oNPPHueYh .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-BywKfq3oNPPHueYh .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-BywKfq3oNPPHueYh .cluster text{fill:#333;}#mermaid-svg-BywKfq3oNPPHueYh .cluster span{color:#333;}#mermaid-svg-BywKfq3oNPPHueYh div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-BywKfq3oNPPHueYh .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-BywKfq3oNPPHueYh rect.text{fill:none;stroke-width:0;}#mermaid-svg-BywKfq3oNPPHueYh .icon-shape,#mermaid-svg-BywKfq3oNPPHueYh .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-BywKfq3oNPPHueYh .icon-shape p,#mermaid-svg-BywKfq3oNPPHueYh .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-BywKfq3oNPPHueYh .icon-shape .label rect,#mermaid-svg-BywKfq3oNPPHueYh .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-BywKfq3oNPPHueYh .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-BywKfq3oNPPHueYh .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-BywKfq3oNPPHueYh :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}
解码
模型推理
编码
否
是
原始文本
Tokenizer切分
Token序列
映射为ID
嵌入+Transformer层
输出概率分布
采样下一个Token ID
是否结束?
ID序列解码
最终文本
第二层:记忆与信息加工(Context & RAG)
2.1 Context:大模型的“临时记忆体”
数学函数如何拥有“记忆”?
答案:它本身没有记忆。背后的程序会自动把你之前的整段对话历史找出来,连同新问题一起打包给大模型。
Context(上下文)定义:大模型每次处理任务时所接收到的信息总和,相当于一个“临时工作台”与“记忆本”。
2.2 Context Window 与 RAG
- Context Window(上下文窗口):Context能容纳的最大Token数量。例如 GPT-4 Turbo 为128K,Claude 3 Opus 为200K,Gemini 1.5 Pro 宣称1M。
- 痛点:将上千页手册全部塞入大模型,成本极高且可能撑爆窗口。
- RAG(检索增强生成)解决方案:
从手册中提取最匹配的片段 → 只将这些片段发送给模型 → 突破窗口限制,降低成本。
#mermaid-svg-GQmLDbquGHOAVQRG{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-GQmLDbquGHOAVQRG .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-GQmLDbquGHOAVQRG .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-GQmLDbquGHOAVQRG .error-icon{fill:#552222;}#mermaid-svg-GQmLDbquGHOAVQRG .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-GQmLDbquGHOAVQRG .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-GQmLDbquGHOAVQRG .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-GQmLDbquGHOAVQRG .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-GQmLDbquGHOAVQRG .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-GQmLDbquGHOAVQRG .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-GQmLDbquGHOAVQRG .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-GQmLDbquGHOAVQRG .marker{fill:#333333;stroke:#333333;}#mermaid-svg-GQmLDbquGHOAVQRG .marker.cross{stroke:#333333;}#mermaid-svg-GQmLDbquGHOAVQRG svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-GQmLDbquGHOAVQRG p{margin:0;}#mermaid-svg-GQmLDbquGHOAVQRG .label{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;color:#333;}#mermaid-svg-GQmLDbquGHOAVQRG .cluster-label text{fill:#333;}#mermaid-svg-GQmLDbquGHOAVQRG .cluster-label span{color:#333;}#mermaid-svg-GQmLDbquGHOAVQRG .cluster-label span p{background-color:transparent;}#mermaid-svg-GQmLDbquGHOAVQRG .label text,#mermaid-svg-GQmLDbquGHOAVQRG span{fill:#333;color:#333;}#mermaid-svg-GQmLDbquGHOAVQRG .node rect,#mermaid-svg-GQmLDbquGHOAVQRG .node circle,#mermaid-svg-GQmLDbquGHOAVQRG .node ellipse,#mermaid-svg-GQmLDbquGHOAVQRG .node polygon,#mermaid-svg-GQmLDbquGHOAVQRG .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-GQmLDbquGHOAVQRG .rough-node .label text,#mermaid-svg-GQmLDbquGHOAVQRG .node .label text,#mermaid-svg-GQmLDbquGHOAVQRG .image-shape .label,#mermaid-svg-GQmLDbquGHOAVQRG .icon-shape .label{text-anchor:middle;}#mermaid-svg-GQmLDbquGHOAVQRG .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-GQmLDbquGHOAVQRG .rough-node .label,#mermaid-svg-GQmLDbquGHOAVQRG .node .label,#mermaid-svg-GQmLDbquGHOAVQRG .image-shape .label,#mermaid-svg-GQmLDbquGHOAVQRG .icon-shape .label{text-align:center;}#mermaid-svg-GQmLDbquGHOAVQRG .node.clickable{cursor:pointer;}#mermaid-svg-GQmLDbquGHOAVQRG .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-GQmLDbquGHOAVQRG .arrowheadPath{fill:#333333;}#mermaid-svg-GQmLDbquGHOAVQRG .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-GQmLDbquGHOAVQRG .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-GQmLDbquGHOAVQRG .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-GQmLDbquGHOAVQRG .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-GQmLDbquGHOAVQRG .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-GQmLDbquGHOAVQRG .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-GQmLDbquGHOAVQRG .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-GQmLDbquGHOAVQRG .cluster text{fill:#333;}#mermaid-svg-GQmLDbquGHOAVQRG .cluster span{color:#333;}#mermaid-svg-GQmLDbquGHOAVQRG div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-GQmLDbquGHOAVQRG .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-GQmLDbquGHOAVQRG rect.text{fill:none;stroke-width:0;}#mermaid-svg-GQmLDbquGHOAVQRG .icon-shape,#mermaid-svg-GQmLDbquGHOAVQRG .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-GQmLDbquGHOAVQRG .icon-shape p,#mermaid-svg-GQmLDbquGHOAVQRG .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-GQmLDbquGHOAVQRG .icon-shape .label rect,#mermaid-svg-GQmLDbquGHOAVQRG .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-GQmLDbquGHOAVQRG .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-GQmLDbquGHOAVQRG .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-GQmLDbquGHOAVQRG :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}
用户问题
检索器
向量数据库知识库
最相关片段
Prompt = 片段 + 问题
大模型
生成答案
第三层:意识控制与沟通(Prompt)
3.1 Prompt 与 Prompt Engineering
- Prompt(提示词):大模型接受的具体问题或指令。
- Prompt Engineering(提示词工程)核心:把话说清楚 —— 明确、结构化、示例引导。
3.2 User Prompt vs System Prompt
| System Prompt(系统提示词) | 设定模型人设、做事规则、输出格式 | 开发者在后台隐式配置 |
| User Prompt(用户提示词) | 提出具体任务需求 | 用户在对话框/前端输入 |
示例:
System: “你是一个专业的Python编程助手,只输出代码和简短注释。”
User: “写一个快速排序函数。”
第四层:外部感知与标准协议(Tool & MCP)
4.1 Tool:感知外部世界的能力
大模型的致命弱点:它只是一个“文字接龙”模型,无法感知外界环境,知识库只停留在训练截止时间,无法获取实时信息(如“今天天气如何”)。
Tool(工具/函数调用) 解决了这个问题。本质上,Tool就是一个函数:
输入参数 → 内部调用外部接口 → 输出结果。有了Tool,大模型就能感知并影响真实的物理世界。
4.2 Tool 的完整调用链路
外部API工具函数LLMUser外部API工具函数LLMUser#mermaid-svg-2QhdC35BcuBROH10{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-2QhdC35BcuBROH10 .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-2QhdC35BcuBROH10 .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-2QhdC35BcuBROH10 .error-icon{fill:#552222;}#mermaid-svg-2QhdC35BcuBROH10 .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-2QhdC35BcuBROH10 .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-2QhdC35BcuBROH10 .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-2QhdC35BcuBROH10 .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-2QhdC35BcuBROH10 .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-2QhdC35BcuBROH10 .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-2QhdC35BcuBROH10 .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-2QhdC35BcuBROH10 .marker{fill:#333333;stroke:#333333;}#mermaid-svg-2QhdC35BcuBROH10 .marker.cross{stroke:#333333;}#mermaid-svg-2QhdC35BcuBROH10 svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-2QhdC35BcuBROH10 p{margin:0;}#mermaid-svg-2QhdC35BcuBROH10 .actor{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:#ECECFF;}#mermaid-svg-2QhdC35BcuBROH10 text.actor>tspan{fill:black;stroke:none;}#mermaid-svg-2QhdC35BcuBROH10 .actor-line{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);}#mermaid-svg-2QhdC35BcuBROH10 .innerArc{stroke-width:1.5;stroke-dasharray:none;}#mermaid-svg-2QhdC35BcuBROH10 .messageLine0{stroke-width:1.5;stroke-dasharray:none;stroke:#333;}#mermaid-svg-2QhdC35BcuBROH10 .messageLine1{stroke-width:1.5;stroke-dasharray:2,2;stroke:#333;}#mermaid-svg-2QhdC35BcuBROH10 #arrowhead path{fill:#333;stroke:#333;}#mermaid-svg-2QhdC35BcuBROH10 .sequenceNumber{fill:white;}#mermaid-svg-2QhdC35BcuBROH10 #sequencenumber{fill:#333;}#mermaid-svg-2QhdC35BcuBROH10 #crosshead path{fill:#333;stroke:#333;}#mermaid-svg-2QhdC35BcuBROH10 .messageText{fill:#333;stroke:none;}#mermaid-svg-2QhdC35BcuBROH10 .labelBox{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:#ECECFF;}#mermaid-svg-2QhdC35BcuBROH10 .labelText,#mermaid-svg-2QhdC35BcuBROH10 .labelText>tspan{fill:black;stroke:none;}#mermaid-svg-2QhdC35BcuBROH10 .loopText,#mermaid-svg-2QhdC35BcuBROH10 .loopText>tspan{fill:black;stroke:none;}#mermaid-svg-2QhdC35BcuBROH10 .loopLine{stroke-width:2px;stroke-dasharray:2,2;stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);}#mermaid-svg-2QhdC35BcuBROH10 .note{stroke:#aaaa33;fill:#fff5ad;}#mermaid-svg-2QhdC35BcuBROH10 .noteText,#mermaid-svg-2QhdC35BcuBROH10 .noteText>tspan{fill:black;stroke:none;}#mermaid-svg-2QhdC35BcuBROH10 .activation0{fill:#f4f4f4;stroke:#666;}#mermaid-svg-2QhdC35BcuBROH10 .activation1{fill:#f4f4f4;stroke:#666;}#mermaid-svg-2QhdC35BcuBROH10 .activation2{fill:#f4f4f4;stroke:#666;}#mermaid-svg-2QhdC35BcuBROH10 .actorPopupMenu{position:absolute;}#mermaid-svg-2QhdC35BcuBROH10 .actorPopupMenuPanel{position:absolute;fill:#ECECFF;box-shadow:0px 8px 16px 0px rgba(0,0,0,0.2);filter:drop-shadow(3px 5px 2px rgb(0 0 0 / 0.4));}#mermaid-svg-2QhdC35BcuBROH10 .actor-man line{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:#ECECFF;}#mermaid-svg-2QhdC35BcuBROH10 .actor-man circle,#mermaid-svg-2QhdC35BcuBROH10 line{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:#ECECFF;stroke-width:2px;}#mermaid-svg-2QhdC35BcuBROH10 :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}“北京今天天气怎么样?”识别需要调用天气工具调用 get_weather(city="北京")请求天气API返回 {"temp":25,"condition":"晴"}返回格式化结果“北京今天晴天,25°C。”
4.3 MCP:统一的接入标准协议
- 工程痛点:不同平台(OpenAI、Anthropic、Cohere等)的工具调用规范各不相同,同一个工具需要按不同规范写多遍代码。
- MCP(模型上下文协议) 解决方案:统一的工具接入规范,就像数码界的 Type-C接口 —— 开发一次,无缝调用任何兼容MCP的模型。
#mermaid-svg-3JONS52caUbmeH47{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-3JONS52caUbmeH47 .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-3JONS52caUbmeH47 .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-3JONS52caUbmeH47 .error-icon{fill:#552222;}#mermaid-svg-3JONS52caUbmeH47 .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-3JONS52caUbmeH47 .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-3JONS52caUbmeH47 .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-3JONS52caUbmeH47 .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-3JONS52caUbmeH47 .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-3JONS52caUbmeH47 .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-3JONS52caUbmeH47 .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-3JONS52caUbmeH47 .marker{fill:#333333;stroke:#333333;}#mermaid-svg-3JONS52caUbmeH47 .marker.cross{stroke:#333333;}#mermaid-svg-3JONS52caUbmeH47 svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-3JONS52caUbmeH47 p{margin:0;}#mermaid-svg-3JONS52caUbmeH47 .label{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;color:#333;}#mermaid-svg-3JONS52caUbmeH47 .cluster-label text{fill:#333;}#mermaid-svg-3JONS52caUbmeH47 .cluster-label span{color:#333;}#mermaid-svg-3JONS52caUbmeH47 .cluster-label span p{background-color:transparent;}#mermaid-svg-3JONS52caUbmeH47 .label text,#mermaid-svg-3JONS52caUbmeH47 span{fill:#333;color:#333;}#mermaid-svg-3JONS52caUbmeH47 .node rect,#mermaid-svg-3JONS52caUbmeH47 .node circle,#mermaid-svg-3JONS52caUbmeH47 .node ellipse,#mermaid-svg-3JONS52caUbmeH47 .node polygon,#mermaid-svg-3JONS52caUbmeH47 .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-3JONS52caUbmeH47 .rough-node .label text,#mermaid-svg-3JONS52caUbmeH47 .node .label text,#mermaid-svg-3JONS52caUbmeH47 .image-shape .label,#mermaid-svg-3JONS52caUbmeH47 .icon-shape .label{text-anchor:middle;}#mermaid-svg-3JONS52caUbmeH47 .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-3JONS52caUbmeH47 .rough-node .label,#mermaid-svg-3JONS52caUbmeH47 .node .label,#mermaid-svg-3JONS52caUbmeH47 .image-shape .label,#mermaid-svg-3JONS52caUbmeH47 .icon-shape .label{text-align:center;}#mermaid-svg-3JONS52caUbmeH47 .node.clickable{cursor:pointer;}#mermaid-svg-3JONS52caUbmeH47 .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-3JONS52caUbmeH47 .arrowheadPath{fill:#333333;}#mermaid-svg-3JONS52caUbmeH47 .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-3JONS52caUbmeH47 .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-3JONS52caUbmeH47 .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-3JONS52caUbmeH47 .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-3JONS52caUbmeH47 .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-3JONS52caUbmeH47 .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-3JONS52caUbmeH47 .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-3JONS52caUbmeH47 .cluster text{fill:#333;}#mermaid-svg-3JONS52caUbmeH47 .cluster span{color:#333;}#mermaid-svg-3JONS52caUbmeH47 div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-3JONS52caUbmeH47 .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-3JONS52caUbmeH47 rect.text{fill:none;stroke-width:0;}#mermaid-svg-3JONS52caUbmeH47 .icon-shape,#mermaid-svg-3JONS52caUbmeH47 .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-3JONS52caUbmeH47 .icon-shape p,#mermaid-svg-3JONS52caUbmeH47 .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-3JONS52caUbmeH47 .icon-shape .label rect,#mermaid-svg-3JONS52caUbmeH47 .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-3JONS52caUbmeH47 .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-3JONS52caUbmeH47 .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-3JONS52caUbmeH47 :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}
MCP方式
天气工具
MCP适配层
任意MCP兼容模型
传统方式
天气工具
OpenAI格式
Claude格式
Gemini格式
第五层:自主智能与定制化(Agent & Agent Skill)
5.1 走向自主规划:Agent(智能体)
复杂需求示例:查天气,不下雨则推荐附近的公园。
这需要模型:思考 → 规划 → 执行/调用工具 → 观察结果 → 再思考 → … → 完成。
核心定义:
Agent = 能够自主规划、自主调用工具、持续运作直至完成任务的系统。
#mermaid-svg-ByJV9TEHt4pZPEeX{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-ByJV9TEHt4pZPEeX .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-ByJV9TEHt4pZPEeX .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-ByJV9TEHt4pZPEeX .error-icon{fill:#552222;}#mermaid-svg-ByJV9TEHt4pZPEeX .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-ByJV9TEHt4pZPEeX .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-ByJV9TEHt4pZPEeX .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-ByJV9TEHt4pZPEeX .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-ByJV9TEHt4pZPEeX .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-ByJV9TEHt4pZPEeX .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-ByJV9TEHt4pZPEeX .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-ByJV9TEHt4pZPEeX .marker{fill:#333333;stroke:#333333;}#mermaid-svg-ByJV9TEHt4pZPEeX .marker.cross{stroke:#333333;}#mermaid-svg-ByJV9TEHt4pZPEeX svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-ByJV9TEHt4pZPEeX p{margin:0;}#mermaid-svg-ByJV9TEHt4pZPEeX .label{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;color:#333;}#mermaid-svg-ByJV9TEHt4pZPEeX .cluster-label text{fill:#333;}#mermaid-svg-ByJV9TEHt4pZPEeX .cluster-label span{color:#333;}#mermaid-svg-ByJV9TEHt4pZPEeX .cluster-label span p{background-color:transparent;}#mermaid-svg-ByJV9TEHt4pZPEeX .label text,#mermaid-svg-ByJV9TEHt4pZPEeX span{fill:#333;color:#333;}#mermaid-svg-ByJV9TEHt4pZPEeX .node rect,#mermaid-svg-ByJV9TEHt4pZPEeX .node circle,#mermaid-svg-ByJV9TEHt4pZPEeX .node ellipse,#mermaid-svg-ByJV9TEHt4pZPEeX .node polygon,#mermaid-svg-ByJV9TEHt4pZPEeX .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-ByJV9TEHt4pZPEeX .rough-node .label text,#mermaid-svg-ByJV9TEHt4pZPEeX .node .label text,#mermaid-svg-ByJV9TEHt4pZPEeX .image-shape .label,#mermaid-svg-ByJV9TEHt4pZPEeX .icon-shape .label{text-anchor:middle;}#mermaid-svg-ByJV9TEHt4pZPEeX .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-ByJV9TEHt4pZPEeX .rough-node .label,#mermaid-svg-ByJV9TEHt4pZPEeX .node .label,#mermaid-svg-ByJV9TEHt4pZPEeX .image-shape .label,#mermaid-svg-ByJV9TEHt4pZPEeX .icon-shape .label{text-align:center;}#mermaid-svg-ByJV9TEHt4pZPEeX .node.clickable{cursor:pointer;}#mermaid-svg-ByJV9TEHt4pZPEeX .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-ByJV9TEHt4pZPEeX .arrowheadPath{fill:#333333;}#mermaid-svg-ByJV9TEHt4pZPEeX .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-ByJV9TEHt4pZPEeX .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-ByJV9TEHt4pZPEeX .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-ByJV9TEHt4pZPEeX .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-ByJV9TEHt4pZPEeX .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-ByJV9TEHt4pZPEeX .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-ByJV9TEHt4pZPEeX .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-ByJV9TEHt4pZPEeX .cluster text{fill:#333;}#mermaid-svg-ByJV9TEHt4pZPEeX .cluster span{color:#333;}#mermaid-svg-ByJV9TEHt4pZPEeX div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-ByJV9TEHt4pZPEeX .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-ByJV9TEHt4pZPEeX rect.text{fill:none;stroke-width:0;}#mermaid-svg-ByJV9TEHt4pZPEeX .icon-shape,#mermaid-svg-ByJV9TEHt4pZPEeX .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-ByJV9TEHt4pZPEeX .icon-shape p,#mermaid-svg-ByJV9TEHt4pZPEeX .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-ByJV9TEHt4pZPEeX .icon-shape .label rect,#mermaid-svg-ByJV9TEHt4pZPEeX .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-ByJV9TEHt4pZPEeX .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-ByJV9TEHt4pZPEeX .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-ByJV9TEHt4pZPEeX :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}
是
否
用户目标
思考:需要什么信息?
规划:先查天气,再判断
执行:调用天气Tool
观察:得到天气结果
下雨吗?
调用室内推荐Tool
调用公园推荐Tool
获得推荐
输出最终答案
5.2 Agent Skill:专属的“行为说明书”
- 痛点:每次与Agent对话都要重复输入个人习惯(例如“下雨记得提醒我带伞”“所有回答用Markdown表格”),极其反人类。
- Agent Skill 登场:一份存放在本地的Markdown说明文档,预先“塞”给Agent。Agent按需读取,节省Token,彻底定制其行为。
示例 Skill 文件(my_preferences.md):
## 个人偏好
– 回答天气时,同时给出湿度建议
– 代码输出必须包含时间复杂度注释
– 禁止使用emoji
之后每次对话,Agent会自动遵循这些规则。
架构总结:AI底层框架全景图
#mermaid-svg-OAl9dvLZrXSYNABx{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-OAl9dvLZrXSYNABx .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-OAl9dvLZrXSYNABx .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-OAl9dvLZrXSYNABx .error-icon{fill:#552222;}#mermaid-svg-OAl9dvLZrXSYNABx .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-OAl9dvLZrXSYNABx .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-OAl9dvLZrXSYNABx .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-OAl9dvLZrXSYNABx .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-OAl9dvLZrXSYNABx .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-OAl9dvLZrXSYNABx .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-OAl9dvLZrXSYNABx .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-OAl9dvLZrXSYNABx .marker{fill:#333333;stroke:#333333;}#mermaid-svg-OAl9dvLZrXSYNABx .marker.cross{stroke:#333333;}#mermaid-svg-OAl9dvLZrXSYNABx svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-OAl9dvLZrXSYNABx p{margin:0;}#mermaid-svg-OAl9dvLZrXSYNABx .label{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;color:#333;}#mermaid-svg-OAl9dvLZrXSYNABx .cluster-label text{fill:#333;}#mermaid-svg-OAl9dvLZrXSYNABx .cluster-label span{color:#333;}#mermaid-svg-OAl9dvLZrXSYNABx .cluster-label span p{background-color:transparent;}#mermaid-svg-OAl9dvLZrXSYNABx .label text,#mermaid-svg-OAl9dvLZrXSYNABx span{fill:#333;color:#333;}#mermaid-svg-OAl9dvLZrXSYNABx .node rect,#mermaid-svg-OAl9dvLZrXSYNABx .node circle,#mermaid-svg-OAl9dvLZrXSYNABx .node ellipse,#mermaid-svg-OAl9dvLZrXSYNABx .node polygon,#mermaid-svg-OAl9dvLZrXSYNABx .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-OAl9dvLZrXSYNABx .rough-node .label text,#mermaid-svg-OAl9dvLZrXSYNABx .node .label text,#mermaid-svg-OAl9dvLZrXSYNABx .image-shape .label,#mermaid-svg-OAl9dvLZrXSYNABx .icon-shape .label{text-anchor:middle;}#mermaid-svg-OAl9dvLZrXSYNABx .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-OAl9dvLZrXSYNABx .rough-node .label,#mermaid-svg-OAl9dvLZrXSYNABx .node .label,#mermaid-svg-OAl9dvLZrXSYNABx .image-shape .label,#mermaid-svg-OAl9dvLZrXSYNABx .icon-shape .label{text-align:center;}#mermaid-svg-OAl9dvLZrXSYNABx .node.clickable{cursor:pointer;}#mermaid-svg-OAl9dvLZrXSYNABx .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-OAl9dvLZrXSYNABx .arrowheadPath{fill:#333333;}#mermaid-svg-OAl9dvLZrXSYNABx .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-OAl9dvLZrXSYNABx .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-OAl9dvLZrXSYNABx .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-OAl9dvLZrXSYNABx .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-OAl9dvLZrXSYNABx .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-OAl9dvLZrXSYNABx .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-OAl9dvLZrXSYNABx .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-OAl9dvLZrXSYNABx .cluster text{fill:#333;}#mermaid-svg-OAl9dvLZrXSYNABx .cluster span{color:#333;}#mermaid-svg-OAl9dvLZrXSYNABx div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-OAl9dvLZrXSYNABx .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-OAl9dvLZrXSYNABx rect.text{fill:none;stroke-width:0;}#mermaid-svg-OAl9dvLZrXSYNABx .icon-shape,#mermaid-svg-OAl9dvLZrXSYNABx .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-OAl9dvLZrXSYNABx .icon-shape p,#mermaid-svg-OAl9dvLZrXSYNABx .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-OAl9dvLZrXSYNABx .icon-shape .label rect,#mermaid-svg-OAl9dvLZrXSYNABx .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-OAl9dvLZrXSYNABx .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-OAl9dvLZrXSYNABx .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-OAl9dvLZrXSYNABx :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}
数据基础层
模型核心层
智能体层
交互与定制
用户层
感知外部
用户 / 开发者
System Prompt
Agent Skill
Agent自主规划+循环
Tool / MCP
大语言模型Transformer
Context + Context Window
RAG检索
Tokenizer / Token
| 数据基础层 | Token, Tokenizer | 文本与数字的转换 |
| 模型核心层 | LLM, Context, RAG | 计算、记忆、信息增强 |
| 交互与定制层 | System Prompt, Agent Skill | 设定模型行为风格 |
| 智能体层 | Agent, Tool, MCP | 自主规划与执行 |
| 用户层 | 用户/开发者 | 发起目标与配置 |
写在最后
从最底层的Token切分,到上层的Agent自主规划,大模型技术栈正在快速标准化。理解每一层的职责与边界,不仅能帮你写出更高效的Prompt,还能让你在设计AI应用时做出更合理的技术选型。
下一步学习建议:
- 动手实践:用LangChain或AutoGen搭建一个简单的Agent
- 深入RAG:学习向量数据库(Chroma, Milvus)与嵌入模型
- 关注MCP:模型上下文协议可能成为未来的统一标准





