# run()

Canonical URL: https://developers.iagenify.com/zh/sdk/ref/agent/run/
Language: zh

`agent.run({ inputs, outputs?, history?, onStep?, signal? }) → Promise<Result>`

流出平台的运行:每步回调一次, 以及当它结束时的结果 。

Status: POST /api/ai/agents/run · server-sent events · errors keep their type

| Name | Type | Requirement | Description |
| --- | --- | --- | --- |
| `inputs` | array | 必填 | `[{ type: "text", content }]`,包括图像。空阵列投出。 |
| `outputs` | array |  | 覆盖了代理器创建的用途, 本次运行。 |
| `history` | array |  | 缺席使用代理人自己的; `[]` 重新开始。 |
| `onStep` | function |  | 每一步都按步调来 |
| `signal` | AbortSignal |  | 取消请求。 |

## 采取什么步骤 {#step}

```javascript
{
  index: 2,
  kind: "tool",
  tool: "search",
  input: "customer churn definition",
  reasoning: "I will look up how they define churn.",
  summary: "5 result(s)",
  error: "",
  credits: 7,
  durationMs: 1840,
  meta: { enginesUsed: [...], results: [...] }
}
```

`credits` 跑步是全速跑,不是这步 `meta` 无论工具报告什么——它打开的页面、它找到的来源、一代人的数字。

## 三起拒绝 算作一步错误 {#refusals}

| 错误 | 触发条件 |
| --- | --- |
| 未知工具 | 标有您没有声明的模型。 信件列出了可用的 。 |
| 缺少的论点 | 一种需要工具的工具被称作没有它的工具。 |
| 已经做 | 同一工具,同一论点,两次。 |
| 拒绝:.所需信贷 | 宣布的费用将过 `budget`. |

每一个都持续跑步,拒绝就是模式可以采取行动的信息。

## 错误将类型保留在流中 {#errors}

```javascript
import { NotEnoughCredits, Unauthorized, IaGenifyError } from "iagenify";

try {
  await agent.run({ inputs });
} catch (err) {
  if (err instanceof NotEnoughCredits) { /* … */ }
}
```

> **流流中的失败被翻译回来**
>
> 旅行时间为 JSON,并且被重建成同一类 , 剩下的软件包扔出—— 如此一来这里的工作就和其他地方一样, 而不是给你一个简单的错误, 而不是给您一个网络故障无法告诉的错误。

## 不明内嵌内设被断断拒绝 {#unknown}

工具 `builtin` 平台不知道运行失败,而不是被丢弃。 悄悄地缺少其周围工具的工作流程就是没有人诊断出失败。

## 本地工作暂停运行 {#local}

当一个步骤需要打电话者的电脑时, 运行请求并等待您的进程回答。 放弃请求, 而该步骤永远无法完成 。

- [stop()](/zh/sdk/ref/agent/stop): 结束它。
- [api.tools](/zh/sdk/ref/tools): 声明。

```python
{
    "index": 2,
    "kind": "tool",
    "tool": "search",
    "input": "customer churn definition",
    "reasoning": "I will look up how they define churn.",
    "summary": "5 result(s)",
    "error": "",
    "credits": 7,
    "durationMs": 1840,
    "meta": {"enginesUsed": [...], "results": [...]},
}
```

```python
from iagenify import IaGenifyError, NotEnoughCredits, Unauthorized

try:
    agent.run(inputs=inputs)
except NotEnoughCredits:
    pass  # …
```
