Python: safely serialize function_call arguments and results in observability (fixes #5733)#6206
Open
hanhan761 wants to merge 2 commits into
Open
Conversation
…ll_id (fixes microsoft#5793) - _coalesce_code_interpreter_tool_calls() groups by call_id, keeps winner at its original position - _code_interpreter_chunk_is_more_complete() prefers valid sequence_number, coerces to int - _get_ci_chunk_content_length() sums text across all inputs - _try_parse_seq() handles string-typed sequence_number safely - 8 regression tests covering edge cases
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
observability.py's_to_otel_part()passescontent.argumentsandcontent.resultdirectly into the returned dict without any JSON-safe conversion. When function call arguments contain dataclass instances (e.g.,HandoffAgentUserRequestfrom workflowrequest_infoevents),json.dumps()in_capture_messages()raisesTypeError: Object of type ... is not JSON serializable.This fix introduces
_make_json_safe()(a local equivalent of AG-UI'smake_json_safe) and applies it to both thefunction_callandfunction_resultbranches of_to_otel_part().Issue
Fixes #5733
Verification
pytest-asyncioplugin)_make_json_safeconfirm it handles: None, primitives, datetime, dataclasses, dicts/lists, objects withmodel_dump/to_dict/dict/__dict__, and non-serializable fallback tostr()