# Runs and Run Steps

在您从用户的线索中获取所需的所有上下文信息后，您可以选择一个助手来执行线索。

创建并执行运行 基本运行创建：

run = client.beta.threads.runs.create( thread\_id=thread.id, assistant\_id=assistant.id ) 默认情况下，运行会使用助手对象中指定的模型(model)和工具(tools)配置。

自定义运行：

您可以在创建运行时覆盖默认配置以获得更多灵活性：

run = client.beta.threads.runs.create( thread\_id=thread.id, assistant\_id=assistant.id, model="gpt-4-turbo-preview", instructions="New instructions that override the Assistant instructions", tools=\[{"type": "code\_interpreter"}, {"type": "retrieval"}] ) 注意：与助手关联的文件ID (file\_ids) 在创建运行期间不能被覆盖。要修改这些，您需要使用修改助手的端点。

运行生命周期和状态 状态定义：

queued：初始状态，运行创建后或完成所需操作后进入此状态，应该几乎立即转换到 in\_progress 状态。 in\_progress：助手正在使用模型和工具执行步骤，您可以通过检查运行步骤来监控进度。 completed：运行成功完成，您可以查看助手添加到线索的所有消息，以及运行采取的所有步骤。 requires\_action：当使用函数调用工具且模型确定需要调用的函数及其参数时，运行将进入此状态。 expired：如果函数调用的输出未在设定时间内提交，运行将过期。 cancelling：您可以尝试取消正在进行的运行，成功后状态变为 cancelled。 cancelled：运行已成功取消。 failed：运行失败，失败原因可以通过查看运行中的 last\_error 对象来确定。 轮询更新：

为了保持运行状态的最新，需要定期检索运行对象，并根据运行的状态决定下一步行动。

线索锁定 当运行处于 in\_progress 状态且不是终止状态时，线索将被锁定，这意味着无法向线索添加新消息，也无法在线索上创建新的运行。

运行步骤 步骤状态：

运行步骤的状态与运行状态含义相同。

步骤类型：

message\_creation：助手在线索上创建消息时创建。 tool\_calls：助手调用工具时创建。 数据访问指南 鉴于通过 API 创建的助手、线索、消息和文件对整个组织可见，建议实施授权措施、限制 API 密钥访问，并考虑为不同应用创建独立账户/组织以隔离数据。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://doc.afarensis.com/google-zhu-li-de-gong-zuo-yuan-li/runs-and-run-steps.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
