diff --git a/.changeset/shiny-months-smoke.md b/.changeset/shiny-months-smoke.md new file mode 100644 index 00000000..8240cb89 --- /dev/null +++ b/.changeset/shiny-months-smoke.md @@ -0,0 +1,5 @@ +--- +"@openai/agents-core": patch +--- + +Add run context to handoff input filter to align with Python SDK diff --git a/packages/agents-core/src/extensions/handoffFilters.ts b/packages/agents-core/src/extensions/handoffFilters.ts index 0e00a165..236efea2 100644 --- a/packages/agents-core/src/extensions/handoffFilters.ts +++ b/packages/agents-core/src/extensions/handoffFilters.ts @@ -24,7 +24,8 @@ const TOOL_TYPES = new Set([ export function removeAllTools( handoffInputData: HandoffInputData, ): HandoffInputData { - const { inputHistory, preHandoffItems, newItems } = handoffInputData; + const { inputHistory, preHandoffItems, newItems, runContext } = + handoffInputData; const filteredHistory = Array.isArray(inputHistory) ? removeToolTypesFromInput(inputHistory) @@ -37,6 +38,7 @@ export function removeAllTools( inputHistory: filteredHistory, preHandoffItems: filteredPreHandoffItems, newItems: filteredNewItems, + runContext, }; } diff --git a/packages/agents-core/src/handoff.ts b/packages/agents-core/src/handoff.ts index c70012fa..729d4ff4 100644 --- a/packages/agents-core/src/handoff.ts +++ b/packages/agents-core/src/handoff.ts @@ -34,6 +34,11 @@ export type HandoffInputData = { * handoff and the tool output message representing the response from the handoff output. */ newItems: RunItem[]; + /** + * The context of the handoff. + * Note that, since this property was added later on, it's optional to pass from users. + */ + runContext?: RunContext; }; export type HandoffInputFilter = (input: HandoffInputData) => HandoffInputData; diff --git a/packages/agents-core/src/runImplementation.ts b/packages/agents-core/src/runImplementation.ts index 2a32c0f0..4136d479 100644 --- a/packages/agents-core/src/runImplementation.ts +++ b/packages/agents-core/src/runImplementation.ts @@ -1025,6 +1025,7 @@ export async function executeHandoffCalls< : originalInput, preHandoffItems: [...preStepItems], newItems: [...newStepItems], + runContext, }; const filtered = inputFilter(handoffInputData);