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/social-mirrors-juggle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@openai/agents-core': patch
---

ensure getTransferMessage returns valid JSON
2 changes: 1 addition & 1 deletion packages/agents-core/src/handoff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export type HandoffInputFilter = (input: HandoffInputData) => HandoffInputData;
export function getTransferMessage<TContext, TOutput extends AgentOutputType>(
agent: Agent<TContext, TOutput>,
) {
return `{'assistant': '${agent.name}'}`;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only reason why we went with this string is to align with Python SDK. As long as the standard JSON format works without any issues here, I think it should be fine to change this. @dkundel-openai thoughts?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fine to change

return JSON.stringify({ assistant: agent.name });
}

/**
Expand Down
12 changes: 11 additions & 1 deletion packages/agents-core/test/handoffs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down