# API 参考

| 组件 | 源码 | 说明 |
| --- | --- | --- |
| [`Agent` `Context` `agent` `agent_async`](https://fzkuji.github.io/OpenProgram/docs/reference/api/agent.html) | `runtime/agent/`、`runtime/context/model.py` | 直接调用、配置好的 Agent 方法、自动执行上下文 |
| [`Runtime`](https://fzkuji.github.io/OpenProgram/docs/reference/api/runtime.html) | `runtime/agent/runtime/` | 从 DAG 计算上下文，调用 LLM，把响应写回 |
| [`create_runtime` 和 Provider](https://fzkuji.github.io/OpenProgram/docs/reference/api/providers.html) | `runtime/agent/runtime/factory.py`、`models/providers/` | 自动检测或显式创建 Runtime |

路径都在 [`openprogram/`](https://github.com/Fzkuji/OpenProgram/tree/main/openprogram/) 下。会话上下文是由用户消息、LLM 调用和函数调用组成的扁平 DAG：[架构](https://github.com/Fzkuji/OpenProgram/blob/main/openprogram/runtime/context/README.md)。

## 导入

```
from openprogram import Agent, Context, agent, agent_async, Runtime, Session, decision
from openprogram import ChatAgent, TurnRequest, TurnResult
from openprogram.runtime.agent.runtime.factory import create_runtime
```

## 示例

```
from openprogram import Agent

class Observer(Agent):
    tools = []

    def observe(self, task: str) -> str:
        """找到请求的界面元素。"""
        return self(f"Find the UI element for: {task}. Reply with its label only.")

print(Observer().observe("login button"))
```

没有 `create()`、`fix()` 这样的元函数。用普通的文件编辑工具编写、修改和验证 Agent 方法与 Program 函数。
