Skip to content

Python: safely serialize function_call arguments and results in observability (fixes #5733)#6206

Open
hanhan761 wants to merge 2 commits into
microsoft:mainfrom
hanhan761:fix-5733-observability-safe-serialize
Open

Python: safely serialize function_call arguments and results in observability (fixes #5733)#6206
hanhan761 wants to merge 2 commits into
microsoft:mainfrom
hanhan761:fix-5733-observability-safe-serialize

Conversation

@hanhan761
Copy link
Copy Markdown

Summary

observability.py's _to_otel_part() passes content.arguments and content.result directly into the returned dict without any JSON-safe conversion. When function call arguments contain dataclass instances (e.g., HandoffAgentUserRequest from workflow request_info events), json.dumps() in _capture_messages() raises TypeError: Object of type ... is not JSON serializable.

This fix introduces _make_json_safe() (a local equivalent of AG-UI's make_json_safe) and applies it to both the function_call and function_result branches of _to_otel_part().

Issue

Fixes #5733

Verification

  • 97 existing sync tests pass; 29 failures are pre-existing (missing pytest-asyncio plugin)
  • Unit tests for _make_json_safe confirm it handles: None, primitives, datetime, dataclasses, dicts/lists, objects with model_dump/to_dict/dict/__dict__, and non-serializable fallback to str()

hanhan761 added 2 commits May 30, 2026 15:25
…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
Copilot AI review requested due to automatic review settings May 30, 2026 07:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: Core observability cannot safely serialize workflow request_info payloads

2 participants