fix(agent): safely serialize trace payloads in capture_turn - #587
fix(agent): safely serialize trace payloads in capture_turn#587krishna28004 wants to merge 5 commits into
Conversation
|
Thanks for the fix. The datetime/Pydantic/custom-object handling is a good direction, but I think this still needs one more pass before approval.
Could we make the trace normalization fully JSON-safe, or at least add handling/tests for common non-JSON scalar types and assert that the final turn/augmentation payload can pass I ran:
|
|
Thanks @devwdave for catching that edge case. I updated the PR to explicitly handle common non-JSON scalar types that could still leak through The follow-up changes have been pushed in commit Please let me know if you see any other gaps in the serialization path. |
|
Hi @devwdave, |
There was a problem hiding this comment.
Pull request overview
This PR improves robustness of agent turn capture by ensuring trace payloads are JSON-safe before being sent to Memori Cloud, preventing ingestion failures when traces contain common non-JSON Python objects.
Changes:
- Serialize
traceinAgent.capture_turnviaconvert_to_jsonbefore building/posting payloads. - Extend
convert_to_jsonto normalize additional common types (e.g.,datetime/date,Enum,UUID,Path,Decimal, and set/tuple-like iterables). - Add tests covering safe serialization for complex traces and the newly supported scalar/container types.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
memori/agent.py |
Converts trace through convert_to_json inside capture_turn before posting payloads. |
memori/llm/helpers/serialization.py |
Adds concrete serialization branches for more non-JSON-native Python types. |
tests/test_agent.py |
Adds an end-to-end test asserting complex trace objects are safely serialized in turn/augmentation payloads. |
tests/llm/helpers/test_serialization.py |
Adds unit tests asserting convert_to_json handles datetime/date and several scalar/container types safely. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # 2. Assert specific structure preservation | ||
| assert result["id"] == "12345678-1234-5678-1234-567812345678" | ||
| assert result["cost"] == "1.23" | ||
| # Note: Path separator might differ on Windows/Linux, so check ends_with or just type |
What does this PR do?
Related issue
Before opening this PR
Type of change
Affected areas
memori/)memori-ts/)core/)How was this tested?
uv run pytestuv run ruff check .uv run ruff format --check .npm testfrommemori-ts/npm run lintfrommemori-ts/Checklist
Notes for reviewers