fix(chat_history): support nested multimodal content - #209
Merged
Conversation
ChatHistory.get_history() now recursively extracts multimodal objects (Image, PDF, Audio) from arbitrarily nested Pydantic schemas, fixing two related bugs: - #208: TypeError when schemas have both multimodal fields and nested Pydantic models (json.dumps can't serialize Pydantic instances) - #141: Multimodal content inside nested schemas was invisible to the shallow top-level field scan The fix replaces the shallow field iteration + json.dumps with a single recursive _extract_multimodal_info() method that builds a Pydantic exclude spec, then uses model_dump_json(exclude=...) for correct serialization of all remaining fields. Adds 6 comprehensive tests and a nested-multimodal example. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Handle tuples identically to lists in _extract_multimodal_info - Collapse dict exclude spec to True when all values are multimodal - Add 10 direct unit tests for _extract_multimodal_info return values - Add Dict[str, Image] integration test covering the dict code path - Add exact content list length assertions to existing tests Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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
ChatHistory.get_history()crashes withTypeErrorwhen schemas have both multimodal fields (Image/PDF/Audio) and nested Pydantic modelsDocument.pdf) was invisible to the top-level field scanjson.dumps()with recursive_extract_multimodal_info()that builds a Pydanticexcludespec, then usesmodel_dump_json(exclude=...)for correct serializationChanges
atomic-agents/atomic_agents/context/chat_history.py: Rewroteget_history()multimodal handling with a new_extract_multimodal_info()static method that recursively walks nested schemas at any depthatomic-agents/tests/context/test_chat_history.py: Added 6 comprehensive tests (nested + top-level multimodal, deeply nested only, mixed, lists of nested schemas, all-multimodal, backwards compat)atomic-examples/nested-multimodal/: New end-to-end example demonstrating nested multimodal schemas working with an actual LLM callTest plan
🤖 Generated with Claude Code