# Agent 类、Program 与工具

```
from openprogram import Agent

def prepare(text):                                   # 普通 Python，不产生 DAG 节点
    return text.strip()

class Researcher(Agent):
    model = "configured-model"
    method_options = {"research": {"tool": True}}    # 把这个方法登记为工具

    def research(self, question):                    # 记入 DAG
        answer = self(prepare(question))             # 一次模型调用
        if "TODO" in answer:                         # 用代码写的检查
            answer = self(f"Finish this answer: {answer}")
        return answer

result = Researcher().research("A topic")
```

| 概念 | 规则 |
| --- | --- |
| Agent | 只持有配置：`model`、`effort`、`instructions`、`tools`。不拥有对话；历史是否延续由执行作用域决定 |
| Agent 方法 | 子类上的每个函数。无需装饰器：调用时进入作用域，记入会话 DAG，并为其中的模型调用派生 Context |
| `self(...)` | 一次模型调用。周围的分支、循环、重试、检查都是普通 Python |
| Context | 父继承、命名内容、求值、历史可见性 |
| `method_options` | 按方法配置：`tool=True`、公开名称、描述、输入形式、可见性、入口元数据、持久步骤（`resumable`）。没有选项的方法仍被记录，但不是工具 |
| Program | 由这样的类和函数组成的包。已登记源码在 `PROGRAM_ENTRIES` 列出公开入口；显式元数据保留名称与输入形式 |
| `@function` 工具 | 确定性，同一个注册表。授权与调用记录、历史可见性分别处理 |
| Skill | 只提供指令，不创建可执行入口 |
| 模块级帮助函数 | 普通 Python：签名、返回值、异常和 import 不变，没有 DAG 节点 |

实现在 `openprogram/runtime/agent/agent_class.py` 和 `agent_method.py`。类 API、执行生命周期和验证状态见 [Agent 与 Context 契约](https://fzkuji.github.io/OpenProgram/docs/reference/design/integrations/nooa.zh.html#contract)、[实现状态](https://fzkuji.github.io/OpenProgram/docs/reference/design/integrations/nooa.zh.html#implementation)。

[函数调用](https://fzkuji.github.io/OpenProgram/docs/reference/design/function/calling-unification.zh.html)
