Run Steps 描述了智能體運行過程中所採取的步驟,包括模型和工具的調用。
重要Assistant API下線中,建議遷移至Responses API:內建多種工具,並支援多輪上下文管理,可作為替代方案。
列出運行步驟
返回一個運行任務的所有步驟列表。
請求樣本
HTTP
curl --location 'https://dashscope-intl.aliyuncs.com/api/v1/threads/thread_cc2a3e9d-436b-482b-91c5-377e0f376506/runs/run_3de634fa-75d4-4370-adcf-92ba2a60c396/steps?limit=20&order=asc' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY"
SDK
import dashscope
from dashscope import Steps
import os
dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'
steps = Steps.list(
'run_id',
# 建議您優先配置環境變數。若沒有配置環境變數,請用百鍊API Key將下行替換為:api_key="sk-xxx"
api_key=os.getenv("DASHSCOPE_API_KEY"),
thread_id='thread_id',
limit=20
)
import com.alibaba.dashscope.common.GeneralListParam;
import com.alibaba.dashscope.common.ListResult;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.InvalidateParameter;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.threads.runs.RunStep;
import com.alibaba.dashscope.threads.runs.Runs;
import com.alibaba.dashscope.utils.Constants;
public class Main {
static {
Constants.baseHttpApiUrl="https://dashscope-intl.aliyuncs.com/api/v1";
}
public static void main(String[] args) throws ApiException, NoApiKeyException, InputRequiredException, InvalidateParameter, InterruptedException {
Runs runs = new Runs();
// 建議您優先配置環境變數。若沒有配置環境變數,請用百鍊API Key將下行替換為:apiKey("sk-xxx")
GeneralListParam listSteps = GeneralListParam.builder()
.apiKey(System.getenv("DASHSCOPE_API_KEY"))
.build();
ListResult<RunStep> run = runs.listSteps("threadId", "runId", listSteps);
}
}
請求體
參數名稱 | 參數類型 | 是否必須 | 預設值 | 參數描述 |
|---|---|---|---|---|
run_id | string | 是 | 需要列出步驟的運行 (Run) 的 ID。 | |
thread_id | string | 是 | 線程 (Thread) 的 ID。 | |
limit | integer | 否 | None | 要檢索的運行步驟數量。預設為None,表示使用伺服器端的預設值。 |
order | string | 否 | None | 根據created_at欄位進行排序的順序。可以設定為asc(升序)或desc(降序)。預設為None,表示使用伺服器端的預設排序方式。 |
after | string | 否 | None | 用於分頁,指定一個運行步驟 ID,返回在此 ID 之後的運行步驟列表。與before參數互斥。預設為None。 |
before | string | 否 | None | 用於分頁,指定一個運行步驟 ID,返回在此 ID 之前的運行步驟列表。與after參數互斥。預設為None。 |
workspace | string | 是 | None | 阿里雲百鍊的Workspace ID,僅當 api_key 為子業務空間 API Key 時才需要傳入。 |
api_key | string | 是 | None | 阿里雲百鍊的API Key,建議您配置API Key到環境變數。 |
響應樣本
{
"object": "list",
"data": [
{
"id": "[REDACTED]",
"object": "thread.run.step",
"created_at": 1711517599333,
"assistant_id": "[REDACTED]",
"thread_id": "[REDACTED]",
"run_id": "[REDACTED]",
"type": "message_creation",
"status": "completed",
"step_details": {
"type": "message_creation",
"message_creation": {
"message_id": "[REDACTED]"
}
},
"last_error": {
"code": "",
"message": ""
},
"expired_at": 0,
"cancelled_at": -1,
"failed_at": -1,
"completed_at": -1,
"metadata": {},
"usage": {}
}
],
"first_id": "[REDACTED]",
"last_id": "[REDACTED]",
"has_more": false,
"request_id": "[REDACTED]"
}
響應體
一個運行步驟對象列表
檢索運行步驟
請求樣本
HTTP
程式碼範例curl --location 'https://dashscope-intl.aliyuncs.com/api/v1/threads/thread_cc2a3e9d-436b-482b-91c5-377e0f376506/runs/run_3de634fa-75d4-4370-adcf-92ba2a60c396/steps/step_4db180b5-d44a-4b12-9390-4307c6cb87a5' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY"
SDK
程式碼範例import dashscope
from dashscope import Steps
import os
dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'
step = Steps.retrieve(
'step_id',
# 建議您優先配置環境變數。若沒有配置環境變數,請用百鍊API Key將下行替換為:api_key="sk-xxx"
api_key=os.getenv("DASHSCOPE_API_KEY"),
thread_id='thread_id',
run_id='run_id'
)
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.InvalidateParameter;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.threads.runs.RunStep;
import com.alibaba.dashscope.threads.runs.Runs;
import com.alibaba.dashscope.utils.Constants;
public class Main {
static {
Constants.baseHttpApiUrl="https://dashscope-intl.aliyuncs.com/api/v1";
}
public static void main(String[] args) throws ApiException, NoApiKeyException, InputRequiredException, InvalidateParameter, InterruptedException {
Runs runs = new Runs();
// 建議您優先配置環境變數。若沒有配置環境變數,請用百鍊API Key將下行替換為:apiKey("sk-xxx")
String apiKey = System.getenv("DASHSCOPE_API_KEY");
RunStep run = runs.retrieveStep("threadId", "runId", "stepId", apiKey);
}
}
請求體
參數名稱 | 參數類型 | 是否必須 | 預設值 | 參數描述 |
|---|---|---|---|---|
step_id | string | 是 | 要檢索的運行步驟 (RunStep) 的 ID。 | |
thread_id | string | 是 | 線程 (Thread) 的 ID。 | |
run_id | string | 是 | 運行 (Run) 的 ID。 | |
workspace | string | 是 | None | 阿里雲百鍊的Workspace ID,僅當 api_key 為子業務空間 API Key 時才需要傳入。 |
api_key | string | 是 | None | 阿里雲百鍊的API Key,建議您配置API Key到環境變數。 |
響應樣本
{
"assistant_id": "[REDACTED]",
"cancelled_at": null,
"completed_at": 1735025124000,
"created_at": 1735025123150,
"expired_at": null,
"failed_at": null,
"id": "[REDACTED]",
"last_error": null,
"metadata": {},
"object": "thread.run.step",
"request_id": "[REDACTED]",
"run_id": "[REDACTED]",
"status": "completed",
"step_details": {
"message_creation": {
"message_id": "[REDACTED]"
},
"type": "message_creation"
},
"thread_id": "[REDACTED]",
"type": "message_creation",
"usage": null
}
響應體
與指定 ID 匹配的運行步驟對象。
運行步驟對象
表示運行執行過程中的一個步驟。
對象樣本
{
"id": "[REDACTED]",
"assistant_id": "[REDACTED]",
"cancelled_at": null,
"completed_at": 1678886400,
"created_at": 1678886300,
"expired_at": null,
"failed_at": null,
"last_error": null,
"metadata": {
"user_id": "[REDACTED]",
"context": "order_processing"
},
"object": "thread.run.step",
"run_id": "[REDACTED]",
"status": "completed",
"step_details": {
"type": "message_creation",
"message_creation": {
"message_id": "[REDACTED]"
}
},
"thread_id": "[REDACTED]",
"type": "message_creation",
"usage": {
"prompt_tokens": 10,
"completion_tokens": 20,
"total_tokens": 30
}
}
對象屬性
參數名稱 | 參數類型 | 參數描述 |
|---|---|---|
id | string | 運行步驟的唯一識別碼,可在 API 端點中引用。 |
assistant_id | string | 與此運行步驟關聯的助手的 ID。 |
cancelled_at | integer | 運行步驟被取消的時間戳記(Unix 13位時間戳記,單位:毫秒)。 |
completed_at | integer | 運行步驟完成的時間戳記(Unix 13位時間戳記,單位:毫秒)。 |
created_at | integer | 運行步驟建立的時間戳記(Unix 13位時間戳記,單位:毫秒)。 |
expired_at | integer | 運行步驟到期的時間戳記(Unix 13位時間戳記,單位:毫秒)。如果父運行已到期,則步驟也被視為已到期。 |
failed_at | integer | 運行步驟失敗的時間戳記(Unix 13位時間戳記,單位:毫秒)。 |
last_error | object | 與此運行步驟相關的最後一個錯誤。如果沒有錯誤,則為null。 |
metadata | map | 一組最多包含 16 個索引值對,可以附加到對象上。用於以結構化格式儲存有關對象的附加資訊。鍵的最大長度為 64 個字元,值的最大長度為 512 個字元。 |
object | string | 物件類型,始終為thread.run.step。 |
run_id | string | 此運行步驟所屬的啟動並執行 ID。 |
status | string | 運行步驟的狀態,可以是in_progress(進行中)、cancelled(已取消)、failed(已失敗)、completed(已完成)或expired(已到期)。 |
step_details | object | 運行步驟的詳細資料。 |
thread_id | string | 啟動並執行線程的 ID。 |
type | string | 運行步驟的類型,可以是message_creation(訊息建立)或tool_calls(工具調用)。 |
usage | object | 資源使用方式統計資訊。 |
status_code | integer | HTTP 狀態代碼。注意:此參數主要用於內部處理,通常情況下,您無需關注此參數。 |
錯誤碼
如果模型調用失敗並返回報錯資訊,請參見錯誤資訊進行解決。