> ## Documentation Index
> Fetch the complete documentation index at: https://cndoc-langchain.site/llms.txt
> Use this file to discover all available pages before exploring further.

# 测试

> 测试 LangChain 智能体的策略，包括单元测试、集成测试和轨迹评估。

智能体应用让大语言模型自行决定下一步操作以解决问题。这种灵活性非常强大，但模型的黑盒特性使得难以预测对智能体某一部分的微调将如何影响整体。要构建可用于生产环境的智能体，彻底的测试至关重要。

测试智能体有几种方法：

* **单元测试**使用内存中的模拟对象，独立测试智能体中小型、确定性的部分，以便快速、确定性地断言精确行为。
* **集成测试**使用真实的网络调用测试智能体，以确认各组件协同工作、凭证和模式匹配，并且延迟可接受。
* **评估**使用评估器来评估智能体的执行轨迹，可通过确定性匹配或大语言模型裁判进行。

智能体应用往往更依赖集成测试，因为它们将多个组件链接在一起，并且必须应对大语言模型非确定性本质带来的不稳定性。

<CardGroup cols={1}>
  <Card title="单元测试" icon="flask" href="/oss/javascript/langchain/test/unit-testing" arrow>
    模拟聊天模型并使用内存持久化来测试智能体逻辑，无需 API 调用。
  </Card>

  <Card title="集成测试" icon="plug" href="/oss/javascript/langchain/test/integration-testing" arrow>
    使用真实的大语言模型 API 测试您的智能体。组织测试、管理密钥、处理不稳定性并控制成本。
  </Card>

  <Card title="评估" icon="scale" href="/oss/javascript/langchain/test/evals" arrow>
    使用确定性匹配或大语言模型裁判评估器来评估智能体轨迹。
  </Card>
</CardGroup>

***

<div className="source-links">
  <Callout icon="terminal-2">
    [将这些文档](/use-these-docs)通过 MCP 连接到 Claude、VSCode 等，以获取实时答案。
  </Callout>

  <Callout icon="edit">
    [在 GitHub 上编辑此页面](https://github.com/langchain-ai/docs/edit/main/src/oss/langchain/test/index.mdx) 或 [提交问题](https://github.com/langchain-ai/docs/issues/new/choose)。
  </Callout>
</div>
