fix(plugin-openai): skip agent_config_update items in realtime chat-ctx sync#1856
fix(plugin-openai): skip agent_config_update items in realtime chat-ctx sync#1856tsushanth wants to merge 2 commits into
Conversation
…tx sync
`AgentActivity` inserts `agent_config_update` chat items on enter and on
tool / instructions changes. The OpenAI Realtime plugin's chat-context
sync (`createChatCtxUpdateEvents`) fed these directly into
`livekitItemToOpenAIItem`, which has no case for `agent_config_update`
and throws `Unsupported item type: agent_config_update`. The throw is
caught upstream — non-fatal — but the never-played-message sync bails
mid-way, leaving degraded post-tool speech behavior and missing
transcript items.
Filter `agent_config_update` items out of `newChatCtx.items` before the
diff. Mirrors the non-realtime path's `chatCtx.copy({ excludeConfigUpdate: true })`
(agent_activity.ts:666) and the wire filter in `remote_session.ts`
(`item.type !== 'agent_config_update'`).
Two regression tests added in `realtime_model.test.ts`:
- Mixed ChatContext (system + agent_config_update + user) emits create
events only for system and user.
- ChatContext containing only `agent_config_update` items returns no
events and no longer throws.
Fixes livekit#1855.
🦋 Changeset detectedLatest commit: 9957723 The changes in this PR will be included in the next version bump. This PR includes changesets to release 35 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Devin Review on livekit#1856 flagged that `livekitItemToOpenAIItem`'s default arm also throws for `agent_handoff` items — which are part of the `ChatItem` union but not handled in the realtime conversion. The non-realtime path already excludes both via `chatCtx.copy({ excludeHandoff: true, excludeConfigUpdate: true })` (agent_activity.ts:666). Filter `agent_handoff` alongside `agent_config_update` in the realtime sync as defense-in-depth so the symptom doesn't re-emerge if a future code path ever surfaces handoff items to the realtime session. Added a regression test that pushes an `AgentHandoffItem` next to a user message and asserts the user item still gets a create event while the handoff id is absent.
|
Thanks @devin-ai-integration — good catch. Filtered |
Summary
Fixes #1855 — when an
Agentis constructed with tools or instructions,AgentActivityinserts internalagent_config_updatechat items on enter and on tool / instructions changes (agents/src/voice/agent_activity.ts:520, :875). The OpenAI Realtime plugin's chat-context sync (createChatCtxUpdateEventsinplugins/openai/src/realtime/realtime_model.ts:662) feeds these intolivekitItemToOpenAIItem, which has noagent_config_updatecase and throws:The throw is caught upstream — non-fatal — but the never-played-message sync bails mid-iteration, leading to degraded post-tool speech behavior and missing transcript items on those turns (reporter's observation).
Fix
Filter
agent_config_updateitems out ofnewChatCtx.itemsinsidecreateChatCtxUpdateEventsbefore the diff is computed:This mirrors the existing patterns elsewhere in the framework:
agent_activity.ts:666already uses.copy({ excludeInstructions: true, excludeHandoff: true, excludeConfigUpdate: true })when handing context to non-realtime LLMs.remote_session.ts:406already filtersitem.type !== 'agent_config_update'before transport.livekitItemToOpenAIItem's defensivethrowis left in place — it's still the correct behavior for unknown item types reaching the converter through other code paths.Tests
Two new cases in
plugins/openai/src/realtime/realtime_model.test.ts:createChatCtxUpdateEventsemitsconversation.item.createonly for the system and user messages; the config update id is absent from the events.agent_config_updateitems — resolves to[](no events, no throw).Reverse-verified: both new tests fail RED with the exact reporter error against
upstream/main, pass after the filter is added.Local:
pnpm vitest run plugins/openai/src/realtime/realtime_model.test.ts→ 35/35 green.pnpm lintclean (36/36 packages). Pre-existing@livekit/local-inference/@livekit/agents-plugins-testimport errors duringpnpm build:agentsare unrelated and reproduce onupstream/mainwith this change stashed.Changeset:
@livekit/agents-plugin-openaipatch.Breaking changes
None.
agent_config_updateitems had no OpenAI Realtime representation to begin with — the only reachable behavior change is no longer throwing on them during sync.