# Agents

> 驱动 flow 的专用 agents，以及确保其按预期运行的安全机制。

[Flow](https://pentagi.com/zh-cn/docs/glossary/#flow) 由一个 [agents](https://pentagi.com/zh-cn/docs/glossary/#agent) 团队执行。每种 [agent type](https://pentagi.com/zh-cn/docs/glossary/#agent-type) 都有其专属的提示词、模型配置和 [tools](https://pentagi.com/zh-cn/docs/glossary/#tool)，因此您可以为不同角色分配性能更强或成本更低的模型。

## [Agent types](https://pentagi.com/zh-cn/docs/concepts/agents/#agent-types)

| Agent                  | 角色                                                                                                 |
| ---------------------- | -------------------------------------------------------------------------------------------------- |
| `primary_agent`        | 驱动 flow 的主推理 agent                                                                                 |
| `assistant`            | 交互式 [assistant](https://pentagi.com/zh-cn/docs/glossary/#assistant) 模式                                                      |
| `generator`            | 将每个 [task](https://pentagi.com/zh-cn/docs/glossary/#task) 拆分为 [subtasks](https://pentagi.com/zh-cn/docs/glossary/#subtask)                           |
| `refiner`              | 根据返回结果优化计划                                                                                         |
| `adviser`              | 提供专家建议；在执行监控中担任导师，在 task 规划中担任规划师                                                                  |
| `reflector`            | 纠正停止发起 [tool calls](https://pentagi.com/zh-cn/docs/glossary/#tool-call) 的 agents                                            |
| `searcher`             | 信息收集与网络搜索                                                                                          |
| `enricher`             | 在 adviser 回答之前，从 [memory](https://pentagi.com/zh-cn/docs/glossary/#memory) 和 [sandbox](https://pentagi.com/zh-cn/docs/glossary/#sandbox) 中收集额外的上下文信息 |
| `coder`                | 编写与分析代码                                                                                            |
| `installer`            | 在 sandbox 中安装并配置 tools                                                                             |
| `pentester`            | [Pentest](https://pentagi.com/zh-cn/docs/glossary/#pentest) 与安全评估                                                           |
| `simple`、`simple_json` | 纯文本及 JSON 结构化补全                                                                                    |

此外还有两个 agents 在后台运行：`memorist` 基于长期 memory 回答其他 agents 关于过往工作的问题，`reporter` 则负责撰写每个 task 的执行结果报告。

## [工作委派机制](https://pentagi.com/zh-cn/docs/concepts/agents/#how-work-is-delegated)

```mermaid
sequenceDiagram
  accTitle: How a task is split into subtasks and the primary agent delegates each step to specialist agents through shared memory
  participant G as Generator
  participant O as Primary agent
  participant M as Memorist
  participant S as Specialists
  participant V as Vector store
  G->>O: Subtasks of the task
  O->>M: Past work, when the context lacks it
  M->>V: Search memory
  O->>S: Delegate a step to the searcher, pentester, coder or installer
  S->>V: Store tool results
  S-->>O: Result
```

## [安全保护机制](https://pentagi.com/zh-cn/docs/concepts/agents/#safeguards)

* **Tool call 限制**（始终启用）— `MAX_GENERAL_AGENT_TOOL_CALLS`（默认 100）限制 `primary_agent`、`assistant`、`pentester`、`coder` 和 `installer` 链中的模型轮次，而 `MAX_LIMITED_AGENT_TOOL_CALLS`（默认 20）限制其他 agent 的轮次。一轮可以调用多个 tool。1 到 5 的值会提升至 6，0 或更小的值表示使用默认值。
* **重复检测**（始终开启）— 从第三次连续使用相同参数调用同一 tool 开始，该 tool 将不再执行：agent 会收到之前的答案，并被要求改变方向。第七次此类调用将终止该链。
* **Reflector**（始终开启）— 当模型首次未发起 tool call 而直接回复时介入，引导 agent 重新使用 tool；若连续三轮仍未成功，则停止该链。
* **执行监控**（测试版，`EXECUTION_MONITOR_ENABLED`）— 对于 `primary_agent`、`pentester`、`coder`、`installer`，以及与 agents 协作时的 `assistant`，如果 agent 连续 `EXECUTION_MONITOR_SAME_TOOL_LIMIT` 次调用同一个 tool（默认 5 次）或自上次建议以来已发出 `EXECUTION_MONITOR_TOTAL_TOOL_LIMIT` 次 tool calls（默认 10 次），adviser 将充当导师。该触发器统计的是调用次数，而非检测停滞；随后 adviser 会审查 agent 的进展，并建议是继续、改变方法还是停止。
* **智能 task 规划**（测试版，`AGENT_PLANNING_STEP_ENABLED`）— 在专业 agents 开始 subtask 前，adviser agent 会预先拟定 3–7 个具体步骤。

> [!NOTE]
> 对于参数量低于 32B 的模型，启用执行监控和 task 规划可使结果质量大致翻倍，但代价是 Token 消耗和时间增加 2–3 倍。这些功能默认处于关闭状态。

在 Enterprise 中，planner 始终运行，执行监控默认开启，限制为 20 和 40 — 请参阅 [Agent profiles](https://pentagi.com/zh-cn/docs/enterprise/agent-profiles/#planner-and-execution-monitor)。