Skip to content

Commit ea0e940

Browse files
authored
If state is empty on run_finished event, don't trigger a state update (#345)
* If state is empty on run_finished event, don't trigger a state update * update test
1 parent 01407ff commit ea0e940

File tree

2 files changed

+26
-21
lines changed

2 files changed

+26
-21
lines changed

typescript-sdk/packages/client/src/agent/__tests__/legacy-bridged.test.ts

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ describe("AbstractAgent.legacy_to_be_removed_runAgentBridged", () => {
160160
const legacyEvents = await lastValueFrom(legacy$.pipe(toArray()));
161161

162162
// Verify events are in correct legacy format
163-
expect(legacyEvents).toHaveLength(4); // Start, Content, End, AgentStateMessage
163+
expect(legacyEvents).toHaveLength(3); // Start, Content, End
164164

165165
// TextMessageStart
166166
expect(legacyEvents[0]).toMatchObject({
@@ -182,12 +182,12 @@ describe("AbstractAgent.legacy_to_be_removed_runAgentBridged", () => {
182182
});
183183

184184
// Final AgentStateMessage
185-
expect(legacyEvents[3]).toMatchObject({
186-
type: "AgentStateMessage",
187-
threadId: "test-thread-id",
188-
agentName: "test-agent-id",
189-
active: false,
190-
});
185+
// expect(legacyEvents[3]).toMatchObject({
186+
// type: "AgentStateMessage",
187+
// threadId: "test-thread-id",
188+
// agentName: "test-agent-id",
189+
// active: false,
190+
// });
191191
});
192192

193193
it("should pass configuration to the underlying run method", async () => {
@@ -304,7 +304,7 @@ describe("AbstractAgent.legacy_to_be_removed_runAgentBridged", () => {
304304
const legacyEvents = await lastValueFrom(legacy$.pipe(toArray()));
305305

306306
// Verify events are in correct legacy format
307-
expect(legacyEvents).toHaveLength(4); // Start, Content, End, AgentStateMessage
307+
expect(legacyEvents).toHaveLength(3); // Start, Content, End
308308

309309
// TextMessageStart
310310
expect(legacyEvents[0]).toMatchObject({
@@ -326,12 +326,12 @@ describe("AbstractAgent.legacy_to_be_removed_runAgentBridged", () => {
326326
});
327327

328328
// Final AgentStateMessage
329-
expect(legacyEvents[3]).toMatchObject({
330-
type: "AgentStateMessage",
331-
threadId: "test-thread-id",
332-
agentName: "test-agent-id",
333-
active: false,
334-
});
329+
// expect(legacyEvents[3]).toMatchObject({
330+
// type: "AgentStateMessage",
331+
// threadId: "test-thread-id",
332+
// agentName: "test-agent-id",
333+
// active: false,
334+
// });
335335
});
336336

337337
it("should transform tool call events with results into legacy events with correct tool name", async () => {
@@ -348,7 +348,7 @@ describe("AbstractAgent.legacy_to_be_removed_runAgentBridged", () => {
348348
const legacyEvents = await lastValueFrom(legacy$.pipe(toArray()));
349349

350350
// Verify events are in correct legacy format
351-
expect(legacyEvents).toHaveLength(5); // ActionExecutionStart, ActionExecutionArgs, ActionExecutionEnd, ActionExecutionResult, AgentStateMessage
351+
expect(legacyEvents).toHaveLength(4); // ActionExecutionStart, ActionExecutionArgs, ActionExecutionEnd, ActionExecutionResult
352352

353353
// ActionExecutionStart
354354
expect(legacyEvents[0]).toMatchObject({
@@ -379,11 +379,11 @@ describe("AbstractAgent.legacy_to_be_removed_runAgentBridged", () => {
379379
});
380380

381381
// Final AgentStateMessage
382-
expect(legacyEvents[4]).toMatchObject({
383-
type: "AgentStateMessage",
384-
threadId: "test-thread-id",
385-
agentName: "test-agent-id",
386-
active: false,
387-
});
382+
// expect(legacyEvents[4]).toMatchObject({
383+
// type: "AgentStateMessage",
384+
// threadId: "test-thread-id",
385+
// agentName: "test-agent-id",
386+
// active: false,
387+
// });
388388
});
389389
});

typescript-sdk/packages/client/src/legacy/convert.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,11 @@ export const convertToLegacyEvents =
304304
currentState.messages = syncedMessages;
305305
}
306306

307+
// Only do an update if state is not empty
308+
if (Object.keys(currentState).length === 0) {
309+
return [];
310+
}
311+
307312
return [
308313
{
309314
type: LegacyRuntimeEventTypes.enum.AgentStateMessage,

0 commit comments

Comments
 (0)