# getHistory()

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

`agent.getHistory() → Promise<Message[]>`

显示式对话:用户和助手信息,每个都使用它所拨用的工具,以及它们是如何去的。

Status: free · same shape as a model session · source depends on memory

```javascript
const messages = await agent.getHistory();

for (const m of messages) {
  console.log(m.role, m.parts[0].content);
  for (const call of m.toolCalls || []) {
    console.log("   ", call.name, call.target, call.ok ? "ok" : "failed", call.credits);
  }
}
```

| Name | Type | Requirement | Description |
| --- | --- | --- | --- |
| `role` | string |  | `user` 或 `assistant`。工具信息不在里面。 |
| `parts` | array |  | `[{ type: "text", content }]` 相同的模式会话返回模式。 |
| `toolCalls` | array |  | `{ id, name, target, ok, credits, durationMs }` 电话,每次。 |

## 目标的参数的简短版本 {#target}

有意义的字符串 —— 路径、 模式、 命令、 查询、 密钥。 它是一个界面在工具名称旁边显示什么, 以及一个会话记录是什么 。

## 从哪里来 {#source}

| 代理 | 读取自 |
| --- | --- |
| 无 `memory` | 对象在内存中持有的 |
| 与 `memory` | 账户账户 |

> **工具结果从来就没有在工具中出现过**
>
> 工具返回的文字内容在设备日记里, 其它地方也没有——这也是为什么在其他地方重新开会, 显示在未显示读到的东西的情况下所做的。

## 用于显示,而非重放 {#display}

继续聊天,打 `run()` 代理器上——它已经维持了模型需要的状况。这个方法用来显示一个人发生的事情。

- [会话](/zh/sdk/agent/sessions): 藏着什么 藏在哪里
- [agents.list()](/zh/sdk/ref/agents/list): 寻找一个对话。

```python
messages = agent.get_history()
# [{"role", "content", "name", "toolCallId"}] — read from the local journal

for m in messages:
    if m["role"] == "tool":
        print("   ", m["name"], (m["content"] or "")[:60])
    else:
        print(m["role"], (m["content"] or "")[:80])
```
