# 概览

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

什麽 api.agents.create({ runtime: "local" }) 返回:代理循环作为您持有、运行、停止、检查和回放的对象。

Status: 8 methods · the loop is here · read its state as it works

| 方法 | 功能 |
| --- | --- |
| [运行( 选项)](/zh/sdk/ref/local-agent/run) | 交换一个:你的信息,答案。 |
| [( 停止)](/zh/sdk/ref/local-agent/stop) | 结束当前运行 。 |
| 设置 mode( 模式) | 更改模式, 中跑, 包括子试剂 。 |
| [白 字 ()](/zh/sdk/ref/local-agent/compact) | 总结了谈话现在。 |
| [获取历史()](/zh/sdk/ref/local-agent/get-history) | 谈话,显示形状。 |
| [() (检查站)](/zh/sdk/ref/local-agent/checkpoints) | 回到你能够回到的地方 |
| [反后(n)](/zh/sdk/ref/local-agent/rewind) | 回到一条留言。 |
| [(销毁)](/zh/sdk/ref/local-agent/destroy) | 删除会话。 |

```javascript
const agent = api.agents.create({ runtime: "local", machine: pc, model, memory: true });

const result = await agent.run({
  message: "Read the notes and list what is unfinished.",
  onEvent: (e) => { if (e.type === "text_delta") process.stdout.write(e.delta); },
});

console.log(agent.usage, agent.context.tokens, result.stopReason);
```

## 运行 () 是一次交换, 不是一项任务 {#one-exchange}

它将需要您的信息,循环直到模型停止要求工具,然后返回。再拨它继续同样的对话——对象将保留历史。

## 对象为可重复使用,而不是同时 {#reusable}

> **一次一个跑**
>
> 第二次运行( ) , 而在飞行中的人则共享相同的电文列表和相同的使用计数器。 等待第一个, 或者建立第二个代理 。

## 工作时您可以读取状态 {#state}

`usage`, `context`, `todos`, `mode` 和 `messages` 。一个界面可以对它们进行民意测验或倾听 [事件事件事件](/zh/sdk/agent/events)更便宜更精确

- [属性](/zh/sdk/ref/local-agent/properties): 什么都可以读
- [run()](/zh/sdk/ref/local-agent/run): 主要方法。
- [智能体引擎](/zh/sdk/agent): 循环如何运作。

```python
agent = api.agents.create(runtime="local", machine=pc, model=model, memory=True)

result = agent.run(
    message="Read the notes and list what is unfinished.",
    on_event=lambda e: print(e["text"]) if e["type"] == "text" else None,
)

print(agent.usage, agent.context["tokens"], result["stopReason"])
```
