-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Nest handoff history by default #1996
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 20 commits
e895a77
94447af
98d154c
52f0a1e
71df74b
17aa135
6d7f9e4
3364202
b22eeb2
fff4d34
c6e0f50
f3c7048
19a7cf8
411d396
0276722
8746b81
3694c7e
298ef8a
adf0c66
0a70cf4
6590319
7fe0da0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,6 +25,8 @@ This version doesn’t introduce any visible breaking changes, but it includes n | |
|
|
||
| - Added support for `RealtimeRunner` to handle [SIP protocol connections](https://platform.openai.com/docs/guides/realtime-sip) | ||
| - Significantly revised the internal logic of `Runner#run_sync` for Python 3.14 compatibility | ||
| - By default handoff history is now packaged into a single assistant message instead of exposing the raw user/assistant turns, giving downstream agents a concise, predictable recap | ||
| - The existing single-message handoff transcript now by default starts with "For context, here is the conversation so far between the user and the previous agent:" before the `<CONVERSATION HISTORY>` block, so downstream agents get a clearly labeled recap | ||
|
||
|
|
||
| ### 0.4.0 | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -52,7 +52,7 @@ | |
| UserError, | ||
| ) | ||
| from .guardrail import InputGuardrail, InputGuardrailResult, OutputGuardrail, OutputGuardrailResult | ||
| from .handoffs import Handoff, HandoffInputData | ||
| from .handoffs import Handoff, HandoffInputData, nest_handoff_history | ||
| from .items import ( | ||
| HandoffCallItem, | ||
| HandoffOutputItem, | ||
|
|
@@ -998,8 +998,14 @@ async def execute_handoffs( | |
| input_filter = handoff.input_filter or ( | ||
| run_config.handoff_input_filter if run_config else None | ||
| ) | ||
| if input_filter: | ||
| logger.debug("Filtering inputs for handoff") | ||
| handoff_nest_setting = handoff.nest_handoff_history | ||
| should_nest_history = ( | ||
| handoff_nest_setting | ||
| if handoff_nest_setting is not None | ||
| else run_config.nest_handoff_history | ||
| ) | ||
| handoff_input_data: HandoffInputData | None = None | ||
| if input_filter or should_nest_history: | ||
| handoff_input_data = HandoffInputData( | ||
| input_history=tuple(original_input) | ||
| if isinstance(original_input, list) | ||
|
|
@@ -1008,6 +1014,17 @@ async def execute_handoffs( | |
| new_items=tuple(new_step_items), | ||
| run_context=context_wrapper, | ||
| ) | ||
|
|
||
| if input_filter and handoff_input_data is not None: | ||
| filter_name = getattr(input_filter, "__qualname__", repr(input_filter)) | ||
| from_agent = getattr(agent, "name", agent.__class__.__name__) | ||
| to_agent = getattr(new_agent, "name", new_agent.__class__.__name__) | ||
| logger.debug( | ||
| "Filtering handoff inputs with %s for %s -> %s", | ||
| filter_name, | ||
| from_agent, | ||
| to_agent, | ||
| ) | ||
|
Comment on lines
+1233
to
+1241
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. weird syntax - also can you use f-strings and get rid of getattr? |
||
| if not callable(input_filter): | ||
| _error_tracing.attach_error_to_span( | ||
| span_handoff, | ||
|
|
@@ -1037,6 +1054,18 @@ async def execute_handoffs( | |
| ) | ||
| pre_step_items = list(filtered.pre_handoff_items) | ||
| new_step_items = list(filtered.new_items) | ||
| elif should_nest_history and handoff_input_data is not None: | ||
| nested = nest_handoff_history( | ||
| handoff_input_data, | ||
| history_mapper=run_config.handoff_history_mapper, | ||
| ) | ||
| original_input = ( | ||
| nested.input_history | ||
| if isinstance(nested.input_history, str) | ||
| else list(nested.input_history) | ||
| ) | ||
| pre_step_items = list(nested.pre_handoff_items) | ||
| new_step_items = list(nested.new_items) | ||
|
|
||
| return SingleStepResult( | ||
| original_input=original_input, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,10 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from ..handoffs import HandoffInputData | ||
| from ..handoffs import ( | ||
| HandoffInputData, | ||
| default_handoff_history_mapper, | ||
| nest_handoff_history, | ||
| ) | ||
| from ..items import ( | ||
| HandoffCallItem, | ||
| HandoffOutputItem, | ||
|
|
@@ -13,6 +17,12 @@ | |
|
|
||
| """Contains common handoff input filters, for convenience. """ | ||
|
|
||
| __all__ = [ | ||
| "remove_all_tools", | ||
| "nest_handoff_history", | ||
| "default_handoff_history_mapper", | ||
| ] | ||
|
Comment on lines
+20
to
+24
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can remove this, not super useful |
||
|
|
||
|
|
||
| def remove_all_tools(handoff_input_data: HandoffInputData) -> HandoffInputData: | ||
| """Filters out all tool items: file search, web search and function calls+output.""" | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.