Skip to content

Commit 426ad73

Browse files
authored
fix(agents-core): ensure handoff messages use valid JSON (#37)
* fix(core): reference schema version constant * chore(core): add changeset for schema version fix * changeset: fix invalid JSON in getTransferMessage * fix(agents-core): ensure handoff messages use valid JSON * Delete .changeset/fix-schema-version-serialization.md
1 parent 0f4850e commit 426ad73

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@openai/agents-core': patch
3+
---
4+
5+
ensure getTransferMessage returns valid JSON

packages/agents-core/src/handoff.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export type HandoffInputFilter = (input: HandoffInputData) => HandoffInputData;
4747
export function getTransferMessage<TContext, TOutput extends AgentOutputType>(
4848
agent: Agent<TContext, TOutput>,
4949
) {
50-
return `{'assistant': '${agent.name}'}`;
50+
return JSON.stringify({ assistant: agent.name });
5151
}
5252

5353
/**

packages/agents-core/test/handoffs.test.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,17 @@ describe('Agent + handoffs', () => {
6969
outputType: z.object({ a: z.string() }),
7070
}),
7171
);
72-
expect(result).toBe("{'assistant': 'Agent A'}");
72+
expect(result).toBe('{"assistant":"Agent A"}');
73+
});
74+
75+
it('getTransferMessage produces valid JSON', () => {
76+
const result = getTransferMessage(
77+
new Agent({
78+
name: 'Agent A',
79+
outputType: z.object({ a: z.string() }),
80+
}),
81+
);
82+
expect(JSON.parse(result)).toEqual({ assistant: 'Agent A' });
7383
});
7484

7585
it('Handoff#getHandoffAsFunctionTool', async () => {

0 commit comments

Comments
 (0)