-
Notifications
You must be signed in to change notification settings - Fork 3.8k
fix(handoffs): add to_input_list_raw and include_nested_summary param… #2276
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
Closed
HemanthIITJ
wants to merge
2
commits into
openai:main
from
HemanthIITJ:fix/issue-2258-to-input-list-dedup-v2
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| """Tests for to_input_list with handoff history deduplication (Issue #2258).""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from agents.result import RunResultBase | ||
|
|
||
|
|
||
| class TestNestedHistorySummaryDetection: | ||
| """Tests for _is_nested_history_summary static method.""" | ||
|
|
||
| def test_detects_summary_with_markers(self) -> None: | ||
| """Verify detection of nested history summary messages.""" | ||
| summary_item = { | ||
| "role": "assistant", | ||
| "content": "<CONVERSATION HISTORY>\ntest\n</CONVERSATION HISTORY>", | ||
| } | ||
| assert RunResultBase._is_nested_history_summary(summary_item) is True | ||
|
|
||
| def test_ignores_regular_assistant_message(self) -> None: | ||
| """Regular assistant messages should not be detected as summaries.""" | ||
| regular_item = { | ||
| "role": "assistant", | ||
| "content": "Hello, how can I help?", | ||
| } | ||
| assert RunResultBase._is_nested_history_summary(regular_item) is False | ||
|
|
||
| def test_ignores_user_message(self) -> None: | ||
| """User messages should not be detected as summaries.""" | ||
| user_item = {"role": "user", "content": "Test"} | ||
| assert RunResultBase._is_nested_history_summary(user_item) is False | ||
|
|
||
| def test_ignores_function_output(self) -> None: | ||
| """Function outputs should not be detected as summaries.""" | ||
| function_item = { | ||
| "type": "function_call_output", | ||
| "call_id": "123", | ||
| "output": "result", | ||
| } | ||
| assert RunResultBase._is_nested_history_summary(function_item) is False | ||
|
|
||
| def test_requires_both_markers(self) -> None: | ||
| """Both start and end markers are required for detection.""" | ||
| partial_start = { | ||
| "role": "assistant", | ||
| "content": "<CONVERSATION HISTORY> only start marker", | ||
| } | ||
| assert RunResultBase._is_nested_history_summary(partial_start) is False | ||
|
|
||
| partial_end = { | ||
| "role": "assistant", | ||
| "content": "only end marker </CONVERSATION HISTORY>", | ||
| } | ||
| assert RunResultBase._is_nested_history_summary(partial_end) is False | ||
|
|
||
| def test_handles_non_string_content(self) -> None: | ||
| """Non-string content should return False.""" | ||
| structured_content = { | ||
| "role": "assistant", | ||
| "content": [{"type": "text", "text": "structured content"}], | ||
| } | ||
| assert RunResultBase._is_nested_history_summary(structured_content) is False | ||
|
|
||
| def test_handles_non_dict_input(self) -> None: | ||
| """Non-dict inputs should return False.""" | ||
| assert RunResultBase._is_nested_history_summary("not a dict") is False # type: ignore | ||
| assert RunResultBase._is_nested_history_summary(None) is False # type: ignore | ||
| assert RunResultBase._is_nested_history_summary(123) is False # type: ignore |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_is_nested_history_summaryhardcodes the default<CONVERSATION HISTORY>markers, but the handoff API lets callers change these viaset_conversation_history_wrappers(seesrc/agents/handoffs/history.py). If a user customizes the wrappers,to_input_list(include_nested_summary=False)/to_input_list_raw()will no longer detect and filter the nested summary, so the duplicated nested history remains and the parsing issue this change targets persists. Consider reading the current wrappers (e.g., viaget_conversation_history_wrappers) when checking the content.Useful? React with 👍 / 👎.