Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/calm-contexts-sync.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@livekit/agents-plugin-openai': patch
---

Ignore internal agent handoff and configuration records when synchronizing realtime chat contexts.
19 changes: 19 additions & 0 deletions plugins/openai/src/realtime/realtime_model.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,25 @@ describe('RealtimeSession chat context update events', () => {
expect((events[0] as api_proto.ConversationItemDeleteEvent).item_id).toBe('item_1');
expect((events[1] as api_proto.ConversationItemCreateEvent).item.id).toBe('item_1');
});

it('ignores internal agent items', async () => {
const remoteMessage = llm.ChatMessage.create({
id: 'item_1',
role: 'assistant',
content: ['hello'],
});
const session = createChatCtxUpdateSession(remoteMessage);

const events = await session.createChatCtxUpdateEvents(
new llm.ChatContext([
remoteMessage,
llm.AgentConfigUpdate.create({ instructions: 'updated instructions' }),
llm.AgentHandoffItem.create({ oldAgentId: 'agent_1', newAgentId: 'agent_2' }),
]),
);

expect(events).toEqual([]);
});
});

describe('RealtimeSession.updateOptions', () => {
Expand Down
2 changes: 1 addition & 1 deletion plugins/openai/src/realtime/realtime_model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ export class RealtimeSession extends llm.RealtimeSession {
chatCtx: llm.ChatContext,
addMockAudio: boolean = false,
): Promise<(api_proto.ConversationItemCreateEvent | api_proto.ConversationItemDeleteEvent)[]> {
const newChatCtx = chatCtx.copy();
const newChatCtx = chatCtx.copy({ excludeHandoff: true, excludeConfigUpdate: true });
if (addMockAudio) {
newChatCtx.items.push(createMockAudioItem());
} else {
Expand Down