Hello everyone. I use OpenAI Agents SDK but I have a problem. Even if I define an outputType, model rarely gives outputs don’t align with the ouputType defined. This causes my backend service to go down because of an unhandled exception.
export const Answer = catchAsync(async (req: CustomRequestChatbot, res: Response) => {
...
...
...
const runner = new Runner({
workflowName: 'mas_storefront',
groupId: chatSession.sessionId,
traceId: trace_${message.id},
tracingDisabled: false
})
const result = await runner.run(
startAgent,
message.message.content,
{
context: context,
previousResponseId: chatSession.lastResponseId,
stream: true,
},
);
for await (const event of result.toTextStream()) {
res.write(event);
}
res.end();
...
...
...
}
Unhandled rejection ModelBehaviorError: Invalid output type
at executeToolsAndSideEffects (/app/node_modules/@openai/agents-core/src/runImplementation.ts:614:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Runner.#runStreamLoop (/app/node_modules/@openai/agents-core/src/run.ts:781:30) {
catchAsync doesn’t catch the error. I also tried to wrap .run() and .toTextStream() blocks with try/catch before, but it also didin’t work. I couldn’t find a way to handle this error. My backend is crushing every time API returns a response in the wrong format.
Also is it normal for API to give out of format response occasionally?