# 发起对话

`POST` `/v1/ai/agents/{agent_id}/conversations`

向指定 Agent 提问。可以开启一个全新会话，也可以传入已有会话的 `chat_uid` 在同一会话中追加提问。

Agent 会结合行情、账户等能力生成回答。当 Agent 需要你补充信息或确认时，本次运行会**中断**（`status` 为 `interrupted`），此时需通过 [继续对话](/zh-CN/docs/ai/chat/continue) 回传答案后才能继续。

通过请求头 `Accept` 选择响应模式：`text/event-stream` 为 SSE 流式，逐步推送运行过程与回答；其他值为阻塞式，一次性返回聚合后的最终结果。

:::tip 如何获取 Agent 的 UID
除通过 Workspace 下的 Agent 接口查询外，也可以直接从 Longbridge 网页端获取：打开 Agent 的对话页，URL 形如 `https://longbridge.com/zh-CN/ai/agents/chatbot/chat`，其中 `chatbot` 即为该 Agent 的 UID。
:::

## Parameters

### Path Parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `agent_id` | string | Yes | 目标 Agent 的 UID，需为已发布 Agent |

### Request Body

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `query` | string | Yes | 用户问题，不能为空 |
| `chat_uid` | string | No | 已有会话标识。传入则在该会话中继续提问，不传则新建会话 |
| `parent_message_id` | string | No | 父消息 ID，取上一轮响应中的 `message_id`。在已有会话中追加提问时传入，将本轮消息挂在指定消息之后，保证消息流顺序。仅在传入 `chat_uid` 时有效，且父消息必须属于该会话；新会话不可传 |

## Request Example

```bash
curl --request POST \
  --url 'https://openapi.longbridge.com/v1/ai/agents/<agent_id>/conversations' \
  --header 'Authorization: Bearer <access_token>' \
  --header 'Content-Type: application/json' \
  --data '{"query":"<query>","chat_uid":"<chat_uid>","parent_message_id":"<parent_message_id>"}'
```

## Response

### Response Properties

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `chat_uid` | string | Yes | 会话标识，追加提问或排查问题时使用 |
| `message_id` | string | Yes | 本轮消息 ID（字符串形式） |
| `status` | string | Yes | 运行终态：`succeeded` / `interrupted` / `failed` / `stopped` |
| `answer` | string | No | 最终回答文本，`status` 为 `succeeded` 时有效 |
| `references` | object[] | No | 回答引用的资料来源，无引用时为 `null` |
| `elapsed_time` | number | No | 运行耗时（秒） |
| `interrupt` | object | No | 仅当 `status` 为 `interrupted` 时出现 |
| `└ node_id` | string | Yes | 触发中断的节点 ID |
| `└ tool_call_id` | string | Yes | 本次询问对应的工具调用 ID，继续对话时作为答案的 key |
| `└ questions` | object[] | Yes | 需要你回答的问题列表 |
| `└ ∟ question` | string | Yes | 问题文本 |
| `└ ∟ options` | object[] | No | 可选项，为空表示自由作答 |
| `└ ∟∟ description` | string | No | 选项文本 |
| `└ ∟ multi_select` | boolean | No | 是否允许多选 |
| `└ message_id` | int64 | No | 被暂停的消息 ID |
| `└ chat_id` | int64 | No | 所属会话 ID |
| `error` | object | No | 仅当运行出错时出现 |
| `└ code` | int32 | No | 错误码 |
| `└ message` | string | No | 错误信息 |

### Response JSON Example

```json
{
  "code": 0,
  "message": "success",
  "data": {
    "chat_uid": "ct_9f2c1a5b",
    "message_id": "42",
    "status": "succeeded",
    "answer": "Tesla (TSLA.US) recently...",
    "references": [
      {
        "index": 1,
        "title": "...",
        "url": "..."
      }
    ],
    "elapsed_time": 3.21
  }
}
```
