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/shiny-months-smoke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@openai/agents-core": patch
---

Add run context to handoff input filter to align with Python SDK
4 changes: 3 additions & 1 deletion packages/agents-core/src/extensions/handoffFilters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -37,6 +38,7 @@ export function removeAllTools(
inputHistory: filteredHistory,
preHandoffItems: filteredPreHandoffItems,
newItems: filteredNewItems,
runContext,
};
}

Expand Down
5 changes: 5 additions & 0 deletions packages/agents-core/src/handoff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any>;
Copy link
Member Author

Choose a reason for hiding this comment

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

before merging this PR, check the review result at openai/openai-agents-python#1302; the name should be consistent

Copy link
Member Author

Choose a reason for hiding this comment

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

ok, the name is run_context in python; so this is ready to go

};

export type HandoffInputFilter = (input: HandoffInputData) => HandoffInputData;
Expand Down
1 change: 1 addition & 0 deletions packages/agents-core/src/runImplementation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1025,6 +1025,7 @@ export async function executeHandoffCalls<
: originalInput,
preHandoffItems: [...preStepItems],
newItems: [...newStepItems],
runContext,
};

const filtered = inputFilter(handoffInputData);
Expand Down