Fix TraceToMessages KeyError on multi-turn rollouts#486
Open
Mr-Neutr0n wants to merge 1 commit intomicrosoft:mainfrom
Open
Fix TraceToMessages KeyError on multi-turn rollouts#486Mr-Neutr0n wants to merge 1 commit intomicrosoft:mainfrom
Mr-Neutr0n wants to merge 1 commit intomicrosoft:mainfrom
Conversation
When a multi-turn agent rollout includes spans with full conversation history, some tracing instrumentations omit the 'role' attribute for assistant turns that consist only of tool_calls. This caused convert_to_openai_messages to crash with KeyError: 'role'. The fix uses dict.get() and infers role='assistant' when tool_calls is present but role is missing. Messages with neither role nor tool_calls are skipped gracefully. Added a regression test that reproduces the exact crash scenario.
Author
|
Friendly bump! Let me know if there's anything I should update or improve to help move this forward. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Fixes #425.
convert_to_openai_messagescrashed withKeyError: 'role'when processing multi-turn agent rollouts where subsequent spans carry full conversation history. Some tracing instrumentations omit theroleattribute for assistant turns that consist only oftool_calls.role="assistant"whentool_callsis present butroleis missing, and skips messages that have neitherrolenortool_calls.id,name,arguments).Test plan
test_trace_messages_adapter_builds_expected_conversationsandtest_trace_messages_adapter_handles_multiple_tool_callscontinue to passtest_convert_to_openai_messages_infers_assistant_role_from_tool_callsreproduces the exact APO's TraceToMessages adapter fails with multi-turn agent rollouts (KeyError: 'role') #425 crash scenario and verifies the fixtest_convert_to_openai_messages_skips_messages_missing_rolevalidates graceful skip of role-less non-tool messagestest_convert_to_openai_messages_skips_tool_calls_missing_keysvalidates filtering of incomplete tool call entries