智能体

停止后台任务(扩展)

请求停止运行中的后台任务并返回当前任务。

POST /agent/v1/sessions/{session_id}/background_tasks/{task_id}/stop● 支持

请求参数

  • session_idstring必填

    path: Session id (sesn_...), as returned by sessions.create or sessions.list. The same id is also accepted as the session_id query parameter on resource and thread calls, where it must equal the path value.

  • task_idstring必填

    path: Background task id (task_...), as listed by sessions.background_tasks.list.

返回

200

复用 TaskStop:持久化 stop_requested_at 并终止进程组。返回 BackgroundTask;终止尚未观察到时仍可为 running,但不可取消。已结束或不支持停止的任务返回 409。

错误按 Anthropic 错误格式返回(type / message / request_id),参见 错误码

响应

HTTP 200

Current task after stop request

application/json

名称类型说明
idstringIdentifier of the object, as returned by the API; pass it in the path of follow-up calls on the same resource.
kindstringKind of background task: bash for a command started with run_in_background, monitor for a Monitor watch.
titlestringShort human-readable title of the task or object.
thread_idstring | nullExecution thread the task belongs to; null for the primary thread.
statusstringCurrent lifecycle state.
started_atstringRFC 3339 time at which the task started.
ended_atstring | nullRFC 3339 time at which the task ended; null while it is running.
cancellablebooleanWhether the task can still be stopped.
notified_atstring | nullRFC 3339 time of the latest run that the task's notification started; null while no notification has been delivered.
trigger_countinteger | nullFor a monitor task, how many times its matches woke the session; null for other kinds or before the first notification.