# 第十一章：容错与可靠性工程

## 章引言

一个智能体系统的成功不仅取决于它在正常情况下的表现，更取决于它在异常情况下的表现。第十一章探讨如何设计和实现一个容错、可恢复的智能体系统。

### 现实中的故障场景

在生产环境中，Harness会面临各种故障：

1. **工具调用失败**
   * API超时
   * 速率限制
   * 权限错误
   * 部分Server宕机
2. **LLM服务故障**
   * API不可用
   * 上下文长度超限
   * 配额耗尽
3. **数据和资源故障**
   * 数据库连接丢失
   * 内存溢出
   * 磁盘空间不足
4. **逻辑故障**
   * LLM幻觉(Hallucination)
   * 无限循环
   * 死锁

### 核心问题

1. **如何可观测？** 我们如何知道系统正在做什么、是否出问题？
2. **如何反馈？** 当智能体做出危险决定时，人类如何介入？
3. **如何容错？** 一个模块故障时，系统如何继续工作？
4. **如何防幻觉？** 如何检测和防止LLM的错误输出？

## 本章结构

* 11.1：可观测性体系
* 11.2：反馈循环与人机协同设计
* 11.3：容错模式与系统级恢复
* 11.4：幻觉防护的工程实践
* 11.5：实战——为 MiniHarness 添加可靠性保障

### 与其他章节的关联

* ← 第10章的配置系统被用于控制容错策略
* → 这是最后的功能章节，为评估和未来方向做准备

## 可靠性的度量

在讨论具体技术前，我们需要定义目标：

| 指标             | 定义         | 生产目标    |
| -------------- | ---------- | ------- |
| Availability   | 系统可用时间/总时间 | 99.9%   |
| MTBF（平均故障间隔时间） | 故障间隔时间     | >1000小时 |
| MTTR（平均恢复时间）   | 平均修复时间     | <5分钟    |
| Error Rate     | 失败的请求比例    | <0.1%   |
| P99延迟          | 99%的请求完成时间 | <10秒    |

## 学习路径

建议按顺序学习：

1. 11.1 建立可观测性基础
2. 11.2 设计反馈机制
3. 11.3 实现容错能力
4. 11.4 防护幻觉
5. 11.5 整合到MiniHarness


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://yeasy.gitbook.io/harness_engineering_guide/di-san-bu-fen-xi-tong-ji-cheng-yu-gong-cheng-shi-jian/11_reliability.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
