OpenAI GPT-Live 委派与工具

2026-11-06 12:39 更新

GPT-Live 管理语音对话,把推理和工具使用委派给后端。后端工作既可以由配置的 Responses 模型运行,也可以通过客户端委派,交给应用运营的任何模型、智能体或服务。无论哪种模式,权限、确认、业务记录和任务状态均由应用负责。

如何引导 Live 模型进行委派和工具使用,见提示词指南。

本页事件示例中的 connection 表示已连接的 Live 主 WebSocket 或旁路连接,配置方法见连接指南。主连接应等待 session.started 后再调用事件辅助函数;已附加的旁路连接则属于运行中的会话。

选择委派模式

Responses 委派中,GPT-Live 调用你选择的 Responses 模型、提供对话上下文,并将后端结果带回实时对话。客户端委派中,由应用准备上下文、运行智能体或工作流,再把结果发回 GPT-Live。

希望 GPT-Live 管理请求时,从 Responses 委派开始;需要自行运行工作流,或在结果传给 GPT-Live 之前审核结果时,选择客户端委派。

考量 适合 Responses 委派的情况 适合客户端委派的情况
实现工作量 希望 GPT-Live 准备后端请求、管理连接并向对话返回结果。 希望自行构建和运营这些部分。
后端结果审核 后端输出可以直接返回 GPT-Live。 应用必须先验证、脱敏、合并或丢弃结果。
后端能力 工作流适合 GPT-Live 支持的 Responses 设置与工具。 需要其他后端、多模型或托管配置之外的 API 能力。
上下文控制权 GPT-Live 提供的对话上下文适合应用。 必须精确选择每次后端请求收到的历史、记忆与应用状态。
执行策略 配置好的模型与工具循环能满足任务。 需要在代码与模型间自定义路由、回退、检查点或跨步骤预算。

例如,旅行助手可以把航班状态查询发给航空公司服务,把行程修改交给独立规划智能体。应用决定调用哪个后端,以及向 GPT-Live 返回什么经过验证的结果。

两种模式下,应用都要追踪任务进度,并在运行自定义工具前检查权限和必要的用户确认。应用审核后端结果期间,GPT-Live 可以继续说话。如果必须控制用户何时听见音频,应增加播放控制。

客户端委派还要求应用维护对话上下文。委派事件只包含元数据,不包含任务文本;应根据转录事件和应用状态构造后端请求。

评估语音智能体时,用实际工作负载比较延迟、任务成功率和费用。针对已有架构的建议见迁移到 GPT-Live。

在创建会话时选择模式;切换模式需要启动新会话。

配置 Responses 委派

创建 Live 会话时添加以下委派配置。Responses 模型可独立于语音模型选择:

来源示例 1(javascript):

原文 Markdown 的此示例为空;以下代码由同页所提供的 HTML 示例补回。

程序文字译释38:[你的后端提示词]是占位文本,应替换为应用实际后端指令。

// [中文] 示例 1:配置 Responses 委派;以下保留本语言原始示例。
// [中文] 原代码明确设置的模型值:gpt-live-1、gpt-6-luna;各值的作用按其所在配置对象区分。
export const session = {
  model: "gpt-live-1",
  delegation: {
    type: "responses",
    responses: {
      model: "gpt-6-luna",
      instructions: "[Your backend prompt]",
    },
  },
};

来源示例 2(python):

沿用程序文字译释38。

## [中文] 示例 2:配置 Responses 委派;以下保留本语言原始示例。
## [中文] 将 Live 语音模型与 Responses 后端模型分开配置;delegation.type 选择 responses,后端指令放在 delegation.responses.instructions。
## [中文] 此对象只描述会话启动配置,没有发起模型调用或执行自定义函数。
from openai.types.live.session_config_param import SessionConfigParam

session: SessionConfigParam = {
    "model": "gpt-live-1",
    "delegation": {
        "type": "responses",
        "responses": {
            "model": "gpt-6-luna",
            "instructions": "[Your backend prompt]",
        },
    },
}

// [中文] 定义会话启动配置,区分Live语音模型与委派后端设置;配置对象本身不会建立连接、执行工具或自动运行后端。
// [中文] 本段为配置或调用片段,需结合外层程序与已建立连接使用;不作为独立完整程序宣称编译通过。
import (
    "github.com/openai/openai-go/v3"
    "github.com/openai/openai-go/v3/live"
)

var session = live.SessionConfigParam{Model: "gpt-live-1", Delegation: live.SessionConfigDelegationUnionParam{OfResponses: &live.SessionConfigDelegationResponsesParam{Responses: live.ResponsesDelegationConfigParam{Model: "gpt-6-luna", Instructions: openai.String("[Your backend prompt]")}}}}

// [中文] 定义会话启动配置,区分Live语音模型与委派后端设置;配置对象本身不会建立连接、执行工具或自动运行后端。
// [中文] 本段为配置或调用片段,需结合外层程序与已建立连接使用;不作为独立完整程序宣称编译通过。
import com.openai.models.live.*;

var session =
    SessionConfig.builder()
        .model("gpt-live-1")
        .responsesDelegation(
            ResponsesDelegationConfig.builder()
                .model("gpt-6-luna")
                .instructions("[Your backend prompt]")
                .build())
        .build();

## [中文] 定义会话启动配置,区分Live语音模型与委派后端设置;配置对象本身不会建立连接、执行工具或自动运行后端。
require "openai"
session = OpenAI::Models::Live::SessionConfig.new(
  model: "gpt-live-1", delegation: {
    type: :responses,
    responses: {
      model: "gpt-6-luna",
      instructions: "[Your backend prompt]"
    }
  }
)

从 gpt-6-luna 开始,后端任务更复杂时可尝试 gpt-6-sol。选择前用自己的任务比较回答质量和延迟。

在 delegation.responses.tools 注册支持的工具。delegation.responses.tool_choice 设为 "auto" 时由后端选择工具,"required" 要求工具调用,"none" 禁用工具调用;也可以指定具名函数。

把 delegation.responses.parallel_tool_calls 设为 true 可允许一次响应包含多个工具调用,设为 false 则顺序调用。自定义函数由应用执行,依赖关系和所需批准也由应用检查。这些设置在 GPT-Live 委派之后生效;何时委派则由 Live 提示词引导。

Responses 配置在创建时必须包含后端 model。除下述工具外,还提供 max_output_tokens(设置时至少为 16)、service_tier,以及所选模型支持的 reasoning、text 设置。可调项见降低后端延迟。

如果模型和项目可使用快速模式,可考虑将其用于延迟敏感的调用。GPT-Live 中用 delegation.responses.service_tier: "priority" 选择。

对话期间,可发送 session.update,在 session.delegation.responses 内更改后端模型、指令、工具、tool_choice 等支持的设置。省略的设置保留当前值。

要切换 Responses 与客户端委派,应创建新 Live 会话。把 delegation 改成 null 表示选择客户端模式,因此对运行中的 Responses 会话这样更新会触发 immutable_field_update。

这些设置使用熟悉的 Responses 概念,但 Live 只支持独立 Responses API 的一个子集。Live 提供对话上下文并发起委派工作。后端应通过会话配置;Live 的 response.create 命令使用该配置,不接受独立 Responses 请求体。

添加托管工具

将网页搜索、文件搜索、代码解释器、托管 Shell或图像生成添加到 delegation.responses.tools。配置、模型支持和所需资源见对应指南。Responses 会运行这些工具并自动返回结果。

Shell 应使用托管容器,也可以配合 Skills。新上传的 Skill,必须等待引用的版本可读取后再启动 Live 会话。本地 Shell 的调用由应用执行。Live 不支持 Shell 的 domain_secrets。

添加 MCP 与其他工具

Responses 委派还支持 MCP、工具搜索、程序化工具调用、函数与自定义工具、计算机使用、本地 Shell 和 Apply Patch。设置见对应指南。应用结果与批准决定通过 Live 续接流程返回。

Live 会把你提供的 MCP authorization 与 headers 传给 Responses,但返回应用的会话配置中不会包含这些值。更新指令等其他设置时不必重发;如果替换 delegation.responses.tools,必须重新包含 MCP 凭证。

处理配置错误

Live 在启动后及设置变更时异步验证 Responses 设置。session.started、session.updated 不等待该验证完成。应监听代码为 responses_validation_failed 的 error,通过消息检查不支持的设置或不可访问资源。会话保持打开,设置也不会回滚,需用 session.update 纠正。

例如,Skill 的数字型 version(如 1)会使 session.start 或 session.update 产生非致命的 responses_validation_failed。错误会在不等待 response.create 的情况下指出无效字段和预期类型。通过 error.client_event_id 匹配配置事件,可在同一会话用 session.update 移除无效工具配置恢复。版本应使用 "1" 等字符串。

验证并不保证后续工具一定可执行。资源访问和工具可用性可能变化,委派期间仍要处理后端错误。托管工具的配置验证可能初始化容器等资源。

从应用引导实时对话

Responses 委派管理后端工作流,但应用仍可直接给 GPT-Live 模型发送上下文。如果通过旁路 WebSocket 或主事件连接监控通话,可使用 delegation_id: null 的 session.instructions.append、session.thinking.append 或 session.commentary.append。例如,基于转录的防护规则可以追加引导对话的指令。这会引导 Live 模型,不会改变 Responses 后端提示词,也不会取消已经运行的工作。

处理 Responses 委派

Responses 后端工作对应的 session.delegation.created 具有 target: "responses" 和 response_id。随后的 Responses 事件位于 response.event 封装中:

来源示例 3(json):

程序文字译释39:天气预报是……(仅是增量片段)。

{
  "type": "response.event",
  "event_id": "event_response_1",
  "delegation_id": "item_9tA2cB6n2V8c4X1z7Q5r9",
  "event": {
    "type": "response.output_text.delta",
    "sequence_number": 4,
    "item_id": "msg_123",
    "output_index": 0,
    "content_index": 0,
    "delta": "The forecast is",
    "logprobs": []
  }
}

顶层事件类型为 response.event 时,根据 envelope.event.type 分发。保存外层 delegation_id,以关联后端事件与委派。处理器还可能接收这里未展示的 Responses 生命周期事件。

托管工具进度、引用、文件和生成图像都会出现在这些嵌套事件中。应读取单独的输出项与部分图像事件收集结果;转发的生命周期快照省略输出数组。使用相应的 Responses 文件或容器 API 下载文件。大型图像或产物事件应通过 WebSocket 或旁路连接接收,因为 WebRTC 数据通道的消息上限可能更小。

Live 讲话和被委派工作独立推进。后端响应完成不代表用户已听到答案;交互中的语音部分应使用 Live 输出转录和音频判断。

返回工具结果与批准

需要应用输入的工具,应从嵌套 response.output_item.done 收集已完成调用。执行获授权操作或批准检查后,通过 response.item.create 发送匹配项目:

收到的项目 返回的结果项目
function_call function_call_output
custom_tool_call custom_tool_call_output
computer_call computer_call_output
本地 shell_call shell_call_output
apply_patch_call apply_patch_call_output
execution: "client" 的 tool_search_call 带 execution: "client" 及发现的 tools 的 tool_search_output
mcp_approval_request mcp_approval_response

用 call_id 匹配结果与调用。MCP 批准则将 approval_request_id 设为批准请求的 id,并把 approve 设为 true 或 false。已完成的 mcp_call 本身不需要客户端结果。遵循各工具的结果结构,包括程序化函数调用的 caller 元数据和计算机使用所需的安全确认。

提交所有待处理调用的结果后,发送 response.create。仅追加项目不会恢复后端。缺少结果会产生 tool_outputs_required;若只缺少函数结果,则为 function_call_outputs_required。重复结果和不匹配的结果类型会被拒绝。

可以在当前后端响应完成前提交结果并请求续接。已接受的 response.create 会等待响应完成,不要重发。如果此后后端发出更多调用,提交其结果,再发送另一个 response.create。

执行自定义函数并返回结果

从嵌套 response.output_item.done 读取完成的函数调用。完成的函数项目包含 call_id、name 和 arguments;只有参数完成事件不足以标识调用。

同时追踪嵌套 response.created 的响应 ID 和外层 delegation_id。从 response.output_item.done 收集该响应的函数调用,并据此确定继续前需要提交哪些工具结果。

转发的生命周期事件,包括 response.completed,即使有待返回结果的函数调用,也包含 response.output: []。其中 tools 也是空数组,instructions: null,并且没有 input。函数调用应从单独的输出项事件读取。

执行获授权操作后,把结果追加为 Responses 项目:

来源示例 4(javascript):

// [中文] 示例 4:执行自定义函数并返回结果;以下保留本语言原始示例。
// [中文] 本段构造的事件类型:response.item.create;不要将构造载荷等同于收到成功确认。
// [中文] 沿原示例执行这些方法:connection.send;异步调用及事件接收顺序保留。
// [中文] 返回函数结果时保留对应 call_id;响应继续事件与结果项目是两个独立步骤。
export function sendUpdate(connection) {
  connection.send({
    type: "response.item.create",
    event_id: "tool_result_1",
    item: {
      type: "function_call_output",
      call_id: "call_123",
      output: '{"status":"confirmed","order_id":"order_123"}',
    },
  });
}

来源示例 5(python):

## [中文] 示例 5:执行自定义函数并返回结果;以下保留本语言原始示例。
## [中文] 沿原示例执行这些方法:connection.response.item.create;异步调用及事件接收顺序保留。
## [中文] 返回函数结果时保留对应 call_id;响应继续事件与结果项目是两个独立步骤。
from openai.resources.live.live import AsyncLiveConnection
from openai.resources.live.sideband import AsyncSidebandConnection
from openai.types.responses.response_input_item_param import ResponseInputItemParam


async def send_update(
    connection: AsyncLiveConnection | AsyncSidebandConnection,
) -> None:
    item: ResponseInputItemParam = {
        "type": "function_call_output",
        "call_id": "call_123",
        "output": '{"status":"confirmed","order_id":"order_123"}',
    }
    await connection.response.item.create(
        event_id="tool_result_1",
        item=item,
    )

// [中文] 保留原例中客户端、输入和返回值的处理顺序;本段需结合所在小节的连接前提使用,未通过真实API调用验证。
// [中文] 本段为配置或调用片段,需结合外层程序与已建立连接使用;不作为独立完整程序宣称编译通过。
import (
    "context"
    "github.com/openai/openai-go/v3"
    "github.com/openai/openai-go/v3/live"
    "github.com/openai/openai-go/v3/responses"
)

// SendUpdate requires a started Live session.
func SendUpdate(ctx context.Context, connection *live.LiveConnection) error {
    return connection.Send(ctx, live.ClientEventUnionParam{OfResponseItemCreate: &live.ResponseItemCreateEventParam{
        EventID: openai.String("tool_result_1"),
        Item:    responses.ResponseInputItemUnionParam{OfFunctionCallOutput: &responses.ResponseInputItemFunctionCallOutputParam{CallID: openai.String("call_123"), Output: responses.ResponseInputItemFunctionCallOutputOutputUnionParam{OfString: openai.String("{\"status\":\"confirmed\",\"order_id\":\"order_123\"}")}}},
    }})
}

// [中文] 保留原例中客户端、输入和返回值的处理顺序;本段需结合所在小节的连接前提使用,未通过真实API调用验证。
// [中文] 本段为配置或调用片段,需结合外层程序与已建立连接使用;不作为独立完整程序宣称编译通过。
import com.openai.helpers.LiveConnection;
import com.openai.models.live.*;
import com.openai.models.responses.*;

public static void sendUpdate(LiveConnection connection) {
  connection.send(
      ClientEvent.ofResponseItemCreate(
          ResponseItemCreateEvent.builder()
              .eventId("tool_result_1")
              .item(
                  ResponseInputItem.FunctionCallOutput.builder()
                      .callId("call_123")
                      .output("{\"status\":\"confirmed\",\"order_id\":\"order_123\"}")
                      .build())
              .build()));
}

## [中文] 返回函数结果时保留对应call_id;结果项目与继续响应是独立步骤,必须按代码显式续接并持续处理错误事件。
def send_update(connection)
  connection.send_event(
    type: "response.item.create", event_id: "tool_result_1", item: {
      type: "function_call_output",
      call_id: "call_123",
      output: "{\"status\":\"confirmed\",\"order_id\":\"order_123\"}"
    }
  )
end

然后显式继续响应:

来源示例 6(javascript):

// [中文] 示例 6:执行自定义函数并返回结果;以下保留本语言原始示例。
// [中文] 本段构造的事件类型:response.create;不要将构造载荷等同于收到成功确认。
// [中文] 沿原示例执行这些方法:connection.send;异步调用及事件接收顺序保留。
export function sendUpdate(connection) {
  connection.send({
    type: "response.create",
    event_id: "continue_1",
  });
}

来源示例 7(python):

## [中文] 示例 7:执行自定义函数并返回结果;以下保留本语言原始示例。
## [中文] 沿原示例执行这些方法:connection.response.create;异步调用及事件接收顺序保留。
from openai.resources.live.live import AsyncLiveConnection
from openai.resources.live.sideband import AsyncSidebandConnection


async def send_update(
    connection: AsyncLiveConnection | AsyncSidebandConnection,
) -> None:
    await connection.response.create(
        event_id="continue_1",
    )

// [中文] 显式请求创建或继续响应,使用本段实际设置的模态、上下文与工具字段;发送请求不等同于收到完成事件。
// [中文] 本段为配置或调用片段,需结合外层程序与已建立连接使用;不作为独立完整程序宣称编译通过。
import (
    "context"
    "github.com/openai/openai-go/v3"
    "github.com/openai/openai-go/v3/live"
)

// SendUpdate requires a started Live session.
func SendUpdate(ctx context.Context, connection *live.LiveConnection) error {
    return connection.Send(ctx, live.ClientEventUnionParam{OfResponseCreate: &live.ResponseCreateEventParam{
        EventID: openai.String("continue_1"),
    }})
}

// [中文] 显式请求创建或继续响应,使用本段实际设置的模态、上下文与工具字段;发送请求不等同于收到完成事件。
// [中文] 本段为配置或调用片段,需结合外层程序与已建立连接使用;不作为独立完整程序宣称编译通过。
import com.openai.helpers.LiveConnection;
import com.openai.models.live.*;

public static void sendUpdate(LiveConnection connection) {
  connection.send(
      ClientEvent.ofResponseCreate(ResponseCreateEvent.builder().eventId("continue_1").build()));
}

## [中文] 显式请求创建或继续响应,使用本段实际设置的模态、上下文与工具字段;发送请求不等同于收到完成事件。
def send_update(connection)
  connection.send_event(type: "response.create", event_id: "continue_1")
end

每个待处理函数调用均发送一个 response.item.create 结果,再用 response.create 继续后端响应。response.item.create 没有单独的成功确认;应持续处理错误和嵌套生命周期事件。

两个命令都要求 Responses 委派。Live response.create 使用会话内保存的后端配置,应使用上述事件载荷,通过会话配置模型和其他设置。

配置客户端委派

创建 Live 会话时设置 delegation:

来源示例 8(javascript):

原文 Markdown 的此示例为空;以下代码由同页所提供的 HTML 示例补回。

// [中文] 示例 8:配置客户端委派;以下保留本语言原始示例。
// [中文] 原代码明确设置的模型值:gpt-live-1;各值的作用按其所在配置对象区分。
export const session = {
  model: "gpt-live-1",
  delegation: {
    type: "client",
  },
};

来源示例 9(python):

## [中文] 示例 9:配置客户端委派;以下保留本语言原始示例。
## [中文] 启动时选择 client 委派;收到委派后,后端的选择、上下文维护、工作执行和结果返回均由应用负责。
## [中文] 这里只定义配置对象,不会自动运行后端;运行中的会话不能据此切换委派类型。
from openai.types.live.session_config_param import SessionConfigParam

session: SessionConfigParam = {"model": "gpt-live-1", "delegation": {"type": "client"}}

// [中文] 定义会话启动配置,区分Live语音模型与委派后端设置;配置对象本身不会建立连接、执行工具或自动运行后端。
// [中文] 本段为配置或调用片段,需结合外层程序与已建立连接使用;不作为独立完整程序宣称编译通过。
import (
    "github.com/openai/openai-go/v3/live"
)

var session = live.SessionConfigParam{Model: "gpt-live-1", Delegation: live.SessionConfigDelegationUnionParam{OfClient: &live.ClientDelegationParam{}}}

// [中文] 定义会话启动配置,区分Live语音模型与委派后端设置;配置对象本身不会建立连接、执行工具或自动运行后端。
// [中文] 本段为配置或调用片段,需结合外层程序与已建立连接使用;不作为独立完整程序宣称编译通过。
import com.openai.models.live.*;

var session =
    SessionConfig.builder()
        .model("gpt-live-1")
        .delegation(ClientDelegation.builder().build())
        .build();

## [中文] 定义会话启动配置,区分Live语音模型与委派后端设置;配置对象本身不会建立连接、执行工具或自动运行后端。
require "openai"
session = OpenAI::Models::Live::SessionConfig.new(model: "gpt-live-1", delegation: { type: :client })

由应用配置和运行后端,选择模型或服务、指令、工具与路由。如果后端使用 Responses API,就在应用的 Responses 请求中配置模型和工具。

GPT-Live 请求帮助时,依据保存的对话历史与当前任务状态构造后端请求。检查权限及必要确认、运行工作,并选择返回哪些结果。

在应用中保留对话上下文

客户端委派中,必须自行收集转录并维护当前任务状态。

监听 session.input_transcript.delta 与 session.output_transcript.delta。事件的 delta 包含转录文字,另有 start_ms、end_ms 时间戳。保留足够历史,才能理解“是”等简短回答、“周四,不是周五”等纠正,以及先前给出的细节。转录片段不是完整用户轮次,转录本身也可能出错。

独立的 session.delegation.created 只包含 offset_ms 时间戳和委派元数据,如 delegation.id、delegation.target,不包含用户说的话或任务文本。应结合转录与应用状态确定用户需求。保存 delegation.id,将后续更新匹配到此请求。

长记录与完整工具输出留在后端。创建替代会话时,从应用恢复相关上下文,并在重复工作前检查哪些操作已经运行。

接收客户端委派

session.delegation.created 标识一项委派:

来源示例 10(json):字段名、事件类型和示意值保留原样,含义见相邻正文;片段中的省略号不表示完整可运行程序。

{
  "type": "session.delegation.created",
  "event_id": "event_delegation",
  "offset_ms": 1000,
  "delegation": {
    "id": "item_9tA2bF3h7K9m2P5q8R1s4",
    "type": "delegation",
    "target": "client"
  }
}

保存 event.delegation.id,该任务的更新中原样包含此值。

使用此 ID 返回结果:

来源示例 11(javascript):

程序文字译释40:订单今天已发货,预计明天到达。

// [中文] 示例 11:接收客户端委派;以下保留本语言原始示例。
// [中文] 本段构造的事件类型:session.commentary.append;不要将构造载荷等同于收到成功确认。
// [中文] 沿原示例执行这些方法:connection.send;异步调用及事件接收顺序保留。
// [中文] 委派 ID 与响应、工具调用 ID 不同;追加上下文时,非空 delegation_id 须对应客户端委派,null 用于会话级上下文。
export function sendUpdate(connection) {
  connection.send({
    type: "session.commentary.append",
    event_id: "result_123",
    delegation_id: "item_9tA2bF3h7K9m2P5q8R1s4",
    content: "The order shipped today and should arrive tomorrow.",
  });
}

来源示例 12(python):

沿用程序文字译释40。

## [中文] 把应向用户说明的已核实内容作为commentary追加;委派ID关联对应任务,会话级更新使用null,生成与实际播放仍需分别核实。
from openai.resources.live.live import AsyncLiveConnection
from openai.resources.live.sideband import AsyncSidebandConnection


async def send_update(
    connection: AsyncLiveConnection | AsyncSidebandConnection,
    delegation_id: str,
) -> None:
    await connection.session.commentary.append(
        event_id="result_123",
        delegation_id=delegation_id,
        content="The order shipped today and should arrive tomorrow.",
    )

// [中文] 保留原例中客户端、输入和返回值的处理顺序;本段需结合所在小节的连接前提使用,未通过真实API调用验证。
// [中文] 本段为配置或调用片段,需结合外层程序与已建立连接使用;不作为独立完整程序宣称编译通过。
import (
    "context"
    "github.com/openai/openai-go/v3"
    "github.com/openai/openai-go/v3/live"
)

// SendUpdate requires a started Live session.
func SendUpdate(ctx context.Context, connection *live.LiveConnection) error {
    return connection.Send(ctx, live.ClientEventUnionParam{OfSessionCommentaryAppend: &live.CommentaryAppendEventParam{
        EventID:      openai.String("result_123"),
        DelegationID: openai.String("item_9tA2bF3h7K9m2P5q8R1s4"),
        Content:      "The order shipped today and should arrive tomorrow.",
    }})
}

// [中文] 保留原例中客户端、输入和返回值的处理顺序;本段需结合所在小节的连接前提使用,未通过真实API调用验证。
// [中文] 本段为配置或调用片段,需结合外层程序与已建立连接使用;不作为独立完整程序宣称编译通过。
import com.openai.helpers.LiveConnection;
import com.openai.models.live.*;

public static void sendUpdate(LiveConnection connection) {
  connection.send(
      ClientEvent.ofSessionCommentaryAppend(
          CommentaryAppendEvent.builder()
              .eventId("result_123")
              .delegationId("item_9tA2bF3h7K9m2P5q8R1s4")
              .content("The order shipped today and should arrive tomorrow.")
              .build()));
}

## [中文] 把应向用户说明的已核实内容作为commentary追加;委派ID关联对应任务,会话级更新使用null,生成与实际播放仍需分别核实。
def send_update(connection)
  connection.send_event(type: "session.commentary.append", event_id: "result_123", delegation_id: "item_9tA2bF3h7K9m2P5q8R1s4", content: "The order shipped today and should arrive tomorrow.")
end

希望 GPT-Live 说给用户听的结果,用 session.commentary.append;模型被训练为可以改述文本。希望供后续回答使用、但不在到达时立即说出的事实或进度,用 session.thinking.append。可用同一个客户端委派 ID 发送多次更新。

内容限制、必填字段和确认时机见发送正确类型的更新。

从现有后端提示词开始

以已有文本智能体提示词为起点。任务指令和业务规则保留在后端,调整那些假定是文本聊天或可直接控制语音的指令,说明如何处理语音转录并返回有用结果。权限和必要确认由应用强制执行。

来源示例 13(text):

本例中文译文与说明:

语音对话上下文:
你正在协助实时语音对话中的助手。转录可能有错误、未说完的短语及后续纠正。使用最新上下文和已验证记录。必要细节仍不清楚时,询问该细节,不要猜测。

任务指令:
[你的任务指令、业务规则、可用工具及确认要求。]

返回结果:
返回相关事实、当前任务状态及下一步。只有工具或服务确认成功后才报告动作完成。结果不明确时,说明不确定性及需要检查什么。

## Voice conversation context
You are helping an assistant in a live voice conversation. Transcripts
can contain mistakes, unfinished phrases, and later corrections. Use
the latest context and verified records. If a needed detail is still
unclear, ask for that detail instead of guessing.

## Task instructions
[Your task instructions, business rules, available tools,
and confirmation requirements.]

## Return the result
Return the relevant facts, the task's current status, and the next step.
Report an action as complete after the tool or service confirms success.
If the outcome is unclear, state that and explain what needs to be checked.

大型结构化载荷、冗长工具输出和供界面展示的 Markdown 留在后端。只把相关事实交给 GPT-Live,由它组织表达。简明工具结果无需额外调用模型改写成口语。

客户端委派应直接向 GPT-Live 返回结果;Responses 委派则返回所需工具结果或批准,以继续后端工作。托管工具无需应用提供结果即可继续。

发送正确类型的更新

根据 GPT-Live 应如何使用内容选择事件:

要发送的内容 事件
面向实时对话的指令,例如告知声明或停止说话要求 session.instructions.append
供内部推理使用、追加时不说出但可用于相关问题的信息 session.thinking.append
希望模型说出并可改述的信息 session.commentary.append

三者均使用纯字符串 content,每次追加最多 500 个词元。必须包含 delegation_id:特定任务更新使用原客户端委派 ID,通用会话上下文使用 null。非空 ID 必须对应已知的客户端委派。指令仍作用于实时会话;带有 ID 不会把它变成独立的后端提示词。

开场问候时,在创建会话的 session.input 中加入开发者问候消息。session.started 后,在输入音频活动的情况下,通过 session.commentary.append 发送一次相同指令,使用唯一 event_id 和 delegation_id: null。模型可能改写文字,确认事件也不代表已发声或播放。精确措辞和确认送达所需的组合流程与应用控制播放,见来电者说话前问候。

追加指令可能打断模型当前语音或行为。需要引导对话时使用;相关工具或动作的阻断仍应由应用状态执行。

客户端管理任务时,发送不立即播报的进度:

来源示例 14(javascript):

程序文字译释41:正在查询周四可用性,尚未预订任何预约。

// [中文] 示例 14:发送正确类型的更新;以下保留本语言原始示例。
// [中文] 本段构造的事件类型:session.thinking.append;不要将构造载荷等同于收到成功确认。
// [中文] 沿原示例执行这些方法:connection.send;异步调用及事件接收顺序保留。
// [中文] 委派 ID 与响应、工具调用 ID 不同;追加上下文时,非空 delegation_id 须对应客户端委派,null 用于会话级上下文。
export function sendUpdate(connection) {
  connection.send({
    type: "session.thinking.append",
    event_id: "availability_progress",
    delegation_id: "item_123",
    content: "Checking Thursday availability. No appointment has been booked.",
  });
}

来源示例 15(python):

沿用程序文字译释41。

## [中文] 将事实或进度作为thinking上下文追加到会话;保留event_id与delegation_id的作用,不能把上下文送达确认当成已经播报。
from openai.resources.live.live import AsyncLiveConnection
from openai.resources.live.sideband import AsyncSidebandConnection


async def send_update(
    connection: AsyncLiveConnection | AsyncSidebandConnection,
    delegation_id: str,
) -> None:
    await connection.session.thinking.append(
        event_id="availability_progress",
        delegation_id=delegation_id,
        content="Checking Thursday availability. No appointment has been booked.",
    )

// [中文] 保留原例中客户端、输入和返回值的处理顺序;本段需结合所在小节的连接前提使用,未通过真实API调用验证。
// [中文] 本段为配置或调用片段,需结合外层程序与已建立连接使用;不作为独立完整程序宣称编译通过。
import (
    "context"
    "github.com/openai/openai-go/v3"
    "github.com/openai/openai-go/v3/live"
)

// SendUpdate requires a started Live session.
func SendUpdate(ctx context.Context, connection *live.LiveConnection) error {
    return connection.Send(ctx, live.ClientEventUnionParam{OfSessionThinkingAppend: &live.ThinkingAppendEventParam{
        EventID:      openai.String("availability_progress"),
        DelegationID: openai.String("item_123"),
        Content:      "Checking Thursday availability. No appointment has been booked.",
    }})
}

// [中文] 保留原例中客户端、输入和返回值的处理顺序;本段需结合所在小节的连接前提使用,未通过真实API调用验证。
// [中文] 本段为配置或调用片段,需结合外层程序与已建立连接使用;不作为独立完整程序宣称编译通过。
import com.openai.helpers.LiveConnection;
import com.openai.models.live.*;

public static void sendUpdate(LiveConnection connection) {
  connection.send(
      ClientEvent.ofSessionThinkingAppend(
          ThinkingAppendEvent.builder()
              .eventId("availability_progress")
              .delegationId("item_123")
              .content("Checking Thursday availability. No appointment has been booked.")
              .build()));
}

## [中文] 将事实或进度作为thinking上下文追加到会话;保留event_id与delegation_id的作用,不能把上下文送达确认当成已经播报。
def send_update(connection)
  connection.send_event(type: "session.thinking.append", event_id: "availability_progress", delegation_id: "item_123", content: "Checking Thursday availability. No appointment has been booked.")
end

预订已确认后,发送用户应听到的结果:

来源示例 16(javascript):

程序文字译释42:预约已确认,时间为周四下午两点。

// [中文] 示例 16:发送正确类型的更新;以下保留本语言原始示例。
// [中文] 本段构造的事件类型:session.commentary.append;不要将构造载荷等同于收到成功确认。
// [中文] 沿原示例执行这些方法:connection.send;异步调用及事件接收顺序保留。
// [中文] 委派 ID 与响应、工具调用 ID 不同;追加上下文时,非空 delegation_id 须对应客户端委派,null 用于会话级上下文。
export function sendUpdate(connection) {
  connection.send({
    type: "session.commentary.append",
    event_id: "appointment_result",
    delegation_id: "item_123",
    content: "Your appointment is confirmed for Thursday at 2:00 PM",
  });
}

来源示例 17(python):

沿用程序文字译释42。

## [中文] 把应向用户说明的已核实内容作为commentary追加;委派ID关联对应任务,会话级更新使用null,生成与实际播放仍需分别核实。
from openai.resources.live.live import AsyncLiveConnection
from openai.resources.live.sideband import AsyncSidebandConnection


async def send_update(
    connection: AsyncLiveConnection | AsyncSidebandConnection,
    delegation_id: str,
) -> None:
    await connection.session.commentary.append(
        event_id="appointment_result",
        delegation_id=delegation_id,
        content="Your appointment is confirmed for Thursday at 2:00 PM",
    )

// [中文] 保留原例中客户端、输入和返回值的处理顺序;本段需结合所在小节的连接前提使用,未通过真实API调用验证。
// [中文] 本段为配置或调用片段,需结合外层程序与已建立连接使用;不作为独立完整程序宣称编译通过。
import (
    "context"
    "github.com/openai/openai-go/v3"
    "github.com/openai/openai-go/v3/live"
)

// SendUpdate requires a started Live session.
func SendUpdate(ctx context.Context, connection *live.LiveConnection) error {
    return connection.Send(ctx, live.ClientEventUnionParam{OfSessionCommentaryAppend: &live.CommentaryAppendEventParam{
        EventID:      openai.String("appointment_result"),
        DelegationID: openai.String("item_123"),
        Content:      "Your appointment is confirmed for Thursday at 2:00 PM",
    }})
}

// [中文] 保留原例中客户端、输入和返回值的处理顺序;本段需结合所在小节的连接前提使用,未通过真实API调用验证。
// [中文] 本段为配置或调用片段,需结合外层程序与已建立连接使用;不作为独立完整程序宣称编译通过。
import com.openai.helpers.LiveConnection;
import com.openai.models.live.*;

public static void sendUpdate(LiveConnection connection) {
  connection.send(
      ClientEvent.ofSessionCommentaryAppend(
          CommentaryAppendEvent.builder()
              .eventId("appointment_result")
              .delegationId("item_123")
              .content("Your appointment is confirmed for Thursday at 2:00 PM")
              .build()));
}

## [中文] 把应向用户说明的已核实内容作为commentary追加;委派ID关联对应任务,会话级更新使用null,生成与实际播放仍需分别核实。
def send_update(connection)
  connection.send_event(type: "session.commentary.append", event_id: "appointment_result", delegation_id: "item_123", content: "Your appointment is confirmed for Thursday at 2:00 PM")
end

只有预订实际成功后才发送该结果。会话级指令使用 delegation_id: null 的 session.instructions.append。

例如,应用根据防护规则阻止请求后,可以重新引导对话:

来源示例 18(javascript):

程序文字译释43:停止讨论该请求,简短说明无法提供帮助,然后等待用户。

// [中文] 示例 18:发送正确类型的更新;以下保留本语言原始示例。
// [中文] 本段构造的事件类型:session.instructions.append;不要将构造载荷等同于收到成功确认。
// [中文] 沿原示例执行这些方法:connection.send;异步调用及事件接收顺序保留。
// [中文] 委派 ID 与响应、工具调用 ID 不同;追加上下文时,非空 delegation_id 须对应客户端委派,null 用于会话级上下文。
export function sendUpdate(connection) {
  connection.send({
    type: "session.instructions.append",
    event_id: "guardrail_block_17",
    delegation_id: null,
    content:
      "Stop speaking about that request. Briefly explain that you cannot help with it, then wait for the user.",
  });
}

来源示例 19(python):

程序文字译释44:停止讨论该请求,简短说明无法提供帮助……

程序文字译释45:……然后等待用户。

## [中文] 示例 19:发送正确类型的更新;以下保留本语言原始示例。
## [中文] 沿原示例执行这些方法:connection.session.instructions.append;异步调用及事件接收顺序保留。
## [中文] 委派 ID 与响应、工具调用 ID 不同;追加上下文时,非空 delegation_id 须对应客户端委派,null 用于会话级上下文。
from openai.resources.live.live import AsyncLiveConnection
from openai.resources.live.sideband import AsyncSidebandConnection


async def send_update(
    connection: AsyncLiveConnection | AsyncSidebandConnection,
) -> None:
    await connection.session.instructions.append(
        event_id="guardrail_block_17",
        delegation_id=None,
        content=(
            "Stop speaking about that request. Briefly explain that you cannot help "
            "with it, then wait for the user."
        ),
    )

// [中文] 保留原例中客户端、输入和返回值的处理顺序;本段需结合所在小节的连接前提使用,未通过真实API调用验证。
// [中文] 本段为配置或调用片段,需结合外层程序与已建立连接使用;不作为独立完整程序宣称编译通过。
import (
    "context"
    "github.com/openai/openai-go/v3"
    "github.com/openai/openai-go/v3/live"
    "github.com/openai/openai-go/v3/packages/param"
)

// SendUpdate requires a started Live session.
func SendUpdate(ctx context.Context, connection *live.LiveConnection) error {
    return connection.Send(ctx, live.ClientEventUnionParam{OfSessionInstructionsAppend: &live.InstructionsAppendEventParam{
        EventID:      openai.String("guardrail_block_17"),
        DelegationID: param.Null[string](),
        Content:      "Stop speaking about that request. Briefly explain that you cannot help with it, then wait for the user.",
    }})
}

// [中文] 保留原例中客户端、输入和返回值的处理顺序;本段需结合所在小节的连接前提使用,未通过真实API调用验证。
// [中文] 本段为配置或调用片段,需结合外层程序与已建立连接使用;不作为独立完整程序宣称编译通过。
import com.openai.core.JsonField;
import com.openai.helpers.LiveConnection;
import com.openai.models.live.*;

public static void sendUpdate(LiveConnection connection) {
  connection.send(
      ClientEvent.ofSessionInstructionsAppend(
          InstructionsAppendEvent.builder()
              .eventId("guardrail_block_17")
              .delegationId(JsonField.<String>ofNullable(null))
              .content(
                  "Stop speaking about that request. Briefly explain that you cannot help with it, then wait for the user.")
              .build()));
}

## [中文] 追加由应用编写的会话指令,区分会话级更新与任务委派;不要把不可信用户文本直接升级成应用指令。
def send_update(connection)
  connection.send_event(type: "session.instructions.append", event_id: "guardrail_block_17", delegation_id: nil, content: "Stop speaking about that request. Briefly explain that you cannot help with it, then wait for the user.")
end

该指令不会取消后端工作。应用仍需阻断相关操作并处理已经运行的工作。

对应确认分别为 session.thinking.appended、session.commentary.appended、session.instructions.appended。通过 client_event_id 匹配发出的 event_id。确认等待的是估计的上下文注入时机,而非说话或播放完成。时间与错误处理见上下文何时到达模型。

发送可供 GPT-Live 用于对话的事实和简短进度。session.thinking.append 的内容可能影响后续口头回复,秘密和私有后端推理应保存在应用中。

保持更新准确且有用

较长任务中,有用状态发生变化时才更新,例如步骤完成、延迟值得告知或需要用户回答问题。

客户端模式的后台进度使用 session.thinking.append;值得说给用户听的更新使用 session.commentary.append。

口头进度必须与已验证的任务状态一致:

状态 内容示例
仍在处理 “我正在查看可预约时间。”
已完成 “已为你预约周四下午两点。”
失败 “这个时间已无法预约。”
已确认取消 “你的预约已取消。”

用户更改请求时,更新应用中的活动任务。例如从周五改成周四后,后续工作使用周四,忽略已过时的周五请求结果。后端负责取消,并在确认成功后才告诉用户工作已取消。打断语音对话不会停止后端工作。

重试失败的工具调用前,检查原操作是否已发生。例如丢失响应不应造成重复预订。结果不明确时,应说明不确定性,并提供有用的下一步。

工具运行时抑制自动确认语

在client委派中,可在自动确认语生成之前发送静默上下文更新,取消待处理的自动确认。创建会话时设置delegation.acknowledgement_delay_ms,给应用留出发送更新的时间:

{
  "delegation": {
    "type": "client",
    "acknowledgement_delay_ms": 800
  }
}

收到session.delegation.created后,立即发送content为空的session.thinking.append,使用唯一event_id,并把event.delegation.id复制到delegation_id。不要先等待后端结果:

{
  "type": "session.thinking.append",
  "event_id": "event_quiet_progress_1",
  "delegation_id": "item_9tA2bF3h7K9m2P5q8R1s4",
  "content": ""
}

继续后端工作,结果验证完成后,用同一委派ID通过session.commentary.append提供需要播报的内容。thinking中加入“正在查询”等事实性进度也会取消待处理确认,但不会要求模型把该进度说出来。

任何thinking或commentary追加都会取消会话中所有待处理自动确认,包括其他委派的确认。它不会停止已生成音频,也不能阻止模型独立发言。延迟只控制何时请求自动确认,模型仍可能更早说话;具体契约见客户端委派和thinking参考。

用session.thinking.appended的client_event_id匹配发出的事件,只能确认上下文送达,不能证明静音。应测试实际音频;要求保证静音时,用应用控制播放。

共享界面上下文

向 GPT-Live 提供当前页面或任务、相关选中项和事实的简短摘要,帮助理解“这个选项”等指代。摘要直接来自应用状态,无需额外模型调用来格式化。

在会话启动及相关状态变化时发送。跳过未变化的更新,将快速连续变化合并成最新状态摘要。明确说明选择被修改:

  • 初始上下文:“用户正在查看餐厅预订:8月6日晚上7点,两位。尚未完成预订。”
  • 纠正:“当前选中时间已改为晚上8点,之前是晚上7点。”

两种委派模式均可使用 delegation_id: null 的 session.thinking.append 进行后台上下文更新。完整 HTML、DOM 树、大型 JSON 和交互日志保留在应用或后端。页面内容视为参考数据,而非指令。

接受键入输入

订单号等键入值,应作为用户提供的数据发送给后端,以使用精确文本。

Responses 委派中,为后端排入一条用户消息:

来源示例 20(javascript):

程序文字译释46:我的订单号是A0042。

// [中文] 示例 20:接受键入输入;以下保留本语言原始示例。
// [中文] 本段构造的事件类型:response.item.create;不要将构造载荷等同于收到成功确认。
// [中文] 沿原示例执行这些方法:connection.send;异步调用及事件接收顺序保留。
export function sendUpdate(connection) {
  connection.send({
    type: "response.item.create",
    event_id: "typed_order_number",
    item: {
      type: "message",
      role: "user",
      content: [
        {
          type: "input_text",
          text: "My order number is A0042.",
        },
      ],
    },
  });
}

来源示例 21(python):

沿用程序文字译释46。

## [中文] 示例 21:接受键入输入;以下保留本语言原始示例。
## [中文] 沿原示例执行这些方法:connection.response.item.create;异步调用及事件接收顺序保留。
from openai.resources.live.live import AsyncLiveConnection
from openai.resources.live.sideband import AsyncSidebandConnection
from openai.types.responses.response_input_item_param import ResponseInputItemParam


async def send_update(
    connection: AsyncLiveConnection | AsyncSidebandConnection,
) -> None:
    item: ResponseInputItemParam = {
        "type": "message",
        "role": "user",
        "content": [{"type": "input_text", "text": "My order number is A0042."}],
    }
    await connection.response.item.create(
        event_id="typed_order_number",
        item=item,
    )

// [中文] 保留原例中客户端、输入和返回值的处理顺序;本段需结合所在小节的连接前提使用,未通过真实API调用验证。
// [中文] 本段为配置或调用片段,需结合外层程序与已建立连接使用;不作为独立完整程序宣称编译通过。
import (
    "context"
    "github.com/openai/openai-go/v3"
    "github.com/openai/openai-go/v3/live"
    "github.com/openai/openai-go/v3/responses"
)

// SendUpdate requires a started Live session.
func SendUpdate(ctx context.Context, connection *live.LiveConnection) error {
    return connection.Send(ctx, live.ClientEventUnionParam{OfResponseItemCreate: &live.ResponseItemCreateEventParam{
        EventID: openai.String("typed_order_number"),
        Item:    responses.ResponseInputItemUnionParam{OfMessage: &responses.EasyInputMessageParam{Role: "user", Content: responses.EasyInputMessageContentUnionParam{OfInputItemContentList: responses.ResponseInputMessageContentListParam{responses.ResponseInputContentParamOfInputText("My order number is A0042.")}}}},
    }})
}

// [中文] 保留原例中客户端、输入和返回值的处理顺序;本段需结合所在小节的连接前提使用,未通过真实API调用验证。
// [中文] 本段为配置或调用片段,需结合外层程序与已建立连接使用;不作为独立完整程序宣称编译通过。
import com.openai.helpers.LiveConnection;
import com.openai.models.live.*;
import com.openai.models.responses.*;

public static void sendUpdate(LiveConnection connection) {
  connection.send(
      ClientEvent.ofResponseItemCreate(
          ResponseItemCreateEvent.builder()
              .eventId("typed_order_number")
              .item(
                  EasyInputMessage.builder()
                      .role(EasyInputMessage.Role.USER)
                      .contentOfResponseInputMessageContentList(
                          java.util.List.of(
                              ResponseInputContent.ofInputText(
                                  ResponseInputText.builder()
                                      .text("My order number is A0042.")
                                      .build())))
                      .build())
              .build()));
}

## [中文] 保留原例中客户端、输入和返回值的处理顺序;本段需结合所在小节的连接前提使用,未通过真实API调用验证。
def send_update(connection)
  connection.send_event(
    type: "response.item.create", event_id: "typed_order_number", item: {
      type: "message",
      role: "user",
      content: [
        {
          type: "input_text",
          text: "My order number is A0042."
        }
      ]
    }
  )
end

准备好运行或继续后端时发送 response.create。如正等待函数结果,先返回全部必要结果。排入文本本身不会取消已运行工作。

客户端委派中,把键入值直接发给处理对话的后端。若是在纠正活动任务,应更新该任务,避免重复启动相同工作。可以用 session.thinking.append 将简短事实摘要同步到实时会话,或用 session.commentary.append 提供用户应听到的结果。

添加图像与视觉上下文

要帮助来电者讨论照片或屏幕,由应用把图像及相关上下文发给具备视觉能力的后端。后端理解图像,再返回 GPT-Live 可用于对话的相关文字。Live 音频前端不直接接收图像。

Responses 委派中,配置支持视觉的后端模型,通过 response.item.create 排入受支持的 Responses 图像输入项,再发送 response.create 运行或恢复后端。继续之前,返回全部必要的待处理工具结果和批准。见处理 Responses 委派。

客户端委派中,将视觉输入连同相关对话和应用状态发给负责委派请求的后端,通过客户端结果流程返回精简结论。

后端图像输入与 session.input 分开:后者在启动时为 Live 前端提供文本历史。图像格式与模型限制见图像与视觉。

降低后端延迟

缩短从请求后端工作到获得对话可用结果的时间。测量各阶段延迟以定位瓶颈。在相同场景比较有用口头回应的到达时间和任务成功率,评估指导见语音智能体评估 Cookbook。

Responses 委派

Live 管理与 Responses 的持久 WebSocket 连接,并提前准备已知请求配置。活动连接和状态支持时,也可复用先前响应状态。使用自己的工作负载测量响应时间与缓存用量,观察效果。

通过 delegation.responses 调整后端:

  • model:独立于语音模型,选择负责推理与工具选择的模型。
  • reasoning.effort:用模型支持的值平衡推理时间与任务质量。
  • service_tier:按模型支持与项目权限选择 auto、default、flex 或 priority。auto 遵循项目配置。应评估所选层级的性能与费用。

运行期间通过 session.update 更新支持的设置。即使 Live 管理 Responses 连接,自定义工具仍在应用中运行;慢服务调用、排队和工具结果缓冲都可能延迟回答。及时返回每个必要工具结果,并继续后端响应。

客户端委派

从收到委派到返回结果的整个路径由应用负责。可在语音会话运行期间提前准备:

  • 复用后端连接。跨委派保持 API 客户端和连接池活动。反复调用 Responses 时,可考虑持久的 Responses WebSocket。
  • 准备已知配置。在首次请求需要之前初始化指令、工具与连接。Responses WebSocket 模式也支持生成前预热已知请求状态,遵循其设置指南。
  • 流式返回有用结果。用 session.commentary.append 返回连贯且经过验证的片段,静默进度用 session.thinking.append。保留客户端委派 ID 和每次 500 个词元限制。私有推理留在后端,宣布成功前先确认操作。
  • 保持可复用输入稳定。保留指令、工具定义及顺序、未变化的历史前缀。后端支持缓存与续接时,把新信息追加在可复用内容之后。
  • 转发完整且有用的更新。文字足够独立理解时立即发送。让后端标记更新是进度还是结果,以便应用选择追加事件。若以文本前缀区分,等前缀接收完整后再转发。

与 Responses 委派比较时,应测量首次有用口头回答的时间。

响应转录片段

应用处理转录片段是可选的,两种委派模式都可使用。用户和助手的转录片段通过 WebSocket 或 WebRTC 数据通道到达。可用应用逻辑或轻量模型,在委派事件到达前开始工作;也可由转录直接触发应用负责的工作。

此模式可用于:

  • 减少等待。信息足够后先做推测性查询,例如用户继续描述偏好时,预先检查可用性。
  • 运行防护规则。检查持续增长的转录,发现需要干预的请求或回复。见应用对话防护规则。
  • 调整对话。发现暗示困惑或沮丧的措辞后,调整体验或发送针对性指令。
  • 更新界面。突出相关控件、填充建议字段,或在结果可用时显示。

浏览器应用用 WebRTC 数据通道处理字幕和本地界面更新。若服务器处理转录,以运行防护规则、轻量模型检查或推测性工具调用,应使用旁路 WebSocket,直接接收事件并引导同一 GPT-Live 会话。

有有意义的新信息时处理累计文本。片段可能不完整,后续讲话也可能更改请求。丢弃过时结果,与后续委派工作协调以防重复操作;产生实际后果的操作前,仍执行通常的权限与确认检查。

用匹配更新类型的追加事件,把结论或指令发回 GPT-Live。客户端委派之外启动的工作使用 delegation_id: null。界面变更、工具执行与取消由应用管理。

共用优化

两种模式都受益于相同后端改进:

  • 按任务选择模型和推理强度。比较能满足准确性要求的配置;低推理强度也能可靠完成任务时就使用较低值。
  • 保持回答简洁。只返回 GPT-Live 继续对话需要的事实与状态,避免冗长解释,以及仅为口语改写而增加模型调用。
  • 降低工具延迟和不必要调用。输入就绪后启动获授权工作,在仍有效时复用结果,避免重复已完成查询。
  • 并发运行独立工作。独立查询可同时执行,操作仍要遵守依赖和必要确认。parallel_tool_calls 允许模型请求多次调用,自定义函数的调度和执行仍由应用负责。

通用 Responses 指导见延迟优化,稳定输入复用见提示词缓存。

验证完整交互

既要验证后端完成了预期操作,也要验证客户端播放了预期语音结果。例如,预订成功后,同时检查预订记录和实际播放的音频。后端可能已完成,而语音答案被打断,因此两种结果应分别测试。

在 GPT-Live 委派 ID 之外,为每个应用操作记录独立操作 ID,为每次请求变更记录任务修订号。借此在重连或重试后识别已完成工作,并丢弃过时请求结果。

可重复测试见评估语音智能体。已有 Realtime 工具循环或串联后端的迁移见迁移到 GPT-Live。

以上内容是否对您有帮助:
在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号