From d63ae1585b8b29542a085dc465ec6c3ee3735560 Mon Sep 17 00:00:00 2001 From: whoiskatrin Date: Thu, 5 Jun 2025 10:53:20 +0100 Subject: [PATCH 1/2] 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/2] 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.