跳转到主要内容
POST
/
agents
/
{agentId}
/
threads
curl --request POST \
  --url https://docs.mosoo.ai/api/v1/agents/{agentId}/threads \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "client_external_ref": "draft-empty-thread"
}
'
{
  "links": {
    "thread": "<string>"
  },
  "run": {
    "completedAt": "2023-11-07T05:31:56Z",
    "createdAt": "2023-11-07T05:31:56Z",
    "id": "01ARZ3NDEKTSV4RRFFQ69G5FAV",
    "startedAt": "2023-11-07T05:31:56Z",
    "updatedAt": "2023-11-07T05:31:56Z"
  },
  "thread": {
    "agent_id": "01ARZ3NDEKTSV4RRFFQ69G5FAV",
    "attributed_user": {
      "id": "01ARZ3NDEKTSV4RRFFQ69G5FAV"
    },
    "client_external_ref": "<string>",
    "created_at": "2023-11-07T05:31:56Z",
    "created_by": {
      "id": "01ARZ3NDEKTSV4RRFFQ69G5FAV"
    },
    "id": "01ARZ3NDEKTSV4RRFFQ69G5FAV",
    "last_run_id": "01ARZ3NDEKTSV4RRFFQ69G5FAV",
    "source": "<unknown>",
    "title": "<string>",
    "updated_at": "2023-11-07T05:31:56Z"
  }
}

授权

Authorization
string
header
必填

使用 Authorization: Bearer mst_...。API token 用于识别账号,不携带 scope。

请求头

Idempotency-Key
string

用于安全重试 create-thread 和 send-events 调用的可选键。用同一个键重复提交相同请求会返回原始响应。如果原始请求仍在处理中就重复使用该键,会返回 409。

Maximum string length: 128

路径参数

agentId
string<ulid>
必填

来自 Agent API Access 面板的已发布 Agent ID。v1 ID 是不带前缀的 ULID。

Pattern: ^[0-7][0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{25}$
示例:

"01J00000000000000000000001"

请求体

application/json

创建 Thread 的请求体。所有字段都是可选的:省略 input 会创建一个空的 IDLE Thread;提供 input 会排队启动初始 Run。

client_external_ref
string

调用方自定义的可选引用,例如外部工单 key。该值会存储在 Thread 上用于关联;不要求唯一,也不会由 Mosoo 校验。

Maximum string length: 255
files
object[]

同一个 API token 调用方上传的草稿文件句柄。

input
object

用于初始化 Thread 并排队启动第一个 Run 的用户消息。省略时会创建一个没有 Run 的空 Thread。

响应

已创建 Thread。

创建 Thread 的结果。

已创建 Thread 的便捷链接。

run
object
必填

提供 input 时排队启动的初始 Run;创建空 Thread 时为 null。

thread
object
必填

已创建的 Thread。