Skip to content

Commit 76c6455

Browse files
authored
Merge branch 'main' into changeset-release/main
2 parents 28f8ad4 + c248a7d commit 76c6455

File tree

5 files changed

+24
-1
lines changed

5 files changed

+24
-1
lines changed

.changeset/better-kids-trade.md

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+
Fix #138 by checking the unexpected absence of state.currentAgent.handoffs

.changeset/poor-regions-try.md

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+
Fix a bug where some of the exceptions thrown from runImplementation.ts could be unhandled

.changeset/upset-baboons-shop.md

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+
Fix #138 by checking the unexpected absence of currentAgent.handoffs

packages/agents-core/src/result.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,9 @@ export class StreamedRunResult<
308308
}
309309
this.#error = err;
310310
this.#completedPromiseReject?.(err);
311+
this.#completedPromise.catch((e) => {
312+
logger.debug(`Resulted in an error: ${e}`);
313+
});
311314
}
312315

313316
/**

packages/agents-core/src/run.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,12 @@ export class Runner extends RunHooks<any, AgentOutputType<unknown>> {
302302
}
303303

304304
if (state._currentStep.type === 'next_step_run_again') {
305-
const handoffs = state._currentAgent.handoffs.map(getHandoff);
305+
const handoffs: Handoff<any>[] = [];
306+
if (state._currentAgent.handoffs) {
307+
// While this array usually must not be undefined,
308+
// we've added this check to prevent unexpected runtime errors like https://github.com/openai/openai-agents-js/issues/138
309+
handoffs.push(...state._currentAgent.handoffs.map(getHandoff));
310+
}
306311

307312
if (!state._currentAgentSpan) {
308313
const handoffNames = handoffs.map((h) => h.agentName);

0 commit comments

Comments
 (0)