Skip to content
Merged
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/fix-schema-version-serialization.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@openai/agents-core': patch
---

Export CURRENT_SCHEMA_VERSION constant and use it when serializing run state.
4 changes: 2 additions & 2 deletions packages/agents-core/src/runState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -349,7 +349,7 @@ export class RunState<TContext, TAgent extends Agent<any, any>> {
*/
toJSON(): z.infer<typeof SerializedRunState> {
const output = {
$schemaVersion: '1.0',
$schemaVersion: CURRENT_SCHEMA_VERSION,
currentTurn: this._currentTurn,
currentAgent: {
name: this._currentAgent.name,
Expand Down
5 changes: 3 additions & 2 deletions packages/agents-core/test/runState.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
buildAgentMap,
deserializeModelResponse,
deserializeItem,
CURRENT_SCHEMA_VERSION,
} from '../src/runState';
import { RunContext } from '../src/runContext';
import { Agent } from '../src/agent';
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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}`,
);
});

Expand Down