主题
中间件集成
使用 LangChain Python 集成中间件。
浏览适用于不同服务商的现成中间件,或将你自己的中间件贡献给生态系统。在中间件概览中进一步了解中间件的工作方式,并在 Deep Agents 文档中了解如何将中间件与 Deep Agents 配合使用。
分享你的中间件
中间件支持上下文工程、harness 定制和运行时安全控制。它是 LangChain 中一个有用的扩展点,我们乐于展示社区用它构建的成果:
精选集成
| 服务商 | 可用中间件 | 源码 | 下载量 | | :- | :- | :- | :- | | [`OpenAI middleware`](https://docs.langchain.com/oss/python/integrations/middleware/openai) | 内容审核 | [`langchain-ai/langchain`](https://github.com/langchain-ai/langchain/tree/master/libs/partners/openai) |
| | [`Anthropic middleware`](https://docs.langchain.com/oss/python/integrations/middleware/anthropic) | 提示词缓存、bash 工具、文本编辑器、记忆与文件搜索 | [`langchain-ai/langchain`](https://github.com/langchain-ai/langchain/tree/master/libs/partners/anthropic) |
| | [`AWS middleware`](https://docs.langchain.com/oss/python/integrations/middleware/aws) | 提示词缓存与 AgentCore Payments | [`langchain-ai/langchain-aws`](https://github.com/langchain-ai/langchain-aws/tree/main/libs/aws), [`aws/bedrock-agentcore-sdk-python`](https://github.com/aws/bedrock-agentcore-sdk-python) |
| | [`Microsoft Foundry middleware`](https://docs.langchain.com/oss/python/integrations/middleware/azure_ai) | 文本审核、图像审核、提示词防护、受保护材料与接地性 | [`langchain-ai/langchain-azure`](https://github.com/langchain-ai/langchain-azure/tree/main/libs/azure-ai) |
| | [`NVIDIA middleware`](https://docs.langchain.com/oss/python/integrations/middleware/nvidia) | 模型路由与 Nemotron 3 Ultra harness 优化 | [`langchain-ai/langchain-nvidia`](https://github.com/langchain-ai/langchain-nvidia), [`langchain-ai/deepagents`](https://github.com/langchain-ai/deepagents) | N/A |
全部中间件
| 服务商 | 可用中间件 | 源码 | 下载量 | | :- | :- | :- | :- | | [`OpenAI middleware`](https://docs.langchain.com/oss/python/integrations/middleware/openai) | 内容审核 | [`langchain-ai/langchain`](https://github.com/langchain-ai/langchain/tree/master/libs/partners/openai) |
| | [`Anthropic middleware`](https://docs.langchain.com/oss/python/integrations/middleware/anthropic) | 提示词缓存、bash 工具、文本编辑器、记忆与文件搜索 | [`langchain-ai/langchain`](https://github.com/langchain-ai/langchain/tree/master/libs/partners/anthropic) |
| | [`AWS middleware`](https://docs.langchain.com/oss/python/integrations/middleware/aws) | 提示词缓存与 AgentCore Payments | [`langchain-ai/langchain-aws`](https://github.com/langchain-ai/langchain-aws/tree/main/libs/aws), [`aws/bedrock-agentcore-sdk-python`](https://github.com/aws/bedrock-agentcore-sdk-python) |
| | [`Microsoft Foundry middleware`](https://docs.langchain.com/oss/python/integrations/middleware/azure_ai) | 文本审核、图像审核、提示词防护、受保护材料与接地性 | [`langchain-ai/langchain-azure`](https://github.com/langchain-ai/langchain-azure/tree/main/libs/azure-ai) |
| | [`CopilotKit`](/langchain/oss/python/langchain/frontend/integrations/copilotkit) | 面向 Deep Agents、create\_agent 图、AG-UI 以及 React 和运行时客户端的 CopilotKit 中间件与 FastAPI 桥接 | [`CopilotKit/CopilotKit`](https://github.com/CopilotKit/CopilotKit) |
| | [`ISNAD`](https://github.com/alizahidraja/isnad) | 面向智能体输出的断言级来源追溯与信任评级。在一个动态注册表中对断言链条中的每个传递者(来源、抓取器、模型)进行评级,将链条的信任上限锁定在其最薄弱环节,并隔离伪造(mawḍūʿ)链条——并带有防篡改的审计追踪。 | [`alizahidraja/isnad`](https://github.com/alizahidraja/isnad) |
| | [`attenu-guard`](https://attenu.io/docs/example-langgraph/) | 通过 wrap\_tool\_call 对每次工具调用和子智能体交接实施按智能体的权限控制(子智能体的权限是其父级权限的计算子集),并配有可离线验证的哈希链式审计日志 | [`attenu-io/attenu-guard`](https://github.com/attenu-io/attenu-guard) |
| | [`xaidr`](https://github.com/delphisecurity/xaidr#langchain-middleware) | 面向 AI 智能体的进程内运行时安全传感器。该 LangChain 中间件覆盖输入、工具调用和输出边界,用于提示词注入、越狱、DLP 和 A2A 协议扫描。 | [`delphisecurity/xaidr`](https://github.com/delphisecurity/xaidr) |
| | [`Tenuo`](https://tenuo.ai/langgraph#tenuomiddleware-langchain-1x-create_agent) | 面向 LangChain 智能体的任务范围授权:每次工具调用都会对照一份签名授权令进行检查,该授权令限定可运行哪些工具、使用哪些参数、持续多久,并且在工作被委派时只能收窄。 | [`tenuo-ai/tenuo`](https://github.com/tenuo-ai/tenuo) |
| | [`PIIAnonymizationMiddleware`](https://athroniaeth.github.io/piighost/getting-started/langchain/) | 保护提示词、工具调用和智能体对话中的个人数据(PII)。对模型隐藏敏感值,然后在回复中以及工具边界处还原真实值,因此工具和用户仍能获得真实数据。可插拔的正则、NER 和 LLM 检测器、线程一致的 token,以及逐 token 的流式还原。 | [`Athroniaeth/piighost`](https://github.com/Athroniaeth/piighost) |
| | [`Highflame`](https://github.com/highflame-ai/highflame-sdk) | 运行时 AI 安全护栏(提示词注入、PII/DLP、内容安全),通过 Highflame Shield(OWASP LLM Top 10)以中间件形式应用。 | [`highflame-ai/highflame-sdk`](https://github.com/highflame-ai/highflame-sdk) |
| | [`TealTiger`](https://docs.tealtiger.ai/integrations/langchain) | 确定性的治理中间件。策略执行、成本限制、工具允许清单、FREEZE 规则,以及 SARIF 审计证据,治理路径中不含 LLM。 | [`agentguard-ai/tealtiger`](https://github.com/agentguard-ai/tealtiger/tree/main/packages/langchain-tealtiger) |
| | [`DynamicToolSelectorMiddleware`](https://github.com/RauhanAhmed/langchain-dynamic-tools-middleware) | 即插即用的智能体中间件,在 zvec 上提供低于 100ms 的稠密与稀疏混合向量工具检索。将提示词 token 开销消除 80% 以上,并在 Berkeley Function Calling Leaderboard (BFCL) 基准上优于基于 LLM 的工具选择。 | [`RauhanAhmed/langchain-dynamic-tools-middleware`](https://github.com/RauhanAhmed/langchain-dynamic-tools-middleware) |
| | [`prompt-shield`](https://github.com/mthamil107/prompt-shield) | 运行时提示词注入防火墙。通过多种检测器和输出扫描器扫描输入、工具结果和输出,支持阻止、标记和记录模式。 | [`mthamil107/prompt-shield`](https://github.com/mthamil107/prompt-shield) |
| | [`SeekritCredentials`](https://seekrit.dev/docs/guides/frameworks/langgraph#4-scope-a-key-to-one-tool) | 按模型调用和工具调用限定密钥的作用范围。凭据在智能体代码中保持为占位符,并在 HTTP 边界处依据默认拒绝的允许清单进行替换,因此未列入清单的工具无法获取凭据。 | [`seekritdev/python-sdk`](https://github.com/seekritdev/python-sdk) |
| | [`MaskflowReversibleAnonymizer`](https://github.com/maskflow/maskflow/tree/main/packages/maskflow-langchain) | 可逆的 PII 匿名化器 / 去匿名化器,可即插即用地替代 langchain-experimental 的 Presidio 匿名化器(相同的 .anonymize / .deanonymize / .deanonymizer\_mapping 以及 JSON/YAML 保存-加载)。它补充了大多数工具遗漏的印度标识符(Aadhaar、PAN、GSTIN、UPI、IFSC、ABHA、姓名、地址),提供一个感知流式传输的去匿名化器 Runnable,以及一个可选的防泄漏回调,在 PII 到达模型时让调用失败关闭。 | [`maskflow/maskflow`](https://github.com/maskflow/maskflow/tree/main/packages/maskflow-langchain) |
| | [`Nuggets Authority`](https://nuggets.life) | 面向工具调用的执行前权限强制执行。在每个工具运行前验证一份限定范围的签名委派,在拒绝时失败关闭,并针对每次决策生成可独立验证的加密证明。 | [`NuggetsLtd/langchain-nuggets`](https://github.com/NuggetsLtd/langchain-nuggets) |
| | [`Pydantic Monty Code Interpreter`](https://github.com/shane-rand/langchain-monty) | 在 Pydantic 的 Monty Runtime 内提供代码解释 | [`langchain-monty`](https://github.com/shane-rand/langchain-monty) |
| | [`compact-middleware`](https://github.com/emanueleielo/compact-middleware) | 将 Claude Code 的压缩引擎作为 LangChain 中间件。面向长时间运行智能体的多级上下文压缩。 | [`emanueleielo/compact-middleware`](https://github.com/emanueleielo/compact-middleware) |
| | [`Cisco AI Defense`](https://github.com/cisco-ai-defense/ai-defense-langchain-middleware) | 运行时安全检查 | [`cisco-ai-defense/ai-defense-langchain-middleware`](https://github.com/cisco-ai-defense/ai-defense-langchain-middleware) |
| | [`langchain-runcycles`](https://runcycles.io) | 面向模型调用、工具调用和智能体循环的执行前预算授权 | [`runcycles/langchain-runcycles`](https://github.com/runcycles/langchain-runcycles) |
| | [`ATLTaskMiddleware`](https://github.com/wenhua6666668-oss/langchain-agenttrafficlab#automatic-task-time-routing-v03) | 自动将任务路由到可执行的 MCP 和服务商能力,并带有失败重新决策和结果上报。 | [`wenhua6666668-oss/langchain-agenttrafficlab`](https://github.com/wenhua6666668-oss/langchain-agenttrafficlab) |
| | [`langchain-router`](https://github.com/johanity/langchain-router) | 基于阶段的模型路由。将执行轮次路由到快速模型,将主模型保留用于规划和恢复。 | [`johanity/langchain-router`](https://github.com/johanity/langchain-router) |
| | [`langchain-task-steering`](https://github.com/edvinhallvaxhiu/langchain-task-steering) | 面向有序任务管线的隐式状态机中间件,具有按任务的工具范围限定、动态提示词注入和可组合的完成校验。 | [`edvinhallvaxhiu/langchain-task-steering`](https://github.com/edvinhallvaxhiu/langchain-task-steering) |
| | [`CTRLRunMiddleware`](https://docs.ctrlrun.dev/guides/langchain-middleware) | 通过 wrap\_tool\_call 实现策略门控的工具调用:被拒绝的调用永远不会到达工具,并会告知模型是哪条规则拒绝了它;effect key 在共享 store 的多个进程间最多执行一次;会抛出异常的工具会让该 effect 保持未解决,而不是重试;approve 决策会为人工保留该调用;每个决策都有一份回执,包括拒绝。 | [`CTRLRun/ctrlrun`](https://github.com/CTRLRun/ctrlrun/tree/main/adapters/langchain) |
| | [`advisor-middleware`](https://github.com/emanueleielo/advisor-middleware) | 将 Claude Code 的顾问模式作为 LangChain 中间件。将快速执行模型与强大的顾问模型配对,后者仅在关键决策时介入。 | [`emanueleielo/advisor-middleware`](https://github.com/emanueleielo/advisor-middleware) |
| | [`BastionGuardrailMiddleware`](https://bastionsoft.com) | 提示词注入和越狱检测。在模型运行前筛查用户输入和工具结果,包括通过检索内容进行的间接注入。在你自己的硬件上本地运行。 | [`bastion-soft/bastion-prompt-protection`](https://github.com/bastion-soft/bastion-prompt-protection) |
| | [`RelayShield`](https://api.relayshield.net/developers) | 强制性的执行前关卡,当 RelayShield 报告风险时阻止 connect\_mcp\_server 和 install\_mcp\_package 工具调用。 | [`nzdsf2-gif/langchain-relayshield`](https://github.com/nzdsf2-gif/langchain-relayshield) |
| | [`langchain-collapse`](https://github.com/johanity/langchain-collapse) | 预防性的上下文管理。在连续的工具调用组填满上下文窗口之前将其折叠。 | [`johanity/langchain-collapse`](https://github.com/johanity/langchain-collapse) |
| | [`NeuralTrust TrustGuard`](https://docs.neuraltrust.ai/integrations/langchain) | TrustGuard 评估中间件。对智能体输入、模型输出和可选的工具流量执行允许、阻止、上报或转换。 | [`NeuralTrust/langchain-neuraltrust`](https://github.com/NeuralTrust/langchain-neuraltrust) |
| | [`DeepKeep middleware`](https://docs.deepkeep.ai) | 面向 LangChain 智能体的 DeepKeep AI Firewall 事前审核和事后审核。 | |
| | [`Tessera`](https://github.com/kenithphilip/Tessera) | 签名信任标签与污点追踪,在上下文包含不可信片段时对工具调用进行门控。 | [`kenithphilip/Tessera`](https://github.com/kenithphilip/Tessera) |
| | [`AxioRank`](https://axiorank.com/docs/integrations/langchain) | 面向 AI 智能体的安全网关:依据策略对工具调用和模型轮次评分,支持允许、拒绝和脱敏。 | [`AxioRank/langchain-axiorank`](https://github.com/AxioRank/langchain-axiorank) |
| | [`OpenBox`](https://docs.openbox.ai/getting-started/langgraph) | 面向 LangGraph 和 Deep Agents 的实时治理。策略、护栏、HITL、OTel 钩子治理和行为规则。 | [`OpenBox-AI/openbox-langgraph-sdk-python`](https://github.com/OpenBox-AI/openbox-langgraph-sdk-python) |
| | [`langchain-distil`](https://github.com/dshakes/distil) | 可逆、经认证的上下文压缩。在模型调用之前对大体积工具输出和消息历史进行摘要整理(工具消息和函数消息可逆处理,人类消息和系统消息无损处理,模型消息从不重写),并可对每个摘要进行逐字节精确恢复。压缩上下文与完整上下文之间的决策等价性由统计非劣效性门控离线认证。 | [`dshakes/distil`](https://github.com/dshakes/distil) |
| | [`text2sql-framework`](https://github.com/Text2SqlAgent/text2sql-framework) | 用递归工具调用替代 RAG:智能体使用单个 execute\_sql 工具进行探索、编写、测试和自我纠正。 | [`Text2SqlAgent/text2sql-framework`](https://github.com/Text2SqlAgent/text2sql-framework) |
| | [`DNS-AID`](https://github.com/IngmarVG-IB/langchain-dns-aid) | 基于 DNS 的智能体发现,通过 DNS-AID 协议实现。启动时自动发布智能体,关闭时自动取消发布,并提供发现工具。 | [`IngmarVG-IB/langchain-dns-aid`](https://github.com/IngmarVG-IB/langchain-dns-aid) |
| | [`OWASP Agent Memory Guard`](https://owasp.org/www-project-agent-memory-guard/) | 针对 AI 智能体内存投毒的运行时防御(OWASP ASI06)。在本地扫描消息、模型响应和工具输出,支持阻断、警告和剥离模式。 | [`OWASP/www-project-agent-memory-guard`](https://github.com/OWASP/www-project-agent-memory-guard/tree/main/integrations/langchain-agent-memory-guard) |
| | [`langchain-pop`](https://github.com/joy7758/persona-object-protocol/tree/main/integrations/langchain-pop) | 面向 LangChain 智能体的可移植角色加载、旧版迁移和边界感知的工具过滤。 | [`joy7758/persona-object-protocol`](https://github.com/joy7758/persona-object-protocol/tree/main/integrations/langchain-pop) |
| | [`comply54`](https://comply54.io/langchain) | 面向 AI 智能体的运行时合规强制执行,依据非洲数据保护和金融行业法规(拒绝、升级、审计或允许)。 | [`comply54/langchain-comply54`](https://github.com/comply54/langchain-comply54) |
| | [`NoPII`](https://github.com/Enigma-Vault/NoPII/tree/main/integrations/langchain-nopii-middleware) | 运行时 PII 令牌化。检测出站提示词中的个人数据,在请求到达 LLM 之前将其替换为确定性的保管库令牌,并在响应中恢复原始值。 | [`Enigma-Vault/NoPII`](https://github.com/Enigma-Vault/NoPII/tree/main/integrations/langchain-nopii-middleware) |
| | [`langgraph-state-machine`](https://github.com/mahmoud661/langgraph-state-machine) | 面向 LangGraph React 智能体的基于区段的流控制。将会话划分为具有作用域工具、提示词、自动转换、分支以及可选的按区段 LLM 覆盖的离散阶段。 | [`mahmoud661/langgraph-state-machine`](https://github.com/mahmoud661/langgraph-state-machine) |
| | [`VecrContextCompressor`](https://github.com/h2cker/vecr) | 确定性的 LLM 上下文压缩,在模型调用之前使用正则保留白名单来保留结构化令牌。 | [`h2cker/vecr`](https://github.com/h2cker/vecr) |
| | [`ATR Guardrail`](https://github.com/Agent-Threat-Rule/agent-threat-rules/tree/main/integrations/langchain) | 使用 Agent Threat Rules 在运行时检测提示词注入、工具投毒和不安全的工具调用。在发现严重问题时停止智能体或阻止工具调用,并保留审计追踪。 | [`Agent-Threat-Rule/agent-threat-rules`](https://github.com/Agent-Threat-Rule/agent-threat-rules/tree/main/integrations/langchain) | N/A | | [`eager-tools`](https://github.com/cloudthinker-ai/eager-tools) | 通过在每个工具调用的流式块关闭时立即派发该调用,将工具执行与 LLM 生成重叠,从而降低智能体的挂钟延迟。 | [`cloudthinker-ai/eager-tools`](https://github.com/cloudthinker-ai/eager-tools) | N/A | | [`Haldir`](https://github.com/ExposureGuard/haldir/tree/main/integrations/langchain-haldir) | 面向 LangChain 智能体的治理层,提供作用域会话、加密密钥、哈希链审计和策略强制执行。 | [`ExposureGuard/haldir`](https://github.com/ExposureGuard/haldir/tree/main/integrations/langchain-haldir) | N/A | | [`NVIDIA middleware`](https://docs.langchain.com/oss/python/integrations/middleware/nvidia) | 模型路由与 Nemotron 3 Ultra harness 优化 | [`langchain-ai/langchain-nvidia`](https://github.com/langchain-ai/langchain-nvidia), [`langchain-ai/deepagents`](https://github.com/langchain-ai/deepagents) | N/A |
INFO
如果你想贡献一个集成,请参阅贡献集成。