Fix KeyError in convert_to_openai_messages for incomplete messages#485
Open
Mr-Neutr0n wants to merge 1 commit intomicrosoft:mainfrom
Open
Fix KeyError in convert_to_openai_messages for incomplete messages#485Mr-Neutr0n wants to merge 1 commit intomicrosoft:mainfrom
Mr-Neutr0n wants to merge 1 commit intomicrosoft:mainfrom
Conversation
…sages When AgentOps captures incomplete message objects (missing "role" or "tool_calls" keys), convert_to_openai_messages() would crash with KeyError on msg["role"] or call["id"]. This change adds defensive key checking: - Infer role="assistant" when "role" is absent but "tool_calls" exists; skip messages missing both keys entirely - Filter out tool_call entries missing "id", "name", or "arguments" - Guard completion tool entries against missing nested "call" dict keys - Fall back to content-only assistant message when all tool entries are filtered out Fixes microsoft#311
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
convert_to_openai_messages()to handle incomplete message objects captured by AgentOps"role"but has"tool_calls", inferrole="assistant"instead of crashing; skip messages missing both keys"id","name","arguments") rather than raisingKeyError"call"dict or its required"id"/"type"keysFixes #311
Test plan
test_trace_messages_adapter_builds_expected_conversations,test_trace_messages_adapter_handles_multiple_tool_calls)test_convert_to_openai_messages_skips_messages_missing_role-- verifies messages without"role"are skippedtest_convert_to_openai_messages_skips_tool_calls_missing_keys-- verifies incomplete tool_call entries are filteredtest_convert_to_openai_messages_infers_assistant_role_from_tool_calls-- verifies role inference fromtool_callspresence