This topic describes the functions of the run component of Assistant API, including how to create, list, retrieve, and modify runs, submit tool outputs, and wait for runs to end.
Function | Description |
Create run | Creates a run class for executing a thread. |
Create thread and run | Creates and runs a thread. |
List run | Lists runs within a thread. |
List run step | Lists run steps of a run. |
Retrieve run | Retrieves a run instance. |
Retrieve run step | Retrieves a run step. |
Modify run | Modifies a run instance. |
Submit tool outputs to run | Submit tool results to a run instance and proceed with the run. |
Create a run task
HTTP
Sample code
Non-streaming
curl --location 'https://dashscope-intl.aliyuncs.com/api/v1/threads/thread_cc2a3e9d-436b-482b-91c5-377e0f376506/runs' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--data '{
"assistant_id": "asst_46e95014-ccac-435d-b884-c97ac44a94d9",
"metadata": {}
}'
Streaming
curl --location 'https://dashscope-intl.aliyuncs.com/api/v1/threads/thread_cc2a3e9d-436b-482b-91c5-377e0f376506/runs' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--data '{
"assistant_id": "asst_46e95014-ccac-435d-b884-c97ac44a94d9",
"metadata": {},
"stream": true
}'
Request parameters
Parameter | Description | Type | Required |
thread id | The ID of the thread to run. | str | Yes |
assistant id | The ID of the assistant to run. | str | Yes |
model | The name of the model to use. If specified here, the model defined in the assistant is overrode. | str | No |
instructions | The system prompt. If specified here, the instruction defined in the assistant is overrode. | str | No |
additional instruction | Adds additional instruction to the end of the original instruction. | str | No |
tools | The tool list. If specified here, the tool list defined in the assistant is overrode. For more informaion, see the Note below. | str | No |
metadata | Other related parameter descriptions. | str | No |
stream | Specifies whether to enable the streaming output mode. | boolean | No |
temperature | Controls the diversity of the responses generated by the model. | float | No |
top_p | The probability threshold of the sampling method. | float | No |
top_k | The size of the candidate set for sampling. | integer | No |
Configure authentication information for custom tools in the following way:
{
"type": "plugin_type",
"auth": {
"type": "user_http",
"user_token": "bearer-token", }
}
When the assistant requests to call a plug-in, the assistant configures the bearer token in the following field:
{"plugin_type":{"user_token": "bearer-token"}}'
Then it adds the bearer token in the header of the requested plugin.
Sample response
Non-streaming
{
"id": "run_3de634fa-75d4-4370-adcf-92ba2a60c396",
"object": "thread.run",
"created_at": 1711517598169,
"thread_id": "thread_cc2a3e9d-436b-482b-91c5-377e0f376506",
"assistant_id": "asst_46e95014-ccac-435d-b884-c97ac44a94d9",
"status": "in_progress",
"model": "qwen-max",
"instructions": "You are an intelligent assistant. You can use different tools based on user needs and then provide answers. Use tools when needed.",
"tools": [
{
"type": "search"
},
{
"type": "text_to_image"
}
],
"metadata": {},
"request_id": "225292ff-9843-95d4-8591-b1377c33e2be"
}
Streaming
event:thread.created
data:{"id":"thread_5b7824dc-dbf9-4538-b214-624ee199caa4","object":"thread","created_at":1714448101977,"metadata":{},"request_id":"f38314af-21c4-945e-acdc-cb9765d1d48f"}
event:thread.run.created
data:{"id":"run_04fba6a3-3ac9-42e8-ba2b-9b5c889a8d58","object":"thread.run","created_at":1714448101996,"thread_id":"thread_5b7824dc-dbf9-4538-b214-624ee199caa4","assistant_id":"asst_5378d83a-f612-4fc1-9034-915351d67d98","status":"queued","required_action":null,"last_error":null,"expires_at":null,"started_at":null,"cancelled_at":null,"failed_at":null,"completed_at":null,"model":"qwen-max","instructions":"You are an intelligent assistant. You can use different tools based on user needs and then provide answers. Use tools when needed.","tools":[{"type":"text_to_image"},{"type":"function","function":{"name":"get_current_weather","description":"Get the current weather in a given location","parameters":{"type":"object","properties":{"location":{"type":"string","description":"The city and state, e.g. San Francisco, CA"},"unit":{"type":"string","enum":["celsius","fahrenheit"]}},"required":["location"]}}}],"file_ids":[],"metadata":{},"usage":null,"temperature":null,"top_p":null,"top_k":null,"max_tokens":null,"truncation_strategy":null,"request_id":"f38314af-21c4-945e-acdc-cb9765d1d48f"}
event:thread.run.queued
data:{"id":"run_04fba6a3-3ac9-42e8-ba2b-9b5c889a8d58","object":"thread.run","created_at":1714448101996,"thread_id":"thread_5b7824dc-dbf9-4538-b214-624ee199caa4","assistant_id":"asst_5378d83a-f612-4fc1-9034-915351d67d98","status":"queued","required_action":null,"last_error":null,"expires_at":null,"started_at":null,"cancelled_at":null,"failed_at":null,"completed_at":null,"model":"qwen-max","instructions":"You are an intelligent assistant. You can use different tools based on user needs and then provide answers. Use tools when needed.","tools":[{"type":"text_to_image"},{"type":"function","function":{"name":"get_current_weather","description":"Get the current weather in a given location","parameters":{"type":"object","properties":{"location":{"type":"string","description":"The city and state, e.g. San Francisco, CA"},"unit":{"type":"string","enum":["celsius","fahrenheit"]}},"required":["location"]}}}],"file_ids":[],"metadata":{},"usage":null,"temperature":null,"top_p":null,"top_k":null,"max_tokens":null,"truncation_strategy":null,"request_id":"f38314af-21c4-945e-acdc-cb9765d1d48f"}
event:thread.run.in_progress
data:{"id":"run_04fba6a3-3ac9-42e8-ba2b-9b5c889a8d58","object":"thread.run","created_at":1714448101996,"thread_id":"thread_5b7824dc-dbf9-4538-b214-624ee199caa4","assistant_id":"asst_5378d83a-f612-4fc1-9034-915351d67d98","status":"in_progress","required_action":null,"last_error":null,"expires_at":null,"started_at":null,"cancelled_at":null,"failed_at":null,"completed_at":null,"model":"qwen-max","instructions":"You are an intelligent assistant. You can use different tools based on user needs and then provide answers. Use tools when needed.","tools":[{"type":"text_to_image"},{"type":"function","function":{"name":"get_current_weather","description":"Get the current weather in a given location","parameters":{"type":"object","properties":{"location":{"type":"string","description":"The city and state, e.g. San Francisco, CA"},"unit":{"type":"string","enum":["celsius","fahrenheit"]}},"required":["location"]}}}],"file_ids":[],"metadata":{},"usage":null,"temperature":null,"top_p":null,"top_k":null,"max_tokens":null,"truncation_strategy":null,"request_id":"f38314af-21c4-945e-acdc-cb9765d1d48f"}
event:thread.run.step.created
data:{"id":"step_52c42910-4993-496d-a7f3-ecd4cf007839","object":"thread.run.step","created_at":1714448102574,"assistant_id":"asst_5378d83a-f612-4fc1-9034-915351d67d98","thread_id":"thread_5b7824dc-dbf9-4538-b214-624ee199caa4","run_id":"run_04fba6a3-3ac9-42e8-ba2b-9b5c889a8d58","type":"message_creation","status":"in_progress","step_details":{"type":"message_creation","message_creation":{"message_id":"message_f4f68f6b-6003-4115-8f20-3ea590137502"}},"last_error":null,"expired_at":null,"cancelled_at":null,"failed_at":null,"completed_at":null,"metadata":{},"usage":null,"request_id":"f38314af-21c4-945e-acdc-cb9765d1d48f"}
event:thread.run.step.in_progress
data:{"id":"step_52c42910-4993-496d-a7f3-ecd4cf007839","object":"thread.run.step","created_at":1714448102574,"assistant_id":"asst_5378d83a-f612-4fc1-9034-915351d67d98","thread_id":"thread_5b7824dc-dbf9-4538-b214-624ee199caa4","run_id":"run_04fba6a3-3ac9-42e8-ba2b-9b5c889a8d58","type":"message_creation","status":"in_progress","step_details":{"type":"message_creation","message_creation":{"message_id":"message_f4f68f6b-6003-4115-8f20-3ea590137502"}},"last_error":null,"expired_at":null,"cancelled_at":null,"failed_at":null,"completed_at":null,"metadata":{},"usage":null,"request_id":"f38314af-21c4-945e-acdc-cb9765d1d48f"}
event:thread.message.created
data:{"id":"message_f4f68f6b-6003-4115-8f20-3ea590137502","object":"thread.message","created_at":1714448102574,"thread_id":"thread_5b7824dc-dbf9-4538-b214-624ee199caa4","incomplete_details":null,"completed_at":null,"incomplete_at":null,"role":"assistant","content":[],"assistant_id":"asst_5378d83a-f612-4fc1-9034-915351d67d98","run_id":"run_04fba6a3-3ac9-42e8-ba2b-9b5c889a8d58","file_ids":[],"metadata":{},"request_id":"f38314af-21c4-945e-acdc-cb9765d1d48f"}
event:thread.message.in_progress
data:{"id":"message_f4f68f6b-6003-4115-8f20-3ea590137502","object":"thread.message","created_at":1714448102574,"thread_id":"thread_5b7824dc-dbf9-4538-b214-624ee199caa4","incomplete_details":null,"completed_at":null,"incomplete_at":null,"role":"assistant","content":[],"assistant_id":"asst_5378d83a-f612-4fc1-9034-915351d67d98","run_id":"run_04fba6a3-3ac9-42e8-ba2b-9b5c889a8d58","file_ids":[],"metadata":{},"request_id":"f38314af-21c4-945e-acdc-cb9765d1d48f"}
event:thread.message.delta
data:{"id":"message_f4f68f6b-6003-4115-8f20-3ea590137502","object":"thread.message.delta","delta":{"role":"assistant","content":[{"type":"text","text":{"value":"9","annotations":[]}}],"file_ids":[]},"request_id":"f38314af-21c4-945e-acdc-cb9765d1d48f"}
event:thread.message.delta
data:{"id":"message_f4f68f6b-6003-4115-8f20-3ea590137502","object":"thread.message.delta","delta":{"role":"assistant","content":[{"type":"text","text":{"value":"9","annotations":[]}}],"file_ids":[]},"request_id":"f38314af-21c4-945e-acdc-cb9765d1d48f"}
event:thread.message.delta
data:{"id":"message_f4f68f6b-6003-4115-8f20-3ea590137502","object":"thread.message.delta","delta":{"role":"assistant","content":[{"type":"text","text":{"value":"9","annotations":[]}}],"file_ids":[]},"request_id":"f38314af-21c4-945e-acdc-cb9765d1d48f"}
event:thread.message.delta
data:{"id":"message_f4f68f6b-6003-4115-8f20-3ea590137502","object":"thread.message.delta","delta":{"role":"assistant","content":[{"type":"text","text":{"value":"times 998","annotations":[]}}],"file_ids":[]},"request_id":"f38314af-21c4-945e-acdc-cb9765d1d48f"}
event:thread.message.delta
data:{"id":"message_f4f68f6b-6003-4115-8f20-3ea590137502","object":"thread.message.delta","delta":{"role":"assistant","content":[{"type":"text","text":{"value":"equals 997002.","annotations":[]}}],"file_ids":[]},"request_id":"f38314af-21c4-945e-acdc-cb9765d1d48f"}
event:thread.message.delta
data:{"id":"message_f4f68f6b-6003-4115-8f20-3ea590137502","object":"thread.message.delta","delta":{"role":"assistant","content":[{"type":"text","text":{"value":"","annotations":[]}}],"file_ids":[]},"request_id":"f38314af-21c4-945e-acdc-cb9765d1d48f"}
event:thread.message.completed
data:{"id":"message_f4f68f6b-6003-4115-8f20-3ea590137502","object":"thread.message","created_at":1714448102574,"thread_id":"thread_5b7824dc-dbf9-4538-b214-624ee199caa4","incomplete_details":null,"completed_at":1714448104154,"incomplete_at":null,"role":"assistant","content":[{"type":"text","text":{"value":"999 times 998 equals 997002.","annotations":[]}}],"assistant_id":"asst_5378d83a-f612-4fc1-9034-915351d67d98","run_id":"run_04fba6a3-3ac9-42e8-ba2b-9b5c889a8d58","file_ids":[],"metadata":{},"request_id":"f38314af-21c4-945e-acdc-cb9765d1d48f"}
event:thread.run.step.completed
data:{"id":"step_52c42910-4993-496d-a7f3-ecd4cf007839","object":"thread.run.step","created_at":1714448102574,"assistant_id":"asst_5378d83a-f612-4fc1-9034-915351d67d98","thread_id":"thread_5b7824dc-dbf9-4538-b214-624ee199caa4","run_id":"run_04fba6a3-3ac9-42e8-ba2b-9b5c889a8d58","type":"message_creation","status":"completed","step_details":{"type":"message_creation","message_creation":{"message_id":"message_f4f68f6b-6003-4115-8f20-3ea590137502"}},"last_error":null,"expired_at":null,"cancelled_at":null,"failed_at":null,"completed_at":1714448104154,"metadata":{},"usage":null,"request_id":"f38314af-21c4-945e-acdc-cb9765d1d48f"}
event:thread.run.completed
data:{"id":"run_04fba6a3-3ac9-42e8-ba2b-9b5c889a8d58","object":"thread.run","created_at":1714448101996,"thread_id":"thread_5b7824dc-dbf9-4538-b214-624ee199caa4","assistant_id":"asst_5378d83a-f612-4fc1-9034-915351d67d98","status":"completed","required_action":null,"last_error":null,"expires_at":null,"started_at":null,"cancelled_at":null,"failed_at":null,"completed_at":null,"model":"qwen-max","instructions":"You are an intelligent assistant. You can use different tools based on user needs and then provide answers. Use tools when needed.","tools":[{"type":"text_to_image"},{"type":"function","function":{"name":"get_current_weather","description":"Get the current weather in a given location","parameters":{"type":"object","properties":{"location":{"type":"string","description":"The city and state, e.g. San Francisco, CA"},"unit":{"type":"string","enum":["celsius","fahrenheit"]}},"required":["location"]}}}],"file_ids":[],"metadata":{},"usage":{"input_tokens":419,"output_tokens":16,"total_tokens":435},"temperature":null,"top_p":null,"top_k":null,"max_tokens":null,"truncation_strategy":null,"request_id":"f38314af-21c4-945e-acdc-cb9765d1d48f"}
event:done
data:[DONE]
Response parameters
The created run class, including the following parameters:
id: The run ID.
thread_id: The thread ID.
assistant_id: The assistant ID.
request_id: The request ID.
SDK
Sample code in streaming mode
stream_iterator = dashscope.Runs.create(thread.id,
assistant_id=assistant.id,
stream=True)
for event, msg in stream_iterator:
print(event)
print(msg)
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.AssistantStreamMessage;
import com.alibaba.dashscope.threads.runs.RunParam;
import com.alibaba.dashscope.threads.runs.Runs;
import io.reactivex.Flowable;
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();
RunParam runParam = RunParam.builder().assistantId("assistantId").stream(true).build();
Flowable<AssistantStreamMessage> run = runs.createStream("threadId", runParam);
}
}
Request parameters
Parameter | Type | Default value | Description |
thread_id | str | - | The ID of the thread on which to create the run. |
assistant_id | str | - | The assistant ID. |
model | str | - | The model that is used. |
instructions | str | None | The prompt of this run. |
additional_instructions | str | None | The additional instruction of this run. |
tools | List[Dict] | [] | The tools that are used by the assistant. |
stream | boolean | False | Specifies whether to enable the streaming output mode. |
metadata | Dict | None | The metadata of the assistant. |
temperature | For information about these parameters, see Qwen. | ||
top_p | |||
top_k | |||
max_tokens | |||
truncation_strategy | Dict | None | The truncation strategy of the thread. Valid and default value:
|
workspace | str | None | The workspace ID. |
api_key | str | None | The API key. You can set it as an environment variable. |
Configure authentication information for custom tools in the following way:
{
"type": "plugin_type",
"auth": {
"type": "user_http",
"user_token": "bearer-token", }
}
When the assistant requests to call a plug-in, the assistant configures the bearer token in the following field:
{"plugin_type":{"user_token": "bearer-token"}}'
Add the bearer token to a request header.
Sample response
In streaming output mode, events and event data are returned. Sample response:
thread.run.created
{'tools': [{'type': 'quark_search'}], 'required_action': None, 'id': 'run_0f314675-06a4-4379-929c-d29cd351a446', 'object': 'thread.run', 'created_at': 1714460227904, 'thread_id': 'thread_28f0b00b-d825-48f5-bb27-f3b171a64d33', 'assistant_id': 'asst_9453fe59-d6eb-498e-aeca-9abecd492e51', 'status': 'queued', 'last_error': None, 'expires_at': None, 'started_at': None, 'cancelled_at': None, 'failed_at': None, 'completed_at': None, 'model': 'qwen-max', 'instructions': 'You are a helpful assistant. When asked a question, use tools wherever possible.', 'file_ids': [], 'metadata': {}, 'usage': None, 'temperature': None, 'top_p': None, 'top_k': None, 'max_tokens': None, 'truncation_strategy': None, 'request_id': '38fb88b8-196a-9919-8815-f7ed9aa0891f', 'status_code': 200}
thread.run.queued
{'tools': [{'type': 'quark_search'}], 'required_action': None, 'id': 'run_0f314675-06a4-4379-929c-d29cd351a446', 'object': 'thread.run', 'created_at': 1714460227904, 'thread_id': 'thread_28f0b00b-d825-48f5-bb27-f3b171a64d33', 'assistant_id': 'asst_9453fe59-d6eb-498e-aeca-9abecd492e51', 'status': 'queued', 'last_error': None, 'expires_at': None, 'started_at': None, 'cancelled_at': None, 'failed_at': None, 'completed_at': None, 'model': 'qwen-max', 'instructions': 'You are a helpful assistant. When asked a question, use tools wherever possible.', 'file_ids': [], 'metadata': {}, 'usage': None, 'temperature': None, 'top_p': None, 'top_k': None, 'max_tokens': None, 'truncation_strategy': None, 'request_id': '38fb88b8-196a-9919-8815-f7ed9aa0891f', 'status_code': 200}
thread.run.in_progress
{'tools': [{'type': 'quark_search'}], 'required_action': None, 'id': 'run_0f314675-06a4-4379-929c-d29cd351a446', 'object': 'thread.run', 'created_at': 1714460227904, 'thread_id': 'thread_28f0b00b-d825-48f5-bb27-f3b171a64d33', 'assistant_id': 'asst_9453fe59-d6eb-498e-aeca-9abecd492e51', 'status': 'in_progress', 'last_error': None, 'expires_at': None, 'started_at': None, 'cancelled_at': None, 'failed_at': None, 'completed_at': None, 'model': 'qwen-max', 'instructions': 'You are a helpful assistant. When asked a question, use tools wherever possible.', 'file_ids': [], 'metadata': {}, 'usage': None, 'temperature': None, 'top_p': None, 'top_k': None, 'max_tokens': None, 'truncation_strategy': None, 'request_id': '38fb88b8-196a-9919-8815-f7ed9aa0891f', 'status_code': 200}
thread.run.step.created
{'step_details': {'tool_calls': [], 'type': 'tool_calls'}, 'usage': None, 'id': 'step_f923bd08-1e22-40d9-bf54-373b21fde378', 'object': 'thread.run.step', 'created_at': 1714460228960, 'assistant_id': 'asst_9453fe59-d6eb-498e-aeca-9abecd492e51', 'thread_id': 'thread_28f0b00b-d825-48f5-bb27-f3b171a64d33', 'run_id': 'run_0f314675-06a4-4379-929c-d29cd351a446', 'type': 'tool_calls', 'status': 'in_progress', 'expired_at': None, 'cancelled_at': None, 'failed_at': None, 'completed_at': None, 'metadata': {}, 'request_id': '38fb88b8-196a-9919-8815-f7ed9aa0891f', 'status_code': 200, 'last_error': None}
thread.run.step.in_progress
{'step_details': {'tool_calls': [], 'type': 'tool_calls'}, 'usage': None, 'id': 'step_f923bd08-1e22-40d9-bf54-373b21fde378', 'object': 'thread.run.step', 'created_at': 1714460228960, 'assistant_id': 'asst_9453fe59-d6eb-498e-aeca-9abecd492e51', 'thread_id': 'thread_28f0b00b-d825-48f5-bb27-f3b171a64d33', 'run_id': 'run_0f314675-06a4-4379-929c-d29cd351a446', 'type': 'tool_calls', 'status': 'in_progress', 'expired_at': None, 'cancelled_at': None, 'failed_at': None, 'completed_at': None, 'metadata': {}, 'request_id': '38fb88b8-196a-9919-8815-f7ed9aa0891f', 'status_code': 200, 'last_error': None}
thread.run.step.delta
{'delta': {'step_details': {'tool_calls': [{'type': 'quark_search', 'quark_search': {'arguments': ''}}], 'type': 'tool_calls'}}, 'id': 'step_f923bd08-1e22-40d9-bf54-373b21fde378', 'object': 'thread.run.step.delta', 'request_id': '38fb88b8-196a-9919-8815-f7ed9aa0891f', 'status_code': 200}
thread.run.step.delta
{'delta': {'step_details': {'tool_calls': [{'type': 'quark_search', 'quark_search': {'arguments': '{"query": "'}}], 'type': 'tool_calls'}}, 'id': 'step_f923bd08-1e22-40d9-bf54-373b21fde378', 'object': 'thread.run.step.delta', 'request_id': '38fb88b8-196a-9919-8815-f7ed9aa0891f', 'status_code': 200}
thread.run.step.delta
{'delta': {'step_details': {'tool_calls': [{'type': 'quark_search', 'quark_search': {'arguments': 'Today's weather in Beijing "}'}], 'type': 'tool_calls': ' }}}, 'id': 'step_f923bd08-1e22-40d9-bf54-373b21fde378', 'object': thread.run.step.delta
thread.run.step.delta
{'delta': {'step_details': {'tool_calls': [{'type': 'quark_search', 'quark_search': {'arguments': ''}}], 'type': 'tool_calls'}}, 'id': 'step_f923bd08-1e22-40d9-bf54-373b21fde378', 'object': 'thread.run.step.delta', 'request_id': '38fb88b8-196a-9919-8815-f7ed9aa0891f', 'status_code': 200}
thread.run.step.delta
{'delta': {'step_details': {'tool_calls': [{'type': 'quark_search', 'quark_search': {'arguments': ''}}], 'type': 'tool_calls'}}, 'id': 'step_f923bd08-1e22-40d9-bf54-373b21fde378', 'object': 'thread.run.step.delta', 'request_id': '38fb88b8-196a-9919-8815-f7ed9aa0891f', 'status_code': 200}
thread.run.step.delta
{'delta': {'step_details': {'tool_calls': [{'type': 'quark_search', 'plugin_name': {'output': '{"success": true, "errorCode": null, "errorMsg": null, "data": [{"title": "Weather in Beijing, China", "url": null, "desc": "Real-time weather, clear, feels like 24 degrees Celsius, apparent temperature at 23 degrees Celsius, west wind level 1. moderate temperature, very comfortable. Click here to view the weather forecast for the next 15 days", "type": "weather_moji", "original": null, "query": null, "source": null}, {"title": "Beijing Meteorological Service", "url": "http://bj.cma.gov.cn/fzlm/index.html", "desc": "36-Hour Weather Forecast (Issued by Beijing Meteorological Service on 2024-01-25 05:24:58) Today daytime High of 5°C; Mostly sunny with some clouds; northwesterly winds at level 3, gusting to level 5, later easing to level 2 Tonight Low of -5°C; clear; northwesterly winds at level 2, later increasing to level 3 Tomorrow daytime high of 5°C; clear; northwesterly wind at level 3, later easing to level 1 ...", "type": "structure_web_info", "original": null, "query": null, "source": "Beijing Meteorological Service"}, {"title": "Beijing", "url": "https://m.weather.com.cn/mweather/101010100.shtml?_t=1480291523052", "desc": "Beijing weather forecast, timely and accurate release of weather information from the Central Meteorological Service, convenient query of today's weather in Beijing, weekend weather in Beijing, one-week weather forecast in Beijing, blue sky forecast in Beijing, weather forecast in Beijing, 40 day weather forecast in Beijing, also Beijing's daily activity index and health index ...", "type": "normal", "original": null, "query": null, "source": "Weather in China"}, {"title": "moji.com", "url": "https://m.moji.com/", "desc": "Moji Weather Forecast App, used by approximately 650 million people worldwide, supports weather forecast queries for over 200,000 cities and regions across 199 countries. Download Moji App to monitor real-time weather conditions as well as real-time air quality and air quality ratings.", "type": "structure_web_info", "original": null, "query": null, "source": "Moji App"}, {"title": "Beijing", "url": "http://sq.weather.com.cn/mweather15d/101010100.shtml?from=singlemessage", "desc": "Beijing weather forecast, timely and accurate release of weather information from the Central Meteorological Service, convenient query of today's weather in Beijing, weekend weather in Beijing, one-week weather forecast in Beijing, blue sky forecast in Beijing, weather forecast in Beijing, 40 day weather forecast in Beijing, also Beijing's daily activity index and health index ...", "type": "structure_web_info", "original": null, "query": null, "source": "Weather China"}, {"title": "News", "url": null, "desc": "Reported by Weather China 1 day ago: Forecast, Warnings, Radar, Satellite Images, Weather Maps, Professional Products, Information, Videos, Solar Terms, My Sky... Prince Gong's Mansion, Beijing Olympic Park, Olympic Forest Park, Beijing Shijingshan Park, Jinhai Lake, Jingdong Grand Canyon Scenic Area, Ming Tombs, Yinshan Pagoda Forest Scenic Area, China Aviation Museum, Beijing Happy Valley ...", "type": "news_uchq", "original": null, "query": null, "source": null}, {"title": "Beijing", "url": "http://www.weather.com.cn/weather1d/101010100.shtml", "desc": "Beijing weather forecast, timely and accurate release of weather information from the Central Meteorological Service, convenient query of today's weather in Beijing, weekend weather in Beijing, one-week weather forecast in Beijing ...", "type": "structure_web_info", "original": null, "query": null, "source": "Weather China"}, {"title": "24-hour weather query in Beijing _ Today's weather forecast query in Beijing _ 2345 Weather", "url": "http://waptianqi.2345.com/24hour-54511.htm", "desc": "2345 Weather Forecast provides you with the latest weather updates for Beijing today, including 24-hour weather conditions and other related information. Additionally, it offers the meteorological index for Beijing on the given day.", "type": "structure_web_info", "original": null, "query": null, "source": "2345 Weather"}, {"title": "15-day weather in Beijing", "url": "http://waptianqi.2345.com/beijing-54511.htm", "desc": "2345 Weather Forecast provides weather forecasts for Beijing. Get detailed insights into the weather in Beijing and surrounding areas for the next 15 to 30 days, including temperature, air quality, precipitation, wind speed, air pressure, and UV intensity", "type": "structure_web_info", "original": null, "query": null, "source": "2345 Weather"}, {"title": "15-day weather forecast for Beijing", "url": "https://m.tianqi.com/beijing/15/", "desc": "15-Day Beijing Weather Forecast Details:12/11 Today: Light Snow, -2 to 2°C12/12 Tomorrow: Cloudy turning to Light Snow, -2 to 2°C12/13 The Day After Tomorrow: Light Snow, -5 to 0°C12/14 Thursday: Light Snow, -5 to -1°C12/15 Friday: Overcast turning to Cloudy, -10 to -2°C12/16 Saturday: Clear, -10 to -3°C12/17 ...", "type": "structure_web_info", "original": null, "query": null, "source": "Weather"}, {"title": "Beijing Weather", "url": "https://t.8684.com/beijing_beijing", "desc": "Beijing weather forecast for 15 days, Beijing weather forecast, Beijing weather forecast for 1 week, Beijing weather forecast for 15 days, Beijing weather forecast for this week, Beijing weather forecast for next week, Beijing weather forecast for 15 days, Beijing weather forecast for 10 days", "type": "structure_web_info", "original": null, "query": null, "source": "8684 Weather"}], "requestId": null, "failed": false}'}}], 'type': 'tool_calls'}}, 'id': 'step_f923bd08-1e22-40d9-bf54-373b21fde378', 'object': 'thread.run.step.delta', 'request_id': '38fb88b8-196a-9919-8815-f7ed9aa0891f', 'status_code': 200}
thread.run.step.delta
{'delta': {'step_details': {'tool_calls': [{'quark_search': {'output': ''}}], 'type': 'tool_calls'}}, 'id': 'step_f923bd08-1e22-40d9-bf54-373b21fde378', 'object': 'thread.run.step.delta', 'request_id': '38fb88b8-196a-9919-8815-f7ed9aa0891f', 'status_code': 200}
thread.run.step.delta
{'delta': {'step_details': {'tool_calls': [{'quark_search': {'output': ''}}], 'type': 'tool_calls'}}, 'id': 'step_f923bd08-1e22-40d9-bf54-373b21fde378', 'object': 'thread.run.step.delta', 'request_id': '38fb88b8-196a-9919-8815-f7ed9aa0891f', 'status_code': 200}
thread.run.step.completed
{'step_details': {'tool_calls': [{'type': 'quark_search', 'plugin_name': {'arguments': '{"query": "weather in Beijing today"}', 'output': '{"success": true, "errorCode": snull "weather in Beijing": stitle "" url": null, "desc": " real-time weather conditions, sunny, temperature 24 degrees, feels like 23 degrees, west wind level 1, moderate temperature, very comfortable. Click here to view the weather forecast for the next 15 days", "type": "weather_moji", "original": null, "query": null, "source": null}, {"title": "Beijing Meteorological Service", "url": "http://bj.cma.gov.cn/fzlm/index.html", "desc": "36-Hour Weather Forecast (Issued by Beijing Meteorological Service on 2024-01-25 05:24:58) Today daytime High of 5°C; Mostly sunny with some clouds; northwesterly winds at level 3, gusting to level 5, later easing to level 2 Tonight Low of -5°C; clear; northwesterly winds at level 2, later increasing to level 3 Tomorrow daytime high of 5°C; clear; northwesterly wind at level 3, later easing to level 1 ...", "type": "structure_web_info", "original": null, "query": null, "source": "Beijing Meteorological Service"}, {"title": "Beijing", "url": "https://m.weather.com.cn/mweather/101010100.shtml?_t=1480291523052", "desc": "Beijing weather forecast, timely and accurate release of weather information from the Central Meteorological Service, convenient query of today's weather in Beijing, weekend weather in Beijing, one-week weather forecast in Beijing, blue sky forecast in Beijing, weather forecast in Beijing, 40 day weather forecast in Beijing, also Beijing's daily activity index and health index ...", "type": "normal", "original": null, "query": null, "source": "Weather in China"}, {"title": "moji.com, "url": "https://m.moji.com/", "desc": "Moji Weather Forecast App, used by approximately 650 million people worldwide, supports weather forecast queries for over 200,000 cities and regions across 199 countries. Download Moji App to monitor real-time weather conditions as well as real-time air quality and air quality ratings.", "type": "structure_web_info", "original": null, "query": null, "source": "Moji App"}, {"title": "Beijing", "url": "http://sq.weather.com.cn/mweather15d/101010100.shtml?from=singlemessage", "desc": "Beijing weather forecast, timely and accurate release of weather information from the Central Meteorological Service, convenient query of today's weather in Beijing, weekend weather in Beijing, one-week weather forecast in Beijing, blue sky forecast in Beijing, weather forecast in Beijing, 40 day weather forecast in Beijing, also Beijing's daily activity index and health index ...", "type": "structure_web_info", "original": null, "query": null, "source": "Weather China"}, {"title": "News", "url": null, "desc": "Reported by Weather China 1 day ago: Forecast, Warnings, Radar, Satellite Images, Weather Maps, Professional Products, Information, Videos, Solar Terms, My Sky... Prince Gong's Mansion, Beijing Olympic Park, Olympic Forest Park, Beijing Shijingshan Park, Jinhai Lake, Jingdong Grand Canyon Scenic Area, Ming Tombs, Yinshan Pagoda Forest Scenic Area, China Aviation Museum, Beijing Happy Valley ...", "type": "news_uchq", "original": null, "query": null, "source": null}, {"title": "Beijing", "url": "http://www.weather.com.cn/weather1d/101010100.shtml", "desc": "Beijing weather forecast, timely and accurate release of weather information from the Central Meteorological Service, convenient query of today's weather in Beijing, weekend weather in Beijing, one-week weather forecast in Beijing ...", "type": "structure_web_info", "original": null, "query": null, "source": "Weather China"}, {"title": "24-hour weather query in Beijing _ Today's weather forecast query in Beijing _ 2345 Weather", "url": "http://waptianqi.2345.com/24hour-54511.htm", "desc": "2345 Weather Forecast provides you with the latest weather updates for Beijing today, including 24-hour weather conditions and other related information. Additionally, it offers the meteorological index for Beijing on the given day.", "type": "structure_web_info", "original": null, "query": null, "source": "2345 Weather"}, {"title": "15-day weather in Beijing", "url": "http://waptianqi.2345.com/beijing-54511.htm", "desc": "2345 Weather Forecast provides weather forecasts for Beijing. Get detailed insights into the weather in Beijing and surrounding areas for the next 15 to 30 days, including temperature, air quality, precipitation, wind speed, air pressure, and UV intensity", "type": "structure_web_info", "original": null, "query": null, "source": "2345 Weather"}, {"title": "15-day weather forecast for Beijing", "url": "https://m.tianqi.com/beijing/15/", "desc": "15-Day Beijing Weather Forecast Details:12/11 Today: Light Snow, -2 to 2°C12/12 Tomorrow: Cloudy turning to Light Snow, -2 to 2°C12/13 The Day After Tomorrow: Light Snow, -5 to 0°C12/14 Thursday: Light Snow, -5 to -1°C12/15 Friday: Overcast turning to Cloudy, -10 to -2°C12/16 Saturday: Clear, -10 to -3°C12/17 ...", "type": "structure_web_info", "original": null, "query": null, "source": "Weather"}, {"title": "Beijing Weather", "url": "https://t.8684.com/beijing_beijing", "desc": "Beijing weather forecast for 15 days, Beijing weather forecast, Beijing weather forecast for 1 week, Beijing weather forecast for 15 days, Beijing weather forecast for this week, Beijing weather forecast for next week, Beijing weather forecast for 15 days, Beijing weather forecast for 10 days", "type": "structure_web_info", "original": null, "query": null, "source": "8684 Weather"}], "requestId": null, "failed": false}'}}], 'type': 'tool_calls'}, 'usage': None, 'id': 'step_f923bd08-1e22-40d9-bf54-373b21fde378', 'object': 'thread.run.step', 'created_at': 1714460228960, 'assistant_id': 'asst_9453fe59-d6eb-498e-aeca-9abecd492e51', 'thread_id': 'thread_28f0b00b-d825-48f5-bb27-f3b171a64d33', 'run_id': 'run_0f314675-06a4-4379-929c-d29cd351a446', 'type': 'tool_calls', 'status': 'in_progress', 'expired_at': None, 'cancelled_at': None, 'failed_at': None, 'completed_at': None, 'metadata': {}, 'request_id': '38fb88b8-196a-9919-8815-f7ed9aa0891f', 'status_code': 200, 'last_error': None}
thread.run.step.created
{'step_details': {'message_creation': {'message_id': 'message_93605cd7-fb74-468b-b6fb-4975cd253f8d'}, 'type': 'message_creation'}, 'usage': None, 'id': 'step_89e631c7-491a-4bff-b1f5-1298f88db531', 'object': 'thread.run.step', 'created_at': 1714460234236, 'assistant_id': 'asst_9453fe59-d6eb-498e-aeca-9abecd492e51', 'thread_id': 'thread_28f0b00b-d825-48f5-bb27-f3b171a64d33', 'run_id': 'run_0f314675-06a4-4379-929c-d29cd351a446', 'type': 'message_creation', 'status': 'in_progress', 'expired_at': None, 'cancelled_at': None, 'failed_at': None, 'completed_at': None, 'metadata': {}, 'request_id': '38fb88b8-196a-9919-8815-f7ed9aa0891f', 'status_code': 200, 'last_error': None}
thread.run.step.in_progress
{'step_details': {'message_creation': {'message_id': 'message_93605cd7-fb74-468b-b6fb-4975cd253f8d'}, 'type': 'message_creation'}, 'usage': None, 'id': 'step_89e631c7-491a-4bff-b1f5-1298f88db531', 'object': 'thread.run.step', 'created_at': 1714460234236, 'assistant_id': 'asst_9453fe59-d6eb-498e-aeca-9abecd492e51', 'thread_id': 'thread_28f0b00b-d825-48f5-bb27-f3b171a64d33', 'run_id': 'run_0f314675-06a4-4379-929c-d29cd351a446', 'type': 'message_creation', 'status': 'in_progress', 'expired_at': None, 'cancelled_at': None, 'failed_at': None, 'completed_at': None, 'metadata': {}, 'request_id': '38fb88b8-196a-9919-8815-f7ed9aa0891f', 'status_code': 200, 'last_error': None}
thread.message.created
{'content': [], 'id': 'message_93605cd7-fb74-468b-b6fb-4975cd253f8d', 'object': 'thread.message', 'created_at': 1714460234235, 'thread_id': 'thread_28f0b00b-d825-48f5-bb27-f3b171a64d33', 'incomplete_details': None, 'completed_at': None, 'incomplete_at': None, 'role': 'assistant', 'assistant_id': 'asst_9453fe59-d6eb-498e-aeca-9abecd492e51', 'run_id': 'run_0f314675-06a4-4379-929c-d29cd351a446', 'file_ids': [], 'metadata': {}, 'request_id': '38fb88b8-196a-9919-8815-f7ed9aa0891f', 'status_code': 200}
thread.message.in_progress
{'content': [], 'id': 'message_93605cd7-fb74-468b-b6fb-4975cd253f8d', 'object': 'thread.message', 'created_at': 1714460234235, 'thread_id': 'thread_28f0b00b-d825-48f5-bb27-f3b171a64d33', 'incomplete_details': None, 'completed_at': None, 'incomplete_at': None, 'role': 'assistant', 'assistant_id': 'asst_9453fe59-d6eb-498e-aeca-9abecd492e51', 'run_id': 'run_0f314675-06a4-4379-929c-d29cd351a446', 'file_ids': [], 'metadata': {}, 'request_id': '38fb88b8-196a-9919-8815-f7ed9aa0891f', 'status_code': 200}
thread.message.delta
{'delta': {'content': {'text': {'annotations': [], 'value': 'The weather'}, 'type': 'text'}, 'role': 'assistant'}, 'id': 'message_93605cd7-fb74-468b-b6fb-4975cd253f8d', 'object': 'thread.message.delta', 'request_id': '38fb88b8-196a-9919-8815-f7ed9aa0891f', 'status_code': 200}
thread.message.delta
{'delta': {'content': {'text': {'annotations': [], 'value': 'in Beijing today is'}, 'type': 'text'}, 'role': 'assistant'}, 'id': 'message_93605cd7-fb74-468b-b6fb-4975cd253f8d', 'object': 'thread.message.delta', 'request_id': '38fb88b8-196a-9919-8815-f7ed9aa0891f', 'status_code': 200}
thread.message.delta
{'delta': {'content': {'text': {'annotations': [], 'value': 'clear, with temperature around 24'}, 'type': 'text'}, 'role': 'assistant'}, 'id': 'message_93605cd7-fb74-468b-b6fb-4975cd253f8d', 'object': 'thread.message.delta', 'request_id': '38fb88b8-196a-9919-8815-f7ed9aa0891f', 'status_code': 200}
thread.message.delta
{'delta': {'content': {'text': {'annotations': [], 'value': 'degrees Celsius and a feels-like temperature of 23'}, 'type': 'text'}, 'role': 'assistant'}, 'id': 'message_93605cd7-fb74-468b-b6fb-4975cd253f8d', 'object': 'thread.message.delta', 'request_id': '38fb88b8-196a-9919-8815-f7ed9aa0891f', 'status_code': 200}
thread.message.delta
{'delta': {'content': {'text': {'annotations': [], 'value': 'degrees. There is a gentle west wind at level 1,'}, 'type': 'text'}, 'role': 'assistant'}, 'id': 'message_93605cd7-fb74-468b-b6fb-4975cd253f8d', 'object': 'thread.message.delta', 'request_id': '38fb88b8-196a-9919-8815-f7ed9aa0891f', 'status_code': 200}
thread.message.delta
{'delta': {'content': {'text': {'annotations': [], 'value': 'making the weather quite comfortable. However, I've also found more'}, 'type': 'text'}, 'role': 'assistant'}, 'id': 'message_93605cd7-fb74-468b-b6fb-4975cd253f8d', 'object': 'thread.message.delta', 'request_id': '38fb88b8-196a-9919-8815-f7ed9aa0891f', 'status_code': 200}
thread.message.delta
{'delta': {'content': {'text': {'annotations': [], 'value': 'detailed information released by the Beijing Meteorological Service, stating that'}, 'type': 'text'}, 'role': 'assistant'}, 'id': 'message_93605cd7-fb74-468b-b6fb-4975cd253f8d', 'object': 'thread.message.delta', 'request_id': '38fb88b8-196a-9919-8815-f7ed9aa0891f', 'status_code': 200}
thread.message.delta
{'delta': {'content': {'text': {'annotations': [], 'value': 'the maximum temperature during the day will be about 5 degrees Celsius,'}, 'type': 'text'}, 'role': 'assistant'}, 'id': 'message_93605cd7-fb74-468b-b6fb-4975cd253f8d', 'object': 'thread.message.delta', 'request_id': '38fb88b8-196a-9919-8815-f7ed9aa0891f', 'status_code': 200}
thread.message.delta
{'delta': {'content': {'text': {'annotations': [], 'value': 'with mostly clear skies alternating with some clouds. There will be'}, 'type': 'text'}, 'role': 'assistant'}, 'id': 'message_93605cd7-fb74-468b-b6fb-4975cd253f8d', 'object': 'thread.message.delta', 'request_id': '38fb88b8-196a-9919-8815-f7ed9aa0891f', 'status_code': 200}
thread.message.delta
{'delta': {'content': {'text': {'annotations': [], 'value': 'a northerly wind at level 3, with gusts potentially'}, 'type': 'text'}, 'role': 'assistant'}, 'id': 'message_93605cd7-fb74-468b-b6fb-4975cd253f8d', 'object': 'thread.message.delta', 'request_id': '38fb88b8-196a-9919-8815-f7ed9aa0891f', 'status_code': 200}
thread.message.delta
{'delta': {'content': {'text': {'annotations': [], 'value': 'reaching up to level 5. The minimum temperature at night will drop'}, 'type': 'text'}, 'role': 'assistant'}, 'id': 'message_93605cd7-fb74-468b-b6fb-4975cd253f8d', 'object': 'thread.message.delta', 'request_id': '38fb88b8-196a-9919-8815-f7ed9aa0891f', 'status_code': 200}
thread.message.delta
{'delta': {'content': {'text': {'annotations': [], 'value': 'to 5 degrees Celsius, remaining clear,'}, 'type': 'text'}, 'role': 'assistant'}, 'id': 'message_93605cd7-fb74-468b-b6fb-4975cd253f8d', 'object': 'thread.message.delta', 'request_id': '38fb88b8-196a-9919-8815-f7ed9aa0891f', 'status_code': 200}
thread.message.delta
{'delta': {'content': {'text': {'annotations': [], 'value': 'with the wind direction shifting to northerly,'}, 'type': 'text'}, 'role': 'assistant'}, 'id': 'message_93605cd7-fb74-468b-b6fb-4975cd253f8d', 'object': 'thread.message.delta', 'request_id': '38fb88b8-196a-9919-8815-f7ed9aa0891f', 'status_code': 200}
thread.message.delta
{'delta': {'content': {'text': {'annotations': [], 'value': 'and wind strength changing from level 2 to level 3. '}, 'type': 'text'}, 'role': 'assistant'}, 'id': 'message_93605cd7-fb74-468b-b6fb-4975cd253f8d', 'object': 'thread.message.delta', 'request_id': '38fb88b8-196a-9919-8815-f7ed9aa0891f', 'status_code': 200}
thread.message.delta
{'delta': {'content': {'text': {'annotations': [], 'value': 'Please adjust your attire according to the real-time weather conditions and'}, 'type': 'text'}, 'role': 'assistant'}, 'id': 'message_93605cd7-fb74-468b-b6fb-4975cd253f8d', 'object': 'thread.message.delta', 'request_id': '38fb88b8-196a-9919-8815-f7ed9aa0891f', 'status_code': 200}
thread.message.delta
{'delta': {'content': {'text': {'annotations': [], 'value': 'make sure to stay warm. '}, 'type': 'text'}, 'role': 'assistant'}, 'id': 'message_93605cd7-fb74-468b-b6fb-4975cd253f8d', 'object': 'thread.message.delta', 'request_id': '38fb88b8-196a-9919-8815-f7ed9aa0891f', 'status_code': 200}
thread.message.delta
{'delta': {'content': {'text': {'annotations': [], 'value': ''}, 'type': 'text'}, 'role': 'assistant'}, 'id': 'message_93605cd7-fb74-468b-b6fb-4975cd253f8d', 'object': 'thread.message.delta', 'request_id': '38fb88b8-196a-9919-8815-f7ed9aa0891f', 'status_code': 200}
thread.message.completed
{'content': [{'text': {'annotations': [], 'value': 'The weather in Beijing today is clear, with temperatures around 24 degrees Celsius and a feels-like temperature of 23 degrees. There is a gentle west wind at level 1, making the weather quite comfortable. However, I've also found more detailed information released by the Beijing Meteorological Service, stating that the maximum temperature during the day will be about 5 degrees Celsius, with mostly clear skies alternating with some clouds. There will be a northerly wind at level 3, with gusts potentially reaching up to level 5. The minimum temperature at night will drop to 5 degrees Celsius, remaining clear, with the wind direction shifting to northerly, and wind strength changing from level 2 to level 3. Please adjust your attire according to the real-time weather conditions and make sure to stay warm. '}, 'type': 'text'}], 'id': 'message_93605cd7-fb74-468b-b6fb-4975cd253f8d', 'object': 'thread.message', 'created_at': 1714460234235, 'thread_id': 'thread_28f0b00b-d825-48f5-bb27-f3b171a64d33', 'incomplete_details': None, 'completed_at': 1714460245637, 'incomplete_at': None, 'role': 'assistant', 'assistant_id': 'asst_9453fe59-d6eb-498e-aeca-9abecd492e51', 'run_id': 'run_0f314675-06a4-4379-929c-d29cd351a446', 'file_ids': [], 'metadata': {}, 'request_id': '38fb88b8-196a-9919-8815-f7ed9aa0891f', 'status_code': 200}
thread.run.step.completed
{'step_details': {'message_creation': {'message_id': 'message_93605cd7-fb74-468b-b6fb-4975cd253f8d'}, 'type': 'message_creation'}, 'usage': None, 'id': 'step_89e631c7-491a-4bff-b1f5-1298f88db531', 'object': 'thread.run.step', 'created_at': 1714460234236, 'assistant_id': 'asst_9453fe59-d6eb-498e-aeca-9abecd492e51', 'thread_id': 'thread_28f0b00b-d825-48f5-bb27-f3b171a64d33', 'run_id': 'run_0f314675-06a4-4379-929c-d29cd351a446', 'type': 'message_creation', 'status': 'completed', 'expired_at': None, 'cancelled_at': None, 'failed_at': None, 'completed_at': 1714460245637, 'metadata': {}, 'request_id': '38fb88b8-196a-9919-8815-f7ed9aa0891f', 'status_code': 200, 'last_error': None}
thread.run.completed
{'tools': [{'type': 'quark_search'}], 'required_action': None, 'id': 'run_0f314675-06a4-4379-929c-d29cd351a446', 'object': 'thread.run', 'created_at': 1714460227904, 'thread_id': 'thread_28f0b00b-d825-48f5-bb27-f3b171a64d33', 'assistant_id': 'asst_9453fe59-d6eb-498e-aeca-9abecd492e51', 'status': 'completed', 'last_error': None, 'expires_at': None, 'started_at': None, 'cancelled_at': None, 'failed_at': None, 'completed_at': None, 'model': 'qwen-max', 'instructions': 'You are a helpful assistant. When asked a question, use tools wherever possible.', 'file_ids': [], 'metadata': {}, 'usage': {'input_tokens': 1865, 'output_tokens': 139, 'total_tokens': 2004}, 'temperature': None, 'top_p': None, 'top_k': None, 'max_tokens': None, 'truncation_strategy': None, 'request_id': '38fb88b8-196a-9919-8815-f7ed9aa0891f', 'status_code': 200}
Response parameters
Parameter | Type | Description |
status_code | int | The HTTP status code. A code of 200 indicates success and other codes indicate failure. |
id | str | The run ID, formatted as a UUID string. |
model | str | The name of the model used by the run. |
instructions | str | The instruction information of the assistant. |
metadata | object | The key-value pairs of matadata of the assistant. |
status | str | The status of the run. |
thread_id | str | The ID of the thread associated with the run. |
tools | List[Tool] | The tools used during the run. |
created_at | timestamp | The timestamp when the run was created. |
gmt_created | datetime | The time when the run was created. |
gmt_modified | datetime | The time when the run was modified. |
code | str | The error code returned upon request failure. This parameter is returned only when you use the SDK for Python. |
message | str | The error message returned upon request failure. This parameter is returned only when you use the SDK for Python. |
Create a thread and run tasks
HTTP
Sample code
Non-streaming
curl --location 'https://dashscope-intl.aliyuncs.com/api/v1/threads/runs' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--data '{
"assistant_id": "asst_ce66cfa8-b2f8-4e4c-8e17-2c335145be42",
"thread": {
"messages": [
{
"role": "user",
"content": "What is the weather in Singapore?"
}
]
}
}'
Streaming
curl --location 'https://dashscope-intl.aliyuncs.com/api/v1/threads/runs' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--data '{
"assistant_id": "asst_ce66cfa8-b2f8-4e4c-8e17-2c335145be42",
"thread": {
"messages": [
{
"role": "user",
"content": "Who are you?"
}
]
},
"stream": true
}'
Request parameters
Parameter | Description | Type | Required |
thread id | The ID of the thread to run. | str | Yes |
assistant id | The ID of the assistant to run. | str | Yes |
thread | The information about the thread. | dict | Yes |
stream | Specifies whether to enable the streaming output mode. | boolean | No |
temperature | Controls the diversity of the responses generated by the model. | float | No |
top_p | The probability threshold of the sampling method. | float | No |
top_k | The size of the candidate set for sampling. | integer | No |
Sample response
Non-streaming
{
"id": "run_99935dbd-e731-4bad-b450-60d9d6bf9a44",
"object": "thread.run",
"created_at": 1711519089921,
"thread_id": "thread_9157dfad-71fd-4add-b7a9-1afa452d2d67",
"assistant_id": "asst_ce66cfa8-b2f8-4e4c-8e17-2c335145be42",
"status": "in_progress",
"model": "qwen-max",
"instructions": "You are an intelligent assistant. You can use different tools based on user needs and then provide answers. Use tools when needed.",
"tools": [
{
"type": "text_to_image"
},
{
"type": "function",
"function": {
"name": "get_current_weather",
"description": "Get the current weather in a given location",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA"
},
"unit": {
"type": "string",
"enum": [
"celsius",
"fahrenheit"
]
}
},
"required": [
"location"
]
}
}
}
],
"metadata": {},
"request_id": "191ecdaa-7ef6-9e29-8572-4f89be05bc6c"
}
Streaming
event:thread.created
data:{"id":"thread_4a1e6bee-4e0a-4749-a0c8-f6db8bb7c4bb","object":"thread","created_at":1714448762315,"metadata":{},"request_id":"70673f3f-74b4-9e9a-90bf-de92c23c55b2"}
event:thread.run.created
data:{"id":"run_65adea5e-9086-4806-b733-bb0a7b53a459","object":"thread.run","created_at":1714448762335,"thread_id":"thread_4a1e6bee-4e0a-4749-a0c8-f6db8bb7c4bb","assistant_id":"asst_5378d83a-f612-4fc1-9034-915351d67d98","status":"queued","required_action":null,"last_error":null,"expires_at":null,"started_at":null,"cancelled_at":null,"failed_at":null,"completed_at":null,"model":"qwen-max","instructions":"You are an intelligent assistant. You can use different tools based on user needs and then provide answers. Use tools when needed.","tools":[{"type":"text_to_image"},{"type":"function","function":{"name":"get_current_weather","description":"Get the current weather in a given location","parameters":{"type":"object","properties":{"location":{"type":"string","description":"The city and state, e.g. San Francisco, CA"},"unit":{"type":"string","enum":["celsius","fahrenheit"]}},"required":["location"]}}}],"file_ids":[],"metadata":{},"usage":null,"temperature":null,"top_p":null,"top_k":null,"max_tokens":null,"truncation_strategy":null,"request_id":"70673f3f-74b4-9e9a-90bf-de92c23c55b2"}
event:thread.run.queued
data:{"id":"run_65adea5e-9086-4806-b733-bb0a7b53a459","object":"thread.run","created_at":1714448762335,"thread_id":"thread_4a1e6bee-4e0a-4749-a0c8-f6db8bb7c4bb","assistant_id":"asst_5378d83a-f612-4fc1-9034-915351d67d98","status":"queued","required_action":null,"last_error":null,"expires_at":null,"started_at":null,"cancelled_at":null,"failed_at":null,"completed_at":null,"model":"qwen-max","instructions":"You are an intelligent assistant. You can use different tools based on user needs and then provide answers. Use tools when needed.","tools":[{"type":"text_to_image"},{"type":"function","function":{"name":"get_current_weather","description":"Get the current weather in a given location","parameters":{"type":"object","properties":{"location":{"type":"string","description":"The city and state, e.g. San Francisco, CA"},"unit":{"type":"string","enum":["celsius","fahrenheit"]}},"required":["location"]}}}],"file_ids":[],"metadata":{},"usage":null,"temperature":null,"top_p":null,"top_k":null,"max_tokens":null,"truncation_strategy":null,"request_id":"70673f3f-74b4-9e9a-90bf-de92c23c55b2"}
event:thread.run.in_progress
data:{"id":"run_65adea5e-9086-4806-b733-bb0a7b53a459","object":"thread.run","created_at":1714448762335,"thread_id":"thread_4a1e6bee-4e0a-4749-a0c8-f6db8bb7c4bb","assistant_id":"asst_5378d83a-f612-4fc1-9034-915351d67d98","status":"in_progress","required_action":null,"last_error":null,"expires_at":null,"started_at":null,"cancelled_at":null,"failed_at":null,"completed_at":null,"model":"qwen-max","instructions":"You are an intelligent assistant. You can use different tools based on user needs and then provide answers. Use tools when needed.","tools":[{"type":"text_to_image"},{"type":"function","function":{"name":"get_current_weather","description":"Get the current weather in a given location","parameters":{"type":"object","properties":{"location":{"type":"string","description":"The city and state, e.g. San Francisco, CA"},"unit":{"type":"string","enum":["celsius","fahrenheit"]}},"required":["location"]}}}],"file_ids":[],"metadata":{},"usage":null,"temperature":null,"top_p":null,"top_k":null,"max_tokens":null,"truncation_strategy":null,"request_id":"70673f3f-74b4-9e9a-90bf-de92c23c55b2"}
event:thread.run.step.created
data:{"id":"step_15663219-fda6-4030-b35f-617712371f3b","object":"thread.run.step","created_at":1714448762933,"assistant_id":"asst_5378d83a-f612-4fc1-9034-915351d67d98","thread_id":"thread_4a1e6bee-4e0a-4749-a0c8-f6db8bb7c4bb","run_id":"run_65adea5e-9086-4806-b733-bb0a7b53a459","type":"message_creation","status":"in_progress","step_details":{"type":"message_creation","message_creation":{"message_id":"message_ae7fce4c-a14d-4420-820e-191e1c4996a2"}},"last_error":null,"expired_at":null,"cancelled_at":null,"failed_at":null,"completed_at":null,"metadata":{},"usage":null,"request_id":"70673f3f-74b4-9e9a-90bf-de92c23c55b2"}
event:thread.run.step.in_progress
data:{"id":"step_15663219-fda6-4030-b35f-617712371f3b","object":"thread.run.step","created_at":1714448762933,"assistant_id":"asst_5378d83a-f612-4fc1-9034-915351d67d98","thread_id":"thread_4a1e6bee-4e0a-4749-a0c8-f6db8bb7c4bb","run_id":"run_65adea5e-9086-4806-b733-bb0a7b53a459","type":"message_creation","status":"in_progress","step_details":{"type":"message_creation","message_creation":{"message_id":"message_ae7fce4c-a14d-4420-820e-191e1c4996a2"}},"last_error":null,"expired_at":null,"cancelled_at":null,"failed_at":null,"completed_at":null,"metadata":{},"usage":null,"request_id":"70673f3f-74b4-9e9a-90bf-de92c23c55b2"}
event:thread.message.created
data:{"id":"message_ae7fce4c-a14d-4420-820e-191e1c4996a2","object":"thread.message","created_at":1714448762933,"thread_id":"thread_4a1e6bee-4e0a-4749-a0c8-f6db8bb7c4bb","incomplete_details":null,"completed_at":null,"incomplete_at":null,"role":"assistant","content":[],"assistant_id":"asst_5378d83a-f612-4fc1-9034-915351d67d98","run_id":"run_65adea5e-9086-4806-b733-bb0a7b53a459","file_ids":[],"metadata":{},"request_id":"70673f3f-74b4-9e9a-90bf-de92c23c55b2"}
event:thread.message.in_progress
data:{"id":"message_ae7fce4c-a14d-4420-820e-191e1c4996a2","object":"thread.message","created_at":1714448762933,"thread_id":"thread_4a1e6bee-4e0a-4749-a0c8-f6db8bb7c4bb","incomplete_details":null,"completed_at":null,"incomplete_at":null,"role":"assistant","content":[],"assistant_id":"asst_5378d83a-f612-4fc1-9034-915351d67d98","run_id":"run_65adea5e-9086-4806-b733-bb0a7b53a459","file_ids":[],"metadata":{},"request_id":"70673f3f-74b4-9e9a-90bf-de92c23c55b2"}
event:thread.message.delta
data:{"id":"message_ae7fce4c-a14d-4420-820e-191e1c4996a2","object":"thread.message.delta","delta":{"role":"assistant","content":[{"type":"text","text":{"value":"I am","annotations":[]}}],"file_ids":[]},"request_id":"70673f3f-74b4-9e9a-90bf-de92c23c55b2"}
event:thread.message.delta
data:{"id":"message_ae7fce4c-a14d-4420-820e-191e1c4996a2","object":"thread.message.delta","delta":{"role":"assistant","content":[{"type":"text","text":{"value":"your","annotations":[]}}],"file_ids":[]},"request_id":"70673f3f-74b4-9e9a-90bf-de92c23c55b2"}
event:thread.message.delta
data:{"id":"message_ae7fce4c-a14d-4420-820e-191e1c4996a2","object":"thread.message.delta","delta":{"role":"assistant","content":[{"type":"text","text":{"value":"intelligent","annotations":[]}}],"file_ids":[]},"request_id":"70673f3f-74b4-9e9a-90bf-de92c23c55b2"}
event:thread.message.delta
data:{"id":"message_ae7fce4c-a14d-4420-820e-191e1c4996a2","object":"thread.message.delta","delta":{"role":"assistant","content":[{"type":"text","text":{"value":"assistant, here to help you","annotations":[]}}],"file_ids":[]},"request_id":"70673f3f-74b4-9e9a-90bf-de92c23c55b2"}
event:thread.message.delta
data:{"id":"message_ae7fce4c-a14d-4420-820e-191e1c4996a2","object":"thread.message.delta","delta":{"role":"assistant","content":[{"type":"text","text":{"value":"answer questions, provide information, complete tasks","annotations":[]}}],"file_ids":[]},"request_id":"70673f3f-74b4-9e9a-90bf-de92c23c55b2"}
event:thread.message.delta
data:{"id":"message_ae7fce4c-a14d-4420-820e-191e1c4996a2","object":"thread.message.delta","delta":{"role":"assistant","content":[{"type":"text","text":{"value":"and more. Just let me know how I can help,","annotations":[]}}],"file_ids":[]},"request_id":"70673f3f-74b4-9e9a-90bf-de92c23c55b2"}
event:thread.message.delta
data:{"id":"message_ae7fce4c-a14d-4420-820e-191e1c4996a2","object":"thread.message.delta","delta":{"role":"assistant","content":[{"type":"text","text":{"value":"and I will do my best to serve you. Whether you want to look up information,","annotations":[]}}],"file_ids":[]},"request_id":"70673f3f-74b4-9e9a-90bf-de92c23c55b2"}
event:thread.message.delta
data:{"id":"message_ae7fce4c-a14d-4420-820e-191e1c4996a2","object":"thread.message.delta","delta":{"role":"assistant","content":[{"type":"text","text":{"value":"make plans, learn new knowledge","annotations":[]}}],"file_ids":[]},"request_id":"70673f3f-74b4-9e9a-90bf-de92c23c55b2"}
event:thread.message.delta
data:{"id":"message_ae7fce4c-a14d-4420-820e-191e1c4996a2","object":"thread.message.delta","delta":{"role":"assistant","content":[{"type":"text","text":{"value":", or be entertained, I'm here for you","annotations":[]}}],"file_ids":[]},"request_id":"70673f3f-74b4-9e9a-90bf-de92c23c55b2"}
event:thread.message.delta
data:{"id":"message_ae7fce4c-a14d-4420-820e-191e1c4996a2","object":"thread.message.delta","delta":{"role":"assistant","content":[{"type":"text","text":{"value":". How can I assist you today?","annotations":[]}}],"file_ids":[]},"request_id":"70673f3f-74b4-9e9a-90bf-de92c23c55b2"}
event:thread.message.delta
data:{"id":"message_ae7fce4c-a14d-4420-820e-191e1c4996a2","object":"thread.message.delta","delta":{"role":"assistant","content":[{"type":"text","text":{"value":"","annotations":[]}}],"file_ids":[]},"request_id":"70673f3f-74b4-9e9a-90bf-de92c23c55b2"}
event:thread.message.completed
data:{"id":"message_ae7fce4c-a14d-4420-820e-191e1c4996a2","object":"thread.message","created_at":1714448762933,"thread_id":"thread_4a1e6bee-4e0a-4749-a0c8-f6db8bb7c4bb","incomplete_details":null,"completed_at":1714448773999,"incomplete_at":null,"role":"assistant","content":[{"type":"text","text":{"value":"I am your intelligent assistant, here to help you answer questions, provide information, complete tasks, and more. Just let me know how I can help, and I will do my best to serve you. Whether you want to look up information, make plans, learn new knowledge, or be entertained, I'm here for you. How can I assist you today?","annotations":[]}}],"assistant_id":"asst_5378d83a-f612-4fc1-9034-915351d67d98","run_id":"run_65adea5e-9086-4806-b733-bb0a7b53a459","file_ids":[],"metadata":{},"request_id":"70673f3f-74b4-9e9a-90bf-de92c23c55b2"}
event:thread.run.step.completed
data:{"id":"step_15663219-fda6-4030-b35f-617712371f3b","object":"thread.run.step","created_at":1714448762933,"assistant_id":"asst_5378d83a-f612-4fc1-9034-915351d67d98","thread_id":"thread_4a1e6bee-4e0a-4749-a0c8-f6db8bb7c4bb","run_id":"run_65adea5e-9086-4806-b733-bb0a7b53a459","type":"message_creation","status":"completed","step_details":{"type":"message_creation","message_creation":{"message_id":"message_ae7fce4c-a14d-4420-820e-191e1c4996a2"}},"last_error":null,"expired_at":null,"cancelled_at":null,"failed_at":null,"completed_at":1714448773999,"metadata":{},"usage":null,"request_id":"70673f3f-74b4-9e9a-90bf-de92c23c55b2"}
event:thread.run.completed
data:{"id":"run_65adea5e-9086-4806-b733-bb0a7b53a459","object":"thread.run","created_at":1714448762335,"thread_id":"thread_4a1e6bee-4e0a-4749-a0c8-f6db8bb7c4bb","assistant_id":"asst_5378d83a-f612-4fc1-9034-915351d67d98","status":"completed","required_action":null,"last_error":null,"expires_at":null,"started_at":null,"cancelled_at":null,"failed_at":null,"completed_at":null,"model":"qwen-max","instructions":"You are an intelligent assistant. You can use different tools based on user needs and then provide answers. Use tools when needed.","tools":[{"type":"text_to_image"},{"type":"function","function":{"name":"get_current_weather","description":"Get the current weather in a given location","parameters":{"type":"object","properties":{"location":{"type":"string","description":"The city and state, e.g. San Francisco, CA"},"unit":{"type":"string","enum":["celsius","fahrenheit"]}},"required":["location"]}}}],"file_ids":[],"metadata":{},"usage":{"input_tokens":410,"output_tokens":56,"total_tokens":466},"temperature":null,"top_p":null,"top_k":null,"max_tokens":null,"truncation_strategy":null,"request_id":"70673f3f-74b4-9e9a-90bf-de92c23c55b2"}
event:done
data:[DONE]
Response parameters
The created run class, including the following parameters:
id: The run ID.
thread_id: The thread ID.
assistant_id: The assistant ID.
request_id: The request ID.
SDK
Sample code
from dashscope import Runs
import dashscope
dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'
run = Runs.create('thread_id',
assistant_id='assistant_id',
model='the_model_to_use',
instructions='Instructions',
additional_instructions='additional_instructions',
tools=['list_of_tool_to_use'],
metadata={'key': 'value'})
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.Run;
import com.alibaba.dashscope.threads.runs.RunParam;
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();
RunParam runParam = RunParam.builder().assistantId("assistantId").build();
Run run = runs.create("threadId", runParam);
}
}
Request parameters
Parameter | Type | Default value | Description |
thread_id | str | - | The ID of the thread on which to create the run. |
assistant_id | str | - | The assistant ID. |
model | str | - | The model that is used. |
instructions | str | None | The prompt of this run. |
additional_instructions | str | None | The additional instruction of this run. |
tools | List[Dict] | [] | The tools that are used by the assistant. |
metadata | Dict | None | The metadata of the assistant. |
Sample response
The result is a run object, with the following JSON content:
{
"account_id": "YOUR_AK",
"assistant_id": "asst_8eeaedde-3f8b-41d2-9433-0e88a6042ecb",
"created_at": 1711347311426,
"file_ids": [],
"id": "run_f2c663e6-69f9-4494-9017-acf788db5a17",
"instructions": "You are a helpful assistant. When asked a question, use tools wherever possible.",
"metadata": {},
"model": "qwen-max-allinone",
"object": "thread.run",
"request_id": "53561cd0-350c-918d-b3f7-716a0e41bcfd",
"status": "in_progress",
"status_code": 200,
"thread_id": "thread_45ca9a78-2b1f-4172-b4cf-cf8c748c1c32",
"tools": [
{
"type": "search"
},
{
"function": {
"description": "Add to number",
"name": "big_add",
"parameters": {
"properties": {
"left": {
"description": "The left operator",
"type": "integer"
},
"right": {
"description": "The right operator.",
"type": "integer"
}
},
"required": [
"left",
"right"
],
"type": "object"
}
},
"type": "function"
}
]
}
List run tasks
HTTP
Sample code
curl --location 'https://dashscope-intl.aliyuncs.com/api/v1/threads/thread_cc2a3e9d-436b-482b-91c5-377e0f376506/runs?limit=20&order=asc' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY"
Request parameters
Parameter | Description | Type | Required |
thread id | The ID of the thread to which the runs belong. | str | Yes |
limit | The maximum number of runs that can be returned. | int | No |
order | The ascending or descending order in which the messages are sorted based on the creation time. Default value: desc. | str | No |
Sample response
{
"object": "list",
"data": [
{
"id": "run_3de634fa-75d4-4370-adcf-92ba2a60c396",
"object": "thread.run",
"created_at": 1711517598169,
"thread_id": "thread_cc2a3e9d-436b-482b-91c5-377e0f376506",
"assistant_id": "asst_46e95014-ccac-435d-b884-c97ac44a94d9",
"status": "completed",
"required_action": {},
"last_error": {},
"expires_at": 0,
"started_at": 0,
"cancelled_at": 0,
"failed_at": 0,
"completed_at": 0,
"model": "qwen-max",
"instructions": "You are an intelligent assistant. You can use different tools based on user needs and then provide answers. Use tools when needed.",
"tools": [
{
"type": "search"
},
{
"type": "text_to_image"
}
],
"metadata": {},
"usage": {
"prompt_tokens": 66,
"completion_tokens": 9,
"total_tokens": 75
}
}
],
"first_id": "run_3de634fa-75d4-4370-adcf-92ba2a60c396",
"last_id": "run_3de634fa-75d4-4370-adcf-92ba2a60c396",
"has_more": false,
"request_id": "ff3d2aea-555c-9825-80ca-24029a636641"
}
Response parameters
Returns a list run class, including the following parameters.
A list of runs.
SDK
Sample code
from dashscope import Runs
import dashscope
dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'
runs = Runs.list('thread_id',
limit=1,
order='desc',
after='',
before='')
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.Run;
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();
GeneralListParam listRuns = GeneralListParam.builder().build();
ListResult<Run> run = runs.list("threadId", listRuns);
}
}
Request parameters
Parameter | Type | Description |
thread_id | str | The ID of the thread to which the runs belong. |
limit | str | |
order | str | |
after | str | |
before | str | |
workspace | str | The workspace ID. |
api_key | str | The API key. You can set it as an environment variable. |
Response parameters
Parameter | Type | Description |
has_more | bool | |
last_id | str | |
first_id | str | |
data | list[Run] | The list of run objects. |
List run steps
HTTP
Sample code
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"
Request parameters
Parameter | Description | Type | Required |
thread id | The ID of the thread to which the run belongs. | str | Yes |
run id | The ID of the run to which the steps belong to. | str | Yes |
limit | The maximum number of steps that can be returned. | int | No |
order | The ascending or descending order in which the messages are sorted based on the creation time. Default value: desc. | str | No |
Sample response
{
"object": "list",
"data": [
{
"id": "step_4db180b5-d44a-4b12-9390-4307c6cb87a5",
"object": "thread.run.step",
"created_at": 1711517599333,
"assistant_id": "asst_46e95014-ccac-435d-b884-c97ac44a94d9",
"thread_id": "thread_cc2a3e9d-436b-482b-91c5-377e0f376506",
"run_id": "run_3de634fa-75d4-4370-adcf-92ba2a60c396",
"type": "message_creation",
"status": "completed",
"step_details": {
"type": "message_creation",
"message_creation": {
"message_id": "message_75c67937-a829-4741-ae83-6839cae81269"
}
},
"last_error": {
"code": "",
"message": ""
},
"expires_at": 0,
"started_at": 0,
"cancelled_at": -1,
"failed_at": -1,
"completed_at": -1,
"metadata": {},
"usage": {}
}
],
"first_id": "step_4db180b5-d44a-4b12-9390-4307c6cb87a5",
"last_id": "step_4db180b5-d44a-4b12-9390-4307c6cb87a5",
"has_more": false,
"request_id": "df979778-7c6a-9f45-b7da-758ae00d1e19"
}
Response parameters
Returns a list of run step class, including the following parameters:
A list run step class.
request_id: The request ID.
SDK
Sample code
from dashscope import Steps
import dashscope
dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'
steps = Steps.list('run_id',
thread_id='thread_id',
limit='')
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();
GeneralListParam listSteps = GeneralListParam.builder().build();
ListResult<RunStep> run = runs.listSteps("threadId", "runId", listSteps);
}
}
Request parameters
Parameter | Type | Description |
run_id | str | The ID of the run that the run step belongs. |
thread_id | str | The ID of the thread that the run belongs. |
limit | str | |
order | ||
after | ||
before | ||
workspace | str | The workspace ID. |
api_key | str | The API key. You can set it as an environment variable. |
Response parameters
Parameter | Type | Description |
has_more | bool | |
last_id | str | |
first_id | str | |
data | list[Step] | The list of run steps. |
Retrieve a run task
HTTP
Sample code
curl --location 'https://dashscope-intl.aliyuncs.com/api/v1/threads/thread_cc2a3e9d-436b-482b-91c5-377e0f376506/runs/run_3de634fa-75d4-4370-adcf-92ba2a60c396' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY"
Request parameters
Parameter | Description | Type | Required |
thread id | The ID of the thread to which the run belongs. | str | Yes |
run_id | The ID of the run to be retrieved. | str | Yes |
Sample response
{
"id": "run_3de634fa-75d4-4370-adcf-92ba2a60c396",
"object": "thread.run",
"created_at": 1711517598169,
"thread_id": "thread_cc2a3e9d-436b-482b-91c5-377e0f376506",
"assistant_id": "asst_46e95014-ccac-435d-b884-c97ac44a94d9",
"status": "completed",
"required_action": {},
"last_error": {},
"expires_at": 0,
"started_at": 0,
"cancelled_at": 0,
"failed_at": 0,
"completed_at": 0,
"model": "qwen-max",
"instructions": "You are an intelligent assistant. You can use different tools based on user needs and then provide answers. Use tools when needed.",
"tools": [
{
"type": "search"
},
{
"type": "text_to_image"
}
],
"metadata": {},
"usage": {
"prompt_tokens": 66,
"completion_tokens": 9,
"total_tokens": 75
},
"request_id": "05c5f4ea-5e6b-9901-9849-7a0943a0db43"
}
Response parameters
Returns the retrieved run class, including the following parameters:
id: The run ID.
thread_id: The thread ID.
assistant_id: The assistant ID.
request_id: The request ID.
SDK
Sample code
from dashscope import Runs
import dashscope
dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'
run = Runs.retrieve('run_id',
thread_id='thread_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.Run;
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();
Run run```html
= runs.retrieve("threadId", "runId");
}
}
Request parameters
Parameter | Type | Description |
run_id | str | The ID of the run to retrieve. |
thread_id | str | The ID of the thread to which the run belongs. |
workspace | str | The workspace ID. |
api_key | str | The API key. You can set it as an environment variable. |
Response parameters
See the response parameters of the Create a run task section.
Retrieve run steps
HTTP
Sample code
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"
Request parameters
Parameter | Description | Type | Required |
thread id | The ID of the thread to which the run belongs. | str | Yes |
run_id | The ID of the run to which the step belongs. | str | Yes |
step_id | The ID of the step to retrieve. | str | Yes |
* | Other optional request parameters. | str | No |
Sample response
{
"id": "step_4db180b5-d44a-4b12-9390-4307c6cb87a5",
"object": "thread.run.step",
"created_at": 1711517599333,
"assistant_id": "asst_46e95014-ccac-435d-b884-c97ac44a94d9",
"thread_id": "thread_cc2a3e9d-436b-482b-91c5-377e0f376506",
"run_id": "run_3de634fa-75d4-4370-adcf-92ba2a60c396",
"type": "message_creation",
"status": "completed",
"step_details": {
"type": "message_creation",
"message_creation": {
"message_id": "message_75c67937-a829-4741-ae83-6839cae81269"
}
},
"last_error": {
"code": "",
"message": ""
},
"expires_at": 0,
"started_at": 0,
"cancelled_at": -1,
"failed_at": -1,
"completed_at": -1,
"metadata": {},
"usage": {},
"request_id": "938643a3-d56d-966f-8c17-2cb09772475e"
}
Response parameters
Returns a run step class, including the following parameters:
id: The step ID.
request_id: The request ID.
SDK
Sample code
from dashscope import Steps
import dashscope
dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'
step = Steps.retrieve('step_id',
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();
RunStep step = runs.retrieveStep("threadId", "runId", "stepId");
}
}
Request parameters
Parameter | Type | Description |
step_id | str | The ID of the run step to retrieve. |
run_id | str | The ID of the run that the run step belongs. |
thread_id | str | The ID of the thread to which the run belongs. |
workspace | str | The workspace ID. |
api_key | str | The API key. You can set it as an environment variable. |
Sample response
{
"assistant_id": "asst_1",
"cancelled_at": null,
"completed_at": 1709866473,
"created_at": 1709866472,
"expires_at": null,
"failed_at": null,
"id": "step_1",
"last_error": null,
"object": "thread.run.step",
"run_id": "run_1",
"status": "completed",
"step_details": {
"message_creation": {
"message_id": "msg_1"
},
"type": "message_creation"
},
"thread_id": "thread_1",
"type": "message_creation",
"usage": {
"completion_tokens": 25,
"prompt_tokens": 809,
"total_tokens": 834
}
}
Response parameters
Parameter | Type | Description |
id | str | The step ID. |
assistant_id | str | The ID of the assistant associated with the run step. |
run_id | str | The ID of the run that the run step belongs. |
thread_id | str | The ID of the thread to which the run belongs. |
step_details | Dict | The details of the run step. |
created_at | timestamp | The timestamp when the assistant was created. |
gmt_created | datetime | The time then the run step was created. |
gmt_modified | datetime | The time when the run step was modified. |
code | str | The error code returned in case of a failed request. This parameter is returned only when you use Python. |
message | str | The error message returned in case of a failed request. This parameter is returned only when you use Python. |
Modify a run task
HTTP
Sample code
curl --location 'https://dashscope-intl.aliyuncs.com/api/v1/threads/thread_cc2a3e9d-436b-482b-91c5-377e0f376506/runs/run_3de634fa-75d4-4370-adcf-92ba2a60c396' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--data '{
"metadata": {
"user": "abc123"
}
}'
Request parameters
Parameter | Description | Type | Required |
thread_id | The ID of the thread to which the run belongs. | str | Yes |
run_id | The ID of the run to be modified. | str | Yes |
* | Other optional request parameters. | str | No |
Sample response
{
"id": "run_3de634fa-75d4-4370-adcf-92ba2a60c396",
"object": "thread.run",
"created_at": 1711517598169,
"thread_id": "thread_cc2a3e9d-436b-482b-91c5-377e0f376506",
"assistant_id": "asst_46e95014-ccac-435d-b884-c97ac44a94d9",
"status": "completed",
"required_action": {},
"last_error": {},
"expires_at": 0,
"started_at": 0,
"cancelled_at": 0,
"failed_at": 0,
"completed_at": 0,
"model": "qwen-max",
"instructions": "You are an intelligent assistant. You can use different tools based on user needs and then provide answers. Use tools when needed.",
"tools": [
{
"type": "search"
},
{
"type": "text_to_image"
}
],
"metadata": {
"user": "abc123"
},
"usage": {
"prompt_tokens": 66,
"completion_tokens": 9,
"total_tokens": 75
},
"request_id": "bb6a5c5c-146f-95b8-bafa-e6c467e4f2d3"
}
Response parameters
Returns the modified run class, including the following parameters:
id: The run ID.
request_id: The request ID.
SDK
Sample code
from dashscope import Runs
import dashscope
dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'
run = Runs.update('run_id',
thread_id='thread_id',
metadata={'newkey': 'newvalue'})
import java.util.HashMap;
import java.util.Map;
import com.alibaba.dashscope.common.UpdateMetadataParam;
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.Run;
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();
Map<String, String> metadata = new HashMap<>();
metadata.put("key", "value");
UpdateMetadataParam updateParam = UpdateMetadataParam.builder().metadata(metadata).build();
Run run = runs.update("threadId", "runId", updateParam);
}
}
Request parameters
Parameter | Type | Description |
run_id | str | The ID of the run to modify. |
thread_id | str | The ID of the thread to which the run belongs. |
metadata | Dict | The metadata of the assistant. |
workspace | str | The workspace ID. |
api_key | str | The API key. You can set it as an environment variable. |
Response parameters
See the response parameters of the Create a run task section.
Submit tool outputs and continue the run
HTTP
Sample code
When using function calling, you need to submit intermediate function results to the run and change the run status from require_action
to normal
. The value of required_action.type
should be submit_tool_outputs
.
Non-streaming
curl --location 'https://dashscope-intl.aliyuncs.com/api/v1/threads/thread_9157dfad-71fd-4add-b7a9-1afa452d2d67/runs/run_99935dbd-e731-4bad-b450-60d9d6bf9a44/submit_tool_outputs' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--data '{
"tool_outputs": [
{
"tool_call_id": "",
"output": "rain"
}
]
}'
Streaming
curl --location 'https://dashscope-intl.aliyuncs.com/api/v1/threads/thread_9157dfad-71fd-4add-b7a9-1afa452d2d67/runs/run_99935dbd-e731-4bad-b450-60d9d6bf9a44/submit_tool_outputs' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--data '{
"tool_outputs": [
{
"tool_call_id": "",
"output": "rain"
}
],
"stream": true
}'
Request parameters
Parameter | Description | Type | Required |
thread_id | The ID of the thread to which the run belongs. | str | Yes |
run_id | The ID of the run. | str | Yes |
tool_outputs | The results of tools to be submitted. | array | Yes |
stream | Specifies whether to enable the streaming output mode. | boolean | No |
Sample response
Non-streaming
{
"id": "run_99935dbd-e731-4bad-b450-60d9d6bf9a44",
"object": "thread.run",
"created_at": 1711519089921,
"thread_id": "thread_9157dfad-71fd-4add-b7a9-1afa452d2d67",
"assistant_id": "asst_ce66cfa8-b2f8-4e4c-8e17-2c335145be42",
"status": "in_progress",
"required_action": {
"type": "submit_tool_outputs",
"submit_tool_outputs": {
"tool_calls": [
{
"function": {
"name": "get_current_weather",
"arguments": "{\"location\": \"Singapore\"}"
},
"id": "",
"type": "function"
}
]
}
},
"last_error": {},
"expires_at": 0,
"started_at": 0,
"cancelled_at": 0,
"failed_at": 0,
"completed_at": 0,
"model": "qwen-max",
"instructions": "You are an intelligent assistant. You can use different tools based on user needs and then provide answers. Use tools when needed.",
"tools": [
{
"type": "text_to_image"
},
{
"type": "function",
"function": {
"name": "get_current_weather",
"description": "Get the current weather in a given location",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA"
},
"unit": {
"type": "string",
"enum": [
"celsius",
"fahrenheit"
]
}
},
"required": [
"location"
]
}
}
}
],
"metadata": {},
"usage": null,
"request_id": "792c29a2-e771-9840-9d99-df4f892badd0"
}
Streaming
event:thread.run.step.completed
data:{"id":"step_74a8b5e2-3d23-41d9-b5c8-9bf3ba3839d0","object":"thread.run.step","created_at":1714448906129,"assistant_id":"asst_5378d83a-f612-4fc1-9034-915351d67d98","thread_id":"thread_c6ac2eb0-ed95-4834-befb-ea66eba85b9f","run_id":"run_36d6fba9-0bf1-47f5-8e7b-f8c8140beda9","type":"tool_calls","status":"completed","step_details":{"type":"tool_calls","tool_calls":[{"id":"","type":"function","function":{"name":"get_current_weather","arguments":"{\"location\": \"Xi'an\"}","output":"rain"}}]},"last_error":null,"expired_at":null,"cancelled_at":null,"failed_at":null,"completed_at":null,"metadata":{},"usage":null,"request_id":"6d1573a4-3cbb-9066-99cc-7247ec17cb30"}
event:thread.run.queued
data:{"id":"run_36d6fba9-0bf1-47f5-8e7b-f8c8140beda9","object":"thread.run","created_at":1714448903737,"thread_id":"thread_c6ac2eb0-ed95-4834-befb-ea66eba85b9f","assistant_id":"asst_5378d83a-f612-4fc1-9034-915351d67d98","status":"queued","required_action":null,"last_error":null,"expires_at":null,"started_at":null,"cancelled_at":null,"failed_at":null,"completed_at":null,"model":"qwen-max","instructions":"You are an intelligent assistant. You can use different tools based on user needs and then provide answers. Use tools when needed.","tools":[{"type":"text_to_image"},{"type":"function","function":{"name":"get_current_weather","description":"Get the current weather in a given location","parameters":{"type":"object","properties":{"location":{"type":"string","description":"The city and state, e.g. San Francisco, CA"},"unit":{"type":"string","enum":["celsius","fahrenheit"]}},"required":["location"]}}}],"file_ids":[],"metadata":{},"usage":null,"temperature":null,"top_p":null,"top_k":null,"max_tokens":null,"truncation_strategy":null,"request_id":"6d1573a4-3cbb-9066-99cc-7247ec17cb30"}
event:thread.run.in_progress
data:{"id":"run_36d6fba9-0bf1-47f5-8e7b-f8c8140beda9","object":"thread.run","created_at":1714448903737,"thread_id":"thread_c6ac2eb0-ed95-4834-befb-ea66eba85b9f","assistant_id":"asst_5378d83a-f612-4fc1-9034-915351d67d98","status":"in_progress","required_action":null,"last_error":null,"expires_at":null,"started_at":null,"cancelled_at":null,"failed_at":null,"completed_at":null,"model":"qwen-max","instructions":"You are an intelligent assistant. You can use different tools based on user needs and then provide answers. Use tools when needed.","tools":[{"type":"text_to_image"},{"type":"function","function":{"name":"get_current_weather","description":"Get the current weather in a given location","parameters":{"type":"object","properties":{"location":{"type":"string","description":"The city and state, e.g. San Francisco, CA"},"unit":{"type":"string","enum":["celsius","fahrenheit"]}},"required":["location"]}}}],"file_ids":[],"metadata":{},"usage":null,"temperature":null,"top_p":null,"top_k":null,"max_tokens":null,"truncation_strategy":null,"request_id":"6d1573a4-3cbb-9066-99cc-7247ec17cb30"}
event:thread.run.step.created
data:{"id":"step_d74df5eb-dcb8-4fc2-a943-d06ccda0e2e3","object":"thread.run.step","created_at":1714449008828,"assistant_id":"asst_5378d83a-f612-4fc1-9034-915351d67d98","thread_id":"thread_c6ac2eb0-ed95-4834-befb-ea66eba85b9f","run_id":"run_36d6fba9-0bf1-47f5-8e7b-f8c8140beda9","type":"message_creation","status":"in_progress","step_details":{"type":"message_creation","message_creation":{"message_id":"message_965b3bb5-dbe2-434a-a36e-f7cda3845360"}},"last_error":null,"expired_at":null,"cancelled_at":null,"failed_at":null,"completed_at":null,"metadata":{},"usage":null,"request_id":"6d1573a4-3cbb-9066-99cc-7247ec17cb30"}
event:thread.run.step.in_progress
data:{"id":"step_d74df5eb-dcb8-4fc2-a943-d06ccda0e2e3","object":"thread.run.step","created_at":1714449008828,"assistant_id":"asst_5378d83a-f612-4fc1-9034-915351d67d98","thread_id":"thread_c6ac2eb0-ed95-4834-befb-ea66eba85b9f","run_id":"run_36d6fba9-0bf1-47f5-8e7b-f8c8140beda9","type":"message_creation","status":"in_progress","step_details":{"type":"message_creation","message_creation":{"message_id":"message_965b3bb5-dbe2-434a-a36e-f7cda3845360"}},"last_error":null,"expired_at":null,"cancelled_at":null,"failed_at":null,"completed_at":null,"metadata":{},"usage":null,"request_id":"6d1573a4-3cbb-9066-99cc-7247ec17cb30"}
event:thread.message.created
data:{"id":"message_965b3bb5-dbe2-434a-a36e-f7cda3845360","object":"thread.message","created_at":1714449008828,"thread_id":"thread_c6ac2eb0-ed95-4834-befb-ea66eba85b9f","incomplete_details":null,"completed_at":null,"incomplete_at":null,"role":"assistant","content":[],"assistant_id":"asst_5378d83a-f612-4fc1-9034-915351d67d98","run_id":"run_36d6fba9-0bf1-47f5-8e7b-f8c8140beda9","file_ids":[],"metadata":{},"request_id":"6d1573a4-3cbb-9066-99cc-7247ec17cb30"}
event:thread.message.in_progress
data:{"id":"message_965b3bb5-dbe2-434a-a36e-f7cda3845360","object":"thread.message","created_at":1714449008828,"thread_id":"thread_c6ac2eb0-ed95-4834-befb-ea66eba85b9f","incomplete_details":null,"completed_at":null,"incomplete_at":null,"role":"assistant","content":[],"assistant_id":"asst_5378d83a-f612-4fc1-9034-915351d67d98","run_id":"run_36d6fba9-0bf1-47f5-8e7b-f8c8140beda9","file_ids":[],"metadata":{},"request_id":"6d1573a4-3cbb-9066-99cc-7247ec17cb30"}
event:thread.message.delta
data:{"id":"message_965b3bb5-dbe2-434a-a36e-f7cda3845360","object":"thread.message.delta","delta":{"role":"assistant","content":[{"type":"text","text":{"value":"It","annotations":[]}}],"file_ids":[]},"request_id":"6d1573a4-3cbb-9066-99cc-7247ec17cb30"}
event:thread.message.delta
data:{"id":"message_965b3bb5-dbe2-434a-a36e-f7cda3845360","object":"thread.message.delta","delta":{"role":"assistant","content":[{"type":"text","text":{"value":"is raining in","annotations":[]}}],"file_ids":[]},"request_id":"6d1573a4-3cbb-9066-99cc-7247ec17cb30"}
event:thread.message.delta
data:{"id":"message_965b3bb5-dbe2-434a-a36e-f7cda3845360","object":"thread.message.delta","delta":{"role":"assistant","content":[{"type":"text","text":{"value":"Singapore.","annotations":[]}}],"file_ids":[]},"request_id":"6d1573a4-3cbb-9066-99cc-7247ec17cb30"}
event:thread.message.delta
data:{"id":"message_965b3bb5-dbe2-434a-a36e-f7cda3845360","object":"thread.message.delta","delta":{"role":"assistant","content":[{"type":"text","text":{"value":"","annotations":[]}}],"file_ids":[]},"request_id":"6d1573a4-3cbb-9066-99cc-7247ec17cb30"}
event:thread.message.completed
data:{"id":"message_965b3bb5-dbe2-434a-a36e-f7cda3845360","object":"thread.message","created_at":1714449008828,"thread_id":"thread_c6ac2eb0-ed95-4834-befb-ea66eba85b9f","incomplete_details":null,"completed_at":1714449009919,"incomplete_at":null,"role":"assistant","content":[{"type":"text","text":{"value":"It is raining in Singapore.","annotations":[]}}],"assistant_id":"asst_5378d83a-f612-4fc1-9034-915351d67d98","run_id":"run_36d6fba9-0bf1-47f5-8e7b-f8c8140beda9","file_ids":[],"metadata":{},"request_id":"6d1573a4-3cbb-9066-99cc-7247ec17cb30"}
event:thread.run.step.completed
data:{"id":"step_d74df5eb-dcb8-4fc2-a943-d06ccda0e2e3","object":"thread.run.step","created_at":1714449008828,"assistant_id":"asst_5378d83a-f612-4fc1-9034-915351d67d98","thread_id":"thread_c6ac2eb0-ed95-4834-befb-ea66eba85b9f","run_id":"run_36d6fba9-0bf1-47f5-8e7b-f8c8140beda9","type":"message_creation","status":"completed","step_details":{"type":"message_creation","message_creation":{"message_id":"message_965b3bb5-dbe2-434a-a36e-f7cda3845360"}},"last_error":null,"expired_at":null,"cancelled_at":null,"failed_at":null,"completed_at":1714449009919,"metadata":{},"usage":null,"request_id":"6d1573a4-3cbb-9066-99cc-7247ec17cb30"}
event:thread.run.completed
data:{"id":"run_36d6fba9-0bf1-47f5-8e7b-f8c8140beda9","object":"thread.run","created_at":1714448903737,"thread_id":"thread_c6ac2eb0-ed95-4834-befb-ea66eba85b9f","assistant_id":"asst_5378d83a-f612-4fc1-9034-915351d67d98","status":"completed","required_action":null,"last_error":null,"expires_at":null,"started_at":null,"cancelled_at":null,"failed_at":null,"completed_at":null,"model":"qwen-max","instructions":"You are an intelligent assistant. You can use different tools based on user needs and then provide answers. Use tools when needed.","tools":[{"type":"text_to_image"},{"type":"function","function":{"name":"get_current_weather","description":"Get the current weather in a given location","parameters":{"type":"object","properties":{"location":{"type":"string","description":"The city and state, e.g. San Francisco, CA"},"unit":{"type":"string","enum":["celsius","fahrenheit"]}},"required":["location"]}}}],"file_ids":[],"metadata":{},"usage":{"input_tokens":439,"output_tokens":11,"total_tokens":450},"temperature":null,"top_p":null,"top_k":null,"max_tokens":null,"truncation_strategy":null,"request_id":"6d1573a4-3cbb-9066-99cc-7247ec17cb30"}
event:done
data:[DONE]
Response parameters
Returns a run class, including the following parameters:
id: The run ID.
request_id: The request ID.
SDK
import json
import sys
from http import HTTPStatus
from dashscope import Assistants, Messages, Runs, Steps, Threads
import dashscope
dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'
def create_assistant():
# create assistant with information
assistant = Assistants.create(
model='qwen-max',
name='smart helper',
description='A tool helper.',
instructions='You are a helpful assistant. When asked a question, use tools wherever possible.', # noqa E501
tools=[{
'type': 'function',
'function': {
'name': 'big_add',
'description': 'Add to number',
'parameters': {
'type': 'object',
'properties': {
'left': {
'type': 'integer',
'description': 'The left operator'
},
'right': {
'type': 'integer',
'description': 'The right operator.'
}
},
'required': ['left', 'right']
}
}
}],
)
return assistant
def verify_status_code(res):
if res.status_code != HTTPStatus.OK:
sys.exit(res.status_code)
if __name__ == '__main__':
# create assistant
assistant = create_assistant()
print(assistant)
verify_status_code(assistant)
# create thread.
thread = Threads.create()
print(thread)
verify_status_code(thread)
# create a message.
message = Messages.create(thread.id, content='bigAdd 87787 to 788988737.')
print(message)
verify_status_code(message)
# create run to run message
message_run = Runs.create(thread.id, assistant_id=assistant.id)
print(message_run)
verify_status_code(message_run)
# get run statue
run_status = Runs.get(message_run.id, thread_id=thread.id)
print(run_status)
verify_status_code(run_status)
# wait for run completed or requires_action
run_status = Runs.wait(message_run.id, thread_id=thread.id)
print(run_status)
# if prompt input tool result, submit tool result.
# should call big_add
if run_status.required_action:
tool_outputs = [{
'tool_call_id':
run_status.required_action.submit_tool_outputs.tool_calls[0].id,
'output':
'789076524'
}]
run = Runs.submit_tool_outputs(message_run.id,
thread_id=thread.id,
tool_outputs=tool_outputs)
print(run)
verify_status_code(run)
# wait for run completed or requires_action
run_status = Runs.wait(message_run.id, thread_id=thread.id)
print(run_status)
verify_status_code(run_status)
run_status = Runs.get(run.id, thread_id=thread.id)
print(run_status)
verify_status_code(run_status)
run_steps = Steps.list(run.id, thread_id=thread.id)
print(run_steps)
verify_status_code(run_steps)
# get the thread messages.
msgs = Messages.list(thread.id)
print(msgs)
print(json.dumps(msgs, default=lambda o: o.__dict__, sort_keys=True, indent=4))
import com.alibaba.dashscope.assistants.Assistant;
import com.alibaba.dashscope.assistants.AssistantParam;
import com.alibaba.dashscope.tools.ToolFunction;
import com.alibaba.dashscope.assistants.Assistants;
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.AssistantThread;
import com.alibaba.dashscope.threads.ThreadParam;
import com.alibaba.dashscope.threads.Threads;
import com.alibaba.dashscope.threads.messages.Messages;
import com.alibaba.dashscope.threads.messages.TextMessageParam;
import com.alibaba.dashscope.threads.messages.ThreadMessage;
import com.alibaba.dashscope.threads.runs.RequiredAction;
import com.alibaba.dashscope.threads.runs.Run;
import com.alibaba.dashscope.threads.runs.RunParam;
import com.alibaba.dashscope.threads.runs.Runs;
import com.alibaba.dashscope.threads.runs.SubmitToolOutputsParam;
import com.alibaba.dashscope.threads.runs.ToolOutput;
import com.alibaba.dashscope.tools.FunctionDefinition;
import com.alibaba.dashscope.tools.ToolCallBase;
import com.alibaba.dashscope.utils.JsonUtils;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.github.victools.jsonschema.generator.Option;
import com.github.victools.jsonschema.generator.OptionPreset;
import com.github.victools.jsonschema.generator.SchemaGenerator;
import com.github.victools.jsonschema.generator.SchemaGeneratorConfig;
import com.github.victools.jsonschema.generator.SchemaGeneratorConfigBuilder;
import com.github.victools.jsonschema.generator.SchemaVersion;
import com.alibaba.dashscope.tools.ToolCallFunction;
import com.alibaba.dashscope.utils.Constants;
public class AssistantFunctionCall {
static {
Constants.baseHttpApiUrl="https://dashscope-intl.aliyuncs.com/api/v1";
}
public class AddFunctionTool {
private int left;
private int right;
public AddFunctionTool(int left, int right) {
this.left = left;
this.right = right;
}
public int call() {
return left + right;
}
}
static ToolFunction buildFunction() {
SchemaGeneratorConfigBuilder configBuilder = new SchemaGeneratorConfigBuilder(SchemaVersion.DRAFT_2020_12,
OptionPreset.PLAIN_JSON);
SchemaGeneratorConfig config = configBuilder.with(Option.EXTRA_OPEN_API_FORMAT_VALUES)
.without(Option.FLATTENED_ENUMS_FROM_TOSTRING).build();
SchemaGenerator generator = new SchemaGenerator(config);
// generate jsonSchema of function.
ObjectNode jsonSchema = generator.generateSchema(AddFunctionTool.class);
// call with tools of function call, jsonSchema.toString() is jsonschema String.
FunctionDefinition fd = FunctionDefinition.builder().name("add").description("add two number")
.parameters(JsonUtils.parseString(jsonSchema.toString()).getAsJsonObject()).build();
return ToolFunction.builder().function(fd).build();
}
static public Assistant createAssistant() throws ApiException, NoApiKeyException{
AssistantParam assistantParam = AssistantParam.builder()
.model("qwen-max") // model must be set.
.description("a helper assistant")
.name("system") // name must be set.
.instructions("You are a helpful assistant. When asked a question, use tools wherever possible.")
.tool(buildFunction())
.build();
Assistants assistants = new Assistants();
return assistants.create(assistantParam);
}
static public void run(String assistantId) throws ApiException, NoApiKeyException, InvalidateParameter, InputRequiredException, InterruptedException{
// create a thread
Threads threads = new Threads();
AssistantThread assistantThread = threads.create(ThreadParam.builder().build());
Runs runs = new Runs();
// create a new message
TextMessageParam textMessageParam = TextMessageParam.builder().role("user").content("Add 87787 to 788988737.").build();
Messages messages = new Messages();
ThreadMessage threadMessage = messages.create(assistantThread.getId(), textMessageParam);
System.out.println(threadMessage);
RunParam runParam = RunParam.builder().assistantId(assistantId).build();
Run run = runs.create(assistantThread.getId(), runParam);
while(true){
if(run.getStatus().equals(Run.Status.CANCELLED) ||
run.getStatus().equals(Run.Status.COMPLETED) ||
run.getStatus().equals(Run.Status.FAILED) ||
run.getStatus().equals(Run.Status.REQUIRES_ACTION)||
run.getStatus().equals(Run.Status.EXPIRED)){
break;
}else{
Thread.sleep(1000);
}
run = runs.retrieve(assistantThread.getId(), run.getId());
}
if(run.getStatus().equals(Run.Status.REQUIRES_ACTION)){
// submit action output.
RequiredAction requiredAction = run.getRequiredAction();
if(requiredAction.getType().equals("submit_tool_outputs")){
ToolCallBase toolCall = requiredAction.getSubmitToolOutputs().getToolCalls().get(0);
if (toolCall.getType().equals("function")) {
// get function call name and argument, both String.
String functionName = ((ToolCallFunction) toolCall).getFunction().getName();
String functionId = ((ToolCallFunction)toolCall).getId();
String functionArgument = ((ToolCallFunction) toolCall).getFunction().getArguments();
if (functionName.equals("add")) {
// Create the function object.
AddFunctionTool addFunction =
JsonUtils.fromJson(functionArgument, AddFunctionTool.class);
// call function.
int sum = addFunction.call();
System.out.println(sum);
SubmitToolOutputsParam submitToolOutputsParam = SubmitToolOutputsParam.builder()
.toolOutput(ToolOutput.builder().toolCallId(functionId).output(String.valueOf(sum)).build())
.build();
run = runs.submitToolOutputs(assistantThread.getId(), run.getId(), submitToolOutputsParam);
}
}
}
}
while(true){
if(run.getStatus().equals(Run.Status.CANCELLED) ||
run.getStatus().equals(Run.Status.COMPLETED) ||
run.getStatus().equals(Run.Status.FAILED) ||
run.getStatus().equals(Run.Status.REQUIRES_ACTION)||
run.getStatus().equals(Run.Status.EXPIRED)){
break;
}else{
Thread.sleep(1000);
}
run = runs.retrieve(assistantThread.getId(), run.getId());
}
GeneralListParam listParam = GeneralListParam.builder().limit(100l).build();
ListResult<ThreadMessage> threadMessages = messages.list(assistantThread.getId(), listParam);
for(ThreadMessage threadMessage2: threadMessages.getData()){
System.out.println(threadMessage2);
}
}
public static void main(String[] args) throws ApiException, NoApiKeyException, InputRequiredException, InvalidateParameter, InterruptedException {
Assistant assistant = createAssistant();
run(assistant.getId());
}
}
Wait for a run to complete
Monitor the run until it reaches one of the following statuses:
cancelled
failed
completed
expired
requires_action
SDK
Sample code
from dashscope import Runs
import dashscope
dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'
run = Runs.wait('run_id',
thread_id='thread_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.Run;
import com.alibaba.dashscope.threads.runs.Runs;
import com.alibaba.dashscope.utils.Constants;
public class AssistantFunctionCall {
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();
Run run = runs.retrieve("thread_id", "run_id");
while(true){
if(run.getStatus().equals(Run.Status.CANCELLED) ||
run.getStatus().equals(Run.Status.COMPLETED) ||
run.getStatus().equals(Run.Status.FAILED) ||
run.getStatus().equals(Run.Status.REQUIRES_ACTION)||
run.getStatus().equals(Run.Status.EXPIRED)){
break;
}else{
Thread.sleep(1000);
}
run = runs.retrieve("thread_id", run.getId());
}
}
}
Request parameters
Parameter | Type | Description |
run_id | str | The ID of the run. |
thread_id | str | The ID of the thread to which the run belongs. |
workspace | str | The workspace ID. |
api_key | str | The API key. You can set it as an environment variable. |
Response parameters
See the response parameters of the Create a run task section.
FAQ
Q: How can I cancel an active run task?
A: The Assistant API does not offer an operation to cancel active run tasks. We recommend that you use other code logic instead.