From d63ae1585b8b29542a085dc465ec6c3ee3735560 Mon Sep 17 00:00:00 2001 From: whoiskatrin Date: Thu, 5 Jun 2025 10:53:20 +0100 Subject: [PATCH 1/5] fix(core): reference schema version constant --- packages/agents-core/src/runState.ts | 4 ++-- packages/agents-core/test/runState.test.ts | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/agents-core/src/runState.ts b/packages/agents-core/src/runState.ts index 1022180e..9ab5d928 100644 --- a/packages/agents-core/src/runState.ts +++ b/packages/agents-core/src/runState.ts @@ -37,7 +37,7 @@ import { safeExecute } from './utils/safeExecute'; * run state is compatible with the current version of the SDK. * If anything in this schema changes, the version will have to be incremented. */ -const CURRENT_SCHEMA_VERSION = '1.0' as const; +export const CURRENT_SCHEMA_VERSION = '1.0' as const; const $schemaVersion = z.literal(CURRENT_SCHEMA_VERSION); const serializedAgentSchema = z.object({ @@ -349,7 +349,7 @@ export class RunState> { */ toJSON(): z.infer { const output = { - $schemaVersion: '1.0', + $schemaVersion: CURRENT_SCHEMA_VERSION, currentTurn: this._currentTurn, currentAgent: { name: this._currentAgent.name, diff --git a/packages/agents-core/test/runState.test.ts b/packages/agents-core/test/runState.test.ts index 3f07fc1a..6ca4d12f 100644 --- a/packages/agents-core/test/runState.test.ts +++ b/packages/agents-core/test/runState.test.ts @@ -4,6 +4,7 @@ import { buildAgentMap, deserializeModelResponse, deserializeItem, + CURRENT_SCHEMA_VERSION, } from '../src/runState'; import { RunContext } from '../src/runContext'; import { Agent } from '../src/agent'; @@ -35,7 +36,7 @@ describe('RunState', () => { const agent = new Agent({ name: 'Agent1' }); const state = new RunState(context, 'input1', agent, 2); const json = state.toJSON(); - expect(json.$schemaVersion).toBe('1.0'); + expect(json.$schemaVersion).toBe(CURRENT_SCHEMA_VERSION); expect(json.currentTurn).toBe(0); expect(json.currentAgent).toEqual({ name: 'Agent1' }); expect(json.originalInput).toEqual('input1'); @@ -65,7 +66,7 @@ describe('RunState', () => { expect( async () => await RunState.fromString(agent, JSON.stringify(jsonVersion)), ).rejects.toThrow( - 'Run state schema version 0.1 is not supported. Please use version 1.0', + `Run state schema version 0.1 is not supported. Please use version ${CURRENT_SCHEMA_VERSION}`, ); }); From 0f3a85b85587fa692c652a7a4791042daf6738de Mon Sep 17 00:00:00 2001 From: whoiskatrin Date: Thu, 5 Jun 2025 17:47:13 +0100 Subject: [PATCH 2/5] chore(core): add changeset for schema version fix --- .changeset/fix-schema-version-serialization.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/fix-schema-version-serialization.md diff --git a/.changeset/fix-schema-version-serialization.md b/.changeset/fix-schema-version-serialization.md new file mode 100644 index 00000000..c1acc5b5 --- /dev/null +++ b/.changeset/fix-schema-version-serialization.md @@ -0,0 +1,5 @@ +--- +'@openai/agents-core': patch +--- + +Export CURRENT_SCHEMA_VERSION constant and use it when serializing run state. From fa8b0c114cf53008a9da39c6ed124cfba26dcd87 Mon Sep 17 00:00:00 2001 From: katereznykova Date: Fri, 6 Jun 2025 10:36:27 +0100 Subject: [PATCH 3/5] changeset: fix invalid JSON in getTransferMessage --- .changeset/social-mirrors-juggle.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/social-mirrors-juggle.md diff --git a/.changeset/social-mirrors-juggle.md b/.changeset/social-mirrors-juggle.md new file mode 100644 index 00000000..3c331202 --- /dev/null +++ b/.changeset/social-mirrors-juggle.md @@ -0,0 +1,5 @@ +--- +'@openai/agents-core': patch +--- + +ensure getTransferMessage returns valid JSON From e3bb872cb469ec9e2616200d876b62dfa57038f7 Mon Sep 17 00:00:00 2001 From: katereznykova Date: Fri, 6 Jun 2025 10:41:07 +0100 Subject: [PATCH 4/5] fix(agents-core): ensure handoff messages use valid JSON --- packages/agents-core/src/handoff.ts | 2 +- packages/agents-core/test/handoffs.test.ts | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/agents-core/src/handoff.ts b/packages/agents-core/src/handoff.ts index 40b9d18a..9e97ea44 100644 --- a/packages/agents-core/src/handoff.ts +++ b/packages/agents-core/src/handoff.ts @@ -47,7 +47,7 @@ export type HandoffInputFilter = (input: HandoffInputData) => HandoffInputData; export function getTransferMessage( agent: Agent, ) { - return `{'assistant': '${agent.name}'}`; + return JSON.stringify({ assistant: agent.name }); } /** diff --git a/packages/agents-core/test/handoffs.test.ts b/packages/agents-core/test/handoffs.test.ts index 38132dbd..96e22fae 100644 --- a/packages/agents-core/test/handoffs.test.ts +++ b/packages/agents-core/test/handoffs.test.ts @@ -69,7 +69,17 @@ describe('Agent + handoffs', () => { outputType: z.object({ a: z.string() }), }), ); - expect(result).toBe("{'assistant': 'Agent A'}"); + expect(result).toBe('{"assistant":"Agent A"}'); + }); + + it('getTransferMessage produces valid JSON', () => { + const result = getTransferMessage( + new Agent({ + name: 'Agent A', + outputType: z.object({ a: z.string() }), + }), + ); + expect(JSON.parse(result)).toEqual({ assistant: 'Agent A' }); }); it('Handoff#getHandoffAsFunctionTool', async () => { From 35ce3fda125b94d03f6fa3b894abff6872007d56 Mon Sep 17 00:00:00 2001 From: whoiskatrin Date: Fri, 6 Jun 2025 10:44:16 +0100 Subject: [PATCH 5/5] Delete .changeset/fix-schema-version-serialization.md --- .changeset/fix-schema-version-serialization.md | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 .changeset/fix-schema-version-serialization.md diff --git a/.changeset/fix-schema-version-serialization.md b/.changeset/fix-schema-version-serialization.md deleted file mode 100644 index c1acc5b5..00000000 --- a/.changeset/fix-schema-version-serialization.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -'@openai/agents-core': patch ---- - -Export CURRENT_SCHEMA_VERSION constant and use it when serializing run state.