[{"data":1,"prerenderedAt":944},["ShallowReactive",2],{"article-other\u002Flangchain-middleware":3},{"_path":4,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":8,"description":9,"date":10,"tags":11,"body":13,"_type":938,"_id":939,"_source":940,"_file":941,"_stem":942,"_extension":943},"\u002Farticles\u002Fother\u002Flangchain-middleware","other",false,"","从 Vue 生命周期与 Spring AOP 理解 LangChain Middleware","对比 Vue 生命周期钩子、Spring AOP 与 LangChain Middleware，理解 Hook 是执行节点，Middleware 是封装横切能力的模块。","2026-08-14",[12],"随笔",{"type":14,"children":15,"toc":929},"root",[16,24,30,35,41,46,51,81,86,282,287,405,410,416,421,426,501,514,519,526,531,536,559,564,570,575,765,793,798,803,904,909,918,923],{"type":17,"tag":18,"props":19,"children":21},"element","h2",{"id":20},"起因",[22],{"type":23,"value":20},"text",{"type":17,"tag":25,"props":26,"children":27},"p",{},[28],{"type":23,"value":29},"看 B 站的 LangChain 视频时学到了 Middleware（中间件），于是想到一个问题：前端 Vue、后端 Spring Boot 和 Agent 开发中，有没有相似的设计思想？",{"type":17,"tag":25,"props":31,"children":32},{},[33],{"type":23,"value":34},"先说结论：Vue 生命周期钩子、Spring AOP 和 LangChain Middleware 不是同一个概念，但都允许开发者在不改动主流程的情况下，在框架预留的执行节点插入扩展逻辑。",{"type":17,"tag":18,"props":36,"children":38},{"id":37},"langchain-中的-hook-与-middleware",[39],{"type":23,"value":40},"LangChain 中的 Hook 与 Middleware",{"type":17,"tag":25,"props":42,"children":43},{},[44],{"type":23,"value":45},"Hook（钩子）是框架在执行流程中暴露的扩展点。开发者可以把自己的逻辑挂到这些节点上，在不修改 Agent Loop 主流程的情况下，完成日志、校验、状态更新、重试或权限控制等工作。",{"type":17,"tag":25,"props":47,"children":48},{},[49],{"type":23,"value":50},"LangChain 的 Middleware 则是对这些扩展逻辑的封装。一个 Middleware 可以实现一个或多个 Hook，并作为可复用模块添加到 Agent 中：",{"type":17,"tag":52,"props":53,"children":56},"pre",{"className":54,"code":55,"language":23,"meta":7,"style":7},"language-text shiki shiki-themes github-dark","Hook：Agent 执行流程中的一个介入点\nMiddleware：利用一个或多个 Hook 封装出来的完整功能\n",[57],{"type":17,"tag":58,"props":59,"children":60},"code",{"__ignoreMap":7},[61,72],{"type":17,"tag":62,"props":63,"children":66},"span",{"class":64,"line":65},"line",1,[67],{"type":17,"tag":62,"props":68,"children":69},{},[70],{"type":23,"value":71},"Hook：Agent 执行流程中的一个介入点\n",{"type":17,"tag":62,"props":73,"children":75},{"class":64,"line":74},2,[76],{"type":17,"tag":62,"props":77,"children":78},{},[79],{"type":23,"value":80},"Middleware：利用一个或多个 Hook 封装出来的完整功能\n",{"type":17,"tag":25,"props":82,"children":83},{},[84],{"type":23,"value":85},"LangChain 当前提供两类 Middleware Hook：",{"type":17,"tag":87,"props":88,"children":89},"table",{},[90,119],{"type":17,"tag":91,"props":92,"children":93},"thead",{},[94],{"type":17,"tag":95,"props":96,"children":97},"tr",{},[98,104,109,114],{"type":17,"tag":99,"props":100,"children":101},"th",{},[102],{"type":23,"value":103},"类型",{"type":17,"tag":99,"props":105,"children":106},{},[107],{"type":23,"value":108},"Hook",{"type":17,"tag":99,"props":110,"children":111},{},[112],{"type":23,"value":113},"执行时机",{"type":17,"tag":99,"props":115,"children":116},{},[117],{"type":23,"value":118},"适合处理",{"type":17,"tag":120,"props":121,"children":122},"tbody",{},[123,151,177,203,229,256],{"type":17,"tag":95,"props":124,"children":125},{},[126,132,141,146],{"type":17,"tag":127,"props":128,"children":129},"td",{},[130],{"type":23,"value":131},"节点式",{"type":17,"tag":127,"props":133,"children":134},{},[135],{"type":17,"tag":58,"props":136,"children":138},{"className":137},[],[139],{"type":23,"value":140},"before_agent",{"type":17,"tag":127,"props":142,"children":143},{},[144],{"type":23,"value":145},"Agent 每次调用开始前",{"type":17,"tag":127,"props":147,"children":148},{},[149],{"type":23,"value":150},"请求校验、初始化状态",{"type":17,"tag":95,"props":152,"children":153},{},[154,158,167,172],{"type":17,"tag":127,"props":155,"children":156},{},[157],{"type":23,"value":131},{"type":17,"tag":127,"props":159,"children":160},{},[161],{"type":17,"tag":58,"props":162,"children":164},{"className":163},[],[165],{"type":23,"value":166},"before_model",{"type":17,"tag":127,"props":168,"children":169},{},[170],{"type":23,"value":171},"每次调用模型前",{"type":17,"tag":127,"props":173,"children":174},{},[175],{"type":23,"value":176},"修改状态、限制消息数量",{"type":17,"tag":95,"props":178,"children":179},{},[180,184,193,198],{"type":17,"tag":127,"props":181,"children":182},{},[183],{"type":23,"value":131},{"type":17,"tag":127,"props":185,"children":186},{},[187],{"type":17,"tag":58,"props":188,"children":190},{"className":189},[],[191],{"type":23,"value":192},"after_model",{"type":17,"tag":127,"props":194,"children":195},{},[196],{"type":23,"value":197},"每次收到模型响应后",{"type":17,"tag":127,"props":199,"children":200},{},[201],{"type":23,"value":202},"检查响应、更新状态",{"type":17,"tag":95,"props":204,"children":205},{},[206,210,219,224],{"type":17,"tag":127,"props":207,"children":208},{},[209],{"type":23,"value":131},{"type":17,"tag":127,"props":211,"children":212},{},[213],{"type":17,"tag":58,"props":214,"children":216},{"className":215},[],[217],{"type":23,"value":218},"after_agent",{"type":17,"tag":127,"props":220,"children":221},{},[222],{"type":23,"value":223},"Agent 每次调用结束后",{"type":17,"tag":127,"props":225,"children":226},{},[227],{"type":23,"value":228},"最终校验、记录结果",{"type":17,"tag":95,"props":230,"children":231},{},[232,237,246,251],{"type":17,"tag":127,"props":233,"children":234},{},[235],{"type":23,"value":236},"包裹式",{"type":17,"tag":127,"props":238,"children":239},{},[240],{"type":17,"tag":58,"props":241,"children":243},{"className":242},[],[244],{"type":23,"value":245},"wrap_model_call",{"type":17,"tag":127,"props":247,"children":248},{},[249],{"type":23,"value":250},"包裹每次模型调用",{"type":17,"tag":127,"props":252,"children":253},{},[254],{"type":23,"value":255},"重试、缓存、模型切换",{"type":17,"tag":95,"props":257,"children":258},{},[259,263,272,277],{"type":17,"tag":127,"props":260,"children":261},{},[262],{"type":23,"value":236},{"type":17,"tag":127,"props":264,"children":265},{},[266],{"type":17,"tag":58,"props":267,"children":269},{"className":268},[],[270],{"type":23,"value":271},"wrap_tool_call",{"type":17,"tag":127,"props":273,"children":274},{},[275],{"type":23,"value":276},"包裹每次工具调用",{"type":17,"tag":127,"props":278,"children":279},{},[280],{"type":23,"value":281},"权限检查、异常处理、监控",{"type":17,"tag":25,"props":283,"children":284},{},[285],{"type":23,"value":286},"它们大致位于下面这条执行链路中：",{"type":17,"tag":52,"props":288,"children":290},{"className":54,"code":289,"language":23,"meta":7,"style":7},"用户输入\n   ↓\nbefore_agent（一次）\n   ↓\nbefore_model → wrap_model_call → 模型 → after_model\n                                  ↓\n                       wrap_tool_call → 工具\n                                  ↓\n                         回到模型继续判断\n   ↓\nafter_agent（一次）\n   ↓\n最终结果\n",[291],{"type":17,"tag":58,"props":292,"children":293},{"__ignoreMap":7},[294,302,310,319,327,336,345,354,362,371,379,388,396],{"type":17,"tag":62,"props":295,"children":296},{"class":64,"line":65},[297],{"type":17,"tag":62,"props":298,"children":299},{},[300],{"type":23,"value":301},"用户输入\n",{"type":17,"tag":62,"props":303,"children":304},{"class":64,"line":74},[305],{"type":17,"tag":62,"props":306,"children":307},{},[308],{"type":23,"value":309},"   ↓\n",{"type":17,"tag":62,"props":311,"children":313},{"class":64,"line":312},3,[314],{"type":17,"tag":62,"props":315,"children":316},{},[317],{"type":23,"value":318},"before_agent（一次）\n",{"type":17,"tag":62,"props":320,"children":322},{"class":64,"line":321},4,[323],{"type":17,"tag":62,"props":324,"children":325},{},[326],{"type":23,"value":309},{"type":17,"tag":62,"props":328,"children":330},{"class":64,"line":329},5,[331],{"type":17,"tag":62,"props":332,"children":333},{},[334],{"type":23,"value":335},"before_model → wrap_model_call → 模型 → after_model\n",{"type":17,"tag":62,"props":337,"children":339},{"class":64,"line":338},6,[340],{"type":17,"tag":62,"props":341,"children":342},{},[343],{"type":23,"value":344},"                                  ↓\n",{"type":17,"tag":62,"props":346,"children":348},{"class":64,"line":347},7,[349],{"type":17,"tag":62,"props":350,"children":351},{},[352],{"type":23,"value":353},"                       wrap_tool_call → 工具\n",{"type":17,"tag":62,"props":355,"children":357},{"class":64,"line":356},8,[358],{"type":17,"tag":62,"props":359,"children":360},{},[361],{"type":23,"value":344},{"type":17,"tag":62,"props":363,"children":365},{"class":64,"line":364},9,[366],{"type":17,"tag":62,"props":367,"children":368},{},[369],{"type":23,"value":370},"                         回到模型继续判断\n",{"type":17,"tag":62,"props":372,"children":374},{"class":64,"line":373},10,[375],{"type":17,"tag":62,"props":376,"children":377},{},[378],{"type":23,"value":309},{"type":17,"tag":62,"props":380,"children":382},{"class":64,"line":381},11,[383],{"type":17,"tag":62,"props":384,"children":385},{},[386],{"type":23,"value":387},"after_agent（一次）\n",{"type":17,"tag":62,"props":389,"children":391},{"class":64,"line":390},12,[392],{"type":17,"tag":62,"props":393,"children":394},{},[395],{"type":23,"value":309},{"type":17,"tag":62,"props":397,"children":399},{"class":64,"line":398},13,[400],{"type":17,"tag":62,"props":401,"children":402},{},[403],{"type":23,"value":404},"最终结果\n",{"type":17,"tag":25,"props":406,"children":407},{},[408],{"type":23,"value":409},"因此，Hook 更像一个具体的“检查点”，Middleware 更像安装在一个或多个检查点上的“完整功能模块”。",{"type":17,"tag":18,"props":411,"children":413},{"id":412},"spring-boot-中的-aop",[414],{"type":23,"value":415},"Spring Boot 中的 AOP",{"type":17,"tag":25,"props":417,"children":418},{},[419],{"type":23,"value":420},"AOP（Aspect-Oriented Programming，面向切面编程）是 Spring 中的重要概念。它将日志、事务、权限检查等横切关注点从业务逻辑中分离出来，避免在大量业务方法中重复编写相同代码。",{"type":17,"tag":25,"props":422,"children":423},{},[424],{"type":23,"value":425},"以 Service 方法为例：",{"type":17,"tag":52,"props":427,"children":429},{"className":54,"code":428,"language":23,"meta":7,"style":7},"Controller 调用\n   ↓\nSpring AOP 代理\n   ├── 方法执行前：开启事务、检查权限、记录日志\n   ↓\n真正的 Service 方法\n   ↓\nSpring AOP 代理\n   └── 方法执行后：提交或回滚事务、记录结果\n",[430],{"type":17,"tag":58,"props":431,"children":432},{"__ignoreMap":7},[433,441,448,456,464,471,479,486,493],{"type":17,"tag":62,"props":434,"children":435},{"class":64,"line":65},[436],{"type":17,"tag":62,"props":437,"children":438},{},[439],{"type":23,"value":440},"Controller 调用\n",{"type":17,"tag":62,"props":442,"children":443},{"class":64,"line":74},[444],{"type":17,"tag":62,"props":445,"children":446},{},[447],{"type":23,"value":309},{"type":17,"tag":62,"props":449,"children":450},{"class":64,"line":312},[451],{"type":17,"tag":62,"props":452,"children":453},{},[454],{"type":23,"value":455},"Spring AOP 代理\n",{"type":17,"tag":62,"props":457,"children":458},{"class":64,"line":321},[459],{"type":17,"tag":62,"props":460,"children":461},{},[462],{"type":23,"value":463},"   ├── 方法执行前：开启事务、检查权限、记录日志\n",{"type":17,"tag":62,"props":465,"children":466},{"class":64,"line":329},[467],{"type":17,"tag":62,"props":468,"children":469},{},[470],{"type":23,"value":309},{"type":17,"tag":62,"props":472,"children":473},{"class":64,"line":338},[474],{"type":17,"tag":62,"props":475,"children":476},{},[477],{"type":23,"value":478},"真正的 Service 方法\n",{"type":17,"tag":62,"props":480,"children":481},{"class":64,"line":347},[482],{"type":17,"tag":62,"props":483,"children":484},{},[485],{"type":23,"value":309},{"type":17,"tag":62,"props":487,"children":488},{"class":64,"line":356},[489],{"type":17,"tag":62,"props":490,"children":491},{},[492],{"type":23,"value":455},{"type":17,"tag":62,"props":494,"children":495},{"class":64,"line":364},[496],{"type":17,"tag":62,"props":497,"children":498},{},[499],{"type":23,"value":500},"   └── 方法执行后：提交或回滚事务、记录结果\n",{"type":17,"tag":25,"props":502,"children":503},{},[504,506,512],{"type":23,"value":505},"Spring 的 ",{"type":17,"tag":58,"props":507,"children":509},{"className":508},[],[510],{"type":23,"value":511},"@Transactional",{"type":23,"value":513}," 是常见例子：在默认代理模式下，Spring 通过 AOP 代理在方法调用前开启事务，成功后提交，发生符合回滚规则的异常时回滚。",{"type":17,"tag":25,"props":515,"children":516},{},[517],{"type":23,"value":518},"Spring AOP 与 LangChain Middleware 的相似点是：二者都适合封装日志、监控、权限和异常处理等横切逻辑。区别是，Spring AOP 主要围绕 Spring Bean 的方法调用工作，而 LangChain Middleware 围绕 Agent、模型和工具的执行流程工作。",{"type":17,"tag":520,"props":521,"children":523},"h3",{"id":522},"ioc-与这条类比的关系",[524],{"type":23,"value":525},"IoC 与这条类比的关系",{"type":17,"tag":25,"props":527,"children":528},{},[529],{"type":23,"value":530},"IoC（Inversion of Control，控制反转）负责把对象的创建、依赖组装和生命周期管理交给 Spring 容器。它是 Spring 的重要基础，但不是一种流程拦截机制，因此不能直接对应 LangChain Hook。",{"type":17,"tag":25,"props":532,"children":533},{},[534],{"type":23,"value":535},"可以简单记成：",{"type":17,"tag":52,"props":537,"children":539},{"className":54,"code":538,"language":23,"meta":7,"style":7},"IoC：管理对象和依赖\nAOP：在方法调用前后织入横切逻辑\n",[540],{"type":17,"tag":58,"props":541,"children":542},{"__ignoreMap":7},[543,551],{"type":17,"tag":62,"props":544,"children":545},{"class":64,"line":65},[546],{"type":17,"tag":62,"props":547,"children":548},{},[549],{"type":23,"value":550},"IoC：管理对象和依赖\n",{"type":17,"tag":62,"props":552,"children":553},{"class":64,"line":74},[554],{"type":17,"tag":62,"props":555,"children":556},{},[557],{"type":23,"value":558},"AOP：在方法调用前后织入横切逻辑\n",{"type":17,"tag":25,"props":560,"children":561},{},[562],{"type":23,"value":563},"Spring 容器先管理 Bean，Spring AOP 再为符合条件的 Bean 创建代理并应用切面逻辑。",{"type":17,"tag":18,"props":565,"children":567},{"id":566},"vue-中的生命周期-hook",[568],{"type":23,"value":569},"Vue 中的生命周期 Hook",{"type":17,"tag":25,"props":571,"children":572},{},[573],{"type":23,"value":574},"Vue 组件会经历创建、挂载、更新和卸载等阶段。生命周期 Hook 让开发者可以在这些固定阶段执行自己的逻辑。",{"type":17,"tag":52,"props":576,"children":578},{"className":54,"code":577,"language":23,"meta":7,"style":7},"创建组件\n   ↓\nsetup 阶段：创建响应式状态并同步注册生命周期 Hook\n   ↓\nonBeforeMount：即将首次渲染，组件 DOM 还没有创建\n   ↓\n生成并插入 DOM\n   ↓\nonMounted：组件已经挂载，可以访问 DOM\n   ↓\n响应式数据变化\n   ↓\nonBeforeUpdate：数据已经变化，DOM 还没有完成更新\n   ↓\n更新 DOM\n   ↓\nonUpdated：DOM 已经完成更新\n   ↓\nonBeforeUnmount：组件即将卸载，此时组件仍然可用\n   ↓\n移除组件\n   ↓\nonUnmounted：清理定时器、事件监听器和连接\n",[579],{"type":17,"tag":58,"props":580,"children":581},{"__ignoreMap":7},[582,590,597,605,612,620,627,635,642,650,657,665,672,680,688,697,705,714,722,731,739,748,756],{"type":17,"tag":62,"props":583,"children":584},{"class":64,"line":65},[585],{"type":17,"tag":62,"props":586,"children":587},{},[588],{"type":23,"value":589},"创建组件\n",{"type":17,"tag":62,"props":591,"children":592},{"class":64,"line":74},[593],{"type":17,"tag":62,"props":594,"children":595},{},[596],{"type":23,"value":309},{"type":17,"tag":62,"props":598,"children":599},{"class":64,"line":312},[600],{"type":17,"tag":62,"props":601,"children":602},{},[603],{"type":23,"value":604},"setup 阶段：创建响应式状态并同步注册生命周期 Hook\n",{"type":17,"tag":62,"props":606,"children":607},{"class":64,"line":321},[608],{"type":17,"tag":62,"props":609,"children":610},{},[611],{"type":23,"value":309},{"type":17,"tag":62,"props":613,"children":614},{"class":64,"line":329},[615],{"type":17,"tag":62,"props":616,"children":617},{},[618],{"type":23,"value":619},"onBeforeMount：即将首次渲染，组件 DOM 还没有创建\n",{"type":17,"tag":62,"props":621,"children":622},{"class":64,"line":338},[623],{"type":17,"tag":62,"props":624,"children":625},{},[626],{"type":23,"value":309},{"type":17,"tag":62,"props":628,"children":629},{"class":64,"line":347},[630],{"type":17,"tag":62,"props":631,"children":632},{},[633],{"type":23,"value":634},"生成并插入 DOM\n",{"type":17,"tag":62,"props":636,"children":637},{"class":64,"line":356},[638],{"type":17,"tag":62,"props":639,"children":640},{},[641],{"type":23,"value":309},{"type":17,"tag":62,"props":643,"children":644},{"class":64,"line":364},[645],{"type":17,"tag":62,"props":646,"children":647},{},[648],{"type":23,"value":649},"onMounted：组件已经挂载，可以访问 DOM\n",{"type":17,"tag":62,"props":651,"children":652},{"class":64,"line":373},[653],{"type":17,"tag":62,"props":654,"children":655},{},[656],{"type":23,"value":309},{"type":17,"tag":62,"props":658,"children":659},{"class":64,"line":381},[660],{"type":17,"tag":62,"props":661,"children":662},{},[663],{"type":23,"value":664},"响应式数据变化\n",{"type":17,"tag":62,"props":666,"children":667},{"class":64,"line":390},[668],{"type":17,"tag":62,"props":669,"children":670},{},[671],{"type":23,"value":309},{"type":17,"tag":62,"props":673,"children":674},{"class":64,"line":398},[675],{"type":17,"tag":62,"props":676,"children":677},{},[678],{"type":23,"value":679},"onBeforeUpdate：数据已经变化，DOM 还没有完成更新\n",{"type":17,"tag":62,"props":681,"children":683},{"class":64,"line":682},14,[684],{"type":17,"tag":62,"props":685,"children":686},{},[687],{"type":23,"value":309},{"type":17,"tag":62,"props":689,"children":691},{"class":64,"line":690},15,[692],{"type":17,"tag":62,"props":693,"children":694},{},[695],{"type":23,"value":696},"更新 DOM\n",{"type":17,"tag":62,"props":698,"children":700},{"class":64,"line":699},16,[701],{"type":17,"tag":62,"props":702,"children":703},{},[704],{"type":23,"value":309},{"type":17,"tag":62,"props":706,"children":708},{"class":64,"line":707},17,[709],{"type":17,"tag":62,"props":710,"children":711},{},[712],{"type":23,"value":713},"onUpdated：DOM 已经完成更新\n",{"type":17,"tag":62,"props":715,"children":717},{"class":64,"line":716},18,[718],{"type":17,"tag":62,"props":719,"children":720},{},[721],{"type":23,"value":309},{"type":17,"tag":62,"props":723,"children":725},{"class":64,"line":724},19,[726],{"type":17,"tag":62,"props":727,"children":728},{},[729],{"type":23,"value":730},"onBeforeUnmount：组件即将卸载，此时组件仍然可用\n",{"type":17,"tag":62,"props":732,"children":734},{"class":64,"line":733},20,[735],{"type":17,"tag":62,"props":736,"children":737},{},[738],{"type":23,"value":309},{"type":17,"tag":62,"props":740,"children":742},{"class":64,"line":741},21,[743],{"type":17,"tag":62,"props":744,"children":745},{},[746],{"type":23,"value":747},"移除组件\n",{"type":17,"tag":62,"props":749,"children":751},{"class":64,"line":750},22,[752],{"type":17,"tag":62,"props":753,"children":754},{},[755],{"type":23,"value":309},{"type":17,"tag":62,"props":757,"children":759},{"class":64,"line":758},23,[760],{"type":17,"tag":62,"props":761,"children":762},{},[763],{"type":23,"value":764},"onUnmounted：清理定时器、事件监听器和连接\n",{"type":17,"tag":25,"props":766,"children":767},{},[768,770,776,778,784,786,791],{"type":23,"value":769},"需要注意，",{"type":17,"tag":58,"props":771,"children":773},{"className":772},[],[774],{"type":23,"value":775},"setup",{"type":23,"value":777}," 是组件的设置阶段，不是 ",{"type":17,"tag":58,"props":779,"children":781},{"className":780},[],[782],{"type":23,"value":783},"onXxx",{"type":23,"value":785}," 形式的生命周期 Hook；生命周期 Hook 需要在 ",{"type":17,"tag":58,"props":787,"children":789},{"className":788},[],[790],{"type":23,"value":775},{"type":23,"value":792}," 阶段同步注册。",{"type":17,"tag":25,"props":794,"children":795},{},[796],{"type":23,"value":797},"Vue 生命周期 Hook 与 LangChain Hook 的相似点是：框架先定义执行流程和扩展节点，开发者再决定是否在这些节点注册逻辑。区别是，Vue Hook 关注组件和 DOM 的生命周期，LangChain Hook 关注 Agent 的推理与工具调用流程。",{"type":17,"tag":18,"props":799,"children":801},{"id":800},"三者的共同点与区别",[802],{"type":23,"value":800},{"type":17,"tag":87,"props":804,"children":805},{},[806,832],{"type":17,"tag":91,"props":807,"children":808},{},[809],{"type":17,"tag":95,"props":810,"children":811},{},[812,817,822,827],{"type":17,"tag":99,"props":813,"children":814},{},[815],{"type":23,"value":816},"领域",{"type":17,"tag":99,"props":818,"children":819},{},[820],{"type":23,"value":821},"介入对象",{"type":17,"tag":99,"props":823,"children":824},{},[825],{"type":23,"value":826},"主要机制",{"type":17,"tag":99,"props":828,"children":829},{},[830],{"type":23,"value":831},"常见用途",{"type":17,"tag":120,"props":833,"children":834},{},[835,858,881],{"type":17,"tag":95,"props":836,"children":837},{},[838,843,848,853],{"type":17,"tag":127,"props":839,"children":840},{},[841],{"type":23,"value":842},"Vue 生命周期 Hook",{"type":17,"tag":127,"props":844,"children":845},{},[846],{"type":23,"value":847},"组件生命周期",{"type":17,"tag":127,"props":849,"children":850},{},[851],{"type":23,"value":852},"在固定生命周期节点执行回调",{"type":17,"tag":127,"props":854,"children":855},{},[856],{"type":23,"value":857},"操作 DOM、初始化资源、清理副作用",{"type":17,"tag":95,"props":859,"children":860},{},[861,866,871,876],{"type":17,"tag":127,"props":862,"children":863},{},[864],{"type":23,"value":865},"Spring AOP",{"type":17,"tag":127,"props":867,"children":868},{},[869],{"type":23,"value":870},"Spring Bean 的方法调用",{"type":17,"tag":127,"props":872,"children":873},{},[874],{"type":23,"value":875},"通过切点匹配方法，由代理执行通知",{"type":17,"tag":127,"props":877,"children":878},{},[879],{"type":23,"value":880},"事务、日志、权限、监控",{"type":17,"tag":95,"props":882,"children":883},{},[884,889,894,899],{"type":17,"tag":127,"props":885,"children":886},{},[887],{"type":23,"value":888},"LangChain Middleware",{"type":17,"tag":127,"props":890,"children":891},{},[892],{"type":23,"value":893},"Agent、模型和工具执行流程",{"type":17,"tag":127,"props":895,"children":896},{},[897],{"type":23,"value":898},"通过节点式或包裹式 Hook 介入",{"type":17,"tag":127,"props":900,"children":901},{},[902],{"type":23,"value":903},"Guardrail、重试、状态更新、模型与工具控制",{"type":17,"tag":25,"props":905,"children":906},{},[907],{"type":23,"value":908},"所以，三者最准确的关系不是“相同概念”，而是共享了相似的扩展思想：",{"type":17,"tag":910,"props":911,"children":912},"blockquote",{},[913],{"type":17,"tag":25,"props":914,"children":915},{},[916],{"type":23,"value":917},"框架负责主流程，开发者通过预留的扩展点加入横切逻辑，让核心业务保持清晰。",{"type":17,"tag":25,"props":919,"children":920},{},[921],{"type":23,"value":922},"进一步记忆：Hook 是一个执行节点；Middleware 或 Aspect 是利用这些节点组织起来的功能模块；IoC 则负责对象与依赖管理，属于另一条设计主线。",{"type":17,"tag":924,"props":925,"children":926},"style",{},[927],{"type":23,"value":928},"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);}",{"title":7,"searchDepth":74,"depth":74,"links":930},[931,932,933,936,937],{"id":20,"depth":74,"text":20},{"id":37,"depth":74,"text":40},{"id":412,"depth":74,"text":415,"children":934},[935],{"id":522,"depth":312,"text":525},{"id":566,"depth":74,"text":569},{"id":800,"depth":74,"text":800},"markdown","content:articles:other:langchain-middleware.md","content","articles\u002Fother\u002Flangchain-middleware.md","articles\u002Fother\u002Flangchain-middleware","md",1789465115003]