Repository navigation
Conversation
This branch is waiting to be deployed
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.
Problem
Message.instruct_contentis serialized as{"class", "mapping", "value"}and rebuilt on load,but
actionoutout_schema_to_mapping()inmetagpt/utils/serialize.pyonly mapsstring,array<string>andarray<array<string>>properties. Anyinteger,number,booleanorobjectfield of an ActionNode payload is left out of the mapping, so onMessage.model_validate_json(message.model_dump_json())pydantic rebuilds the model without thosefields and the values are silently dropped.
actionoutput_str_to_mapping()additionally raisesSyntaxErroron the"(<class 'int'>, Ellipsis)"form because only thestrcase isspecial-cased before
eval().Fix
actionoutout_schema_to_mapping()mapsinteger/number/boolean/objecttoint/float/bool/dictandarrayitems tolist[<mapped type>]; missingtype/itemskeys are skipped instead of raising
KeyError.actionoutput_str_to_mapping()resolves builtin type strings by name throughPY_TYPE_TO_MAPPING_STRinstead of callingeval()on invalid Python syntax.Tests
tests/metagpt/utils/test_serialize.py::test_serialize_and_deserialize_message_with_non_string_fieldsround-trips
int/float/bool/dict/strpayloads through bothserialize_message/deserialize_messageand
model_dump_json/model_validate_json.tests/metagpt/utils/test_serialize.py: 1 failed + 2 passed before the fix, 3 passed after.