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

# 测试

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

智能体应用允许大语言模型(LLM)自行决定下一步操作来解决问题。这种灵活性很强大，但模型的黑盒特性使得很难预测对智能体某一部分的调整会如何影响整体。要构建生产就绪的智能体，全面的测试至关重要。

测试智能体有几种方法：

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

由于智能体应用将多个组件链接在一起，且必须处理大语言模型(LLM)非确定性带来的不稳定性，因此倾向于更多地依赖集成测试。

<Tip>
  使用 [LangSmith](https://smith.langchain.com?utm_source=docs\&utm_medium=cta\&utm_campaign=langsmith-signup\&utm_content=oss-langchain-test-index) 大规模运行评估、跟踪结果变化趋势，并比较实验。参阅[评估 LLM 应用](/langsmith/evaluate-llm-application)开始使用。
</Tip>

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

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

  <Card title="评估" icon="scale" href="/oss/python/langchain/test/evals" arrow>
    使用确定性匹配或 LLM 裁判评估器评估智能体轨迹。
  </Card>
</CardGroup>

***

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