Skip to content

Fix Context.deserialize() discarding deserialized cost_manager#1959

Open
jnMetaCode wants to merge 1 commit intoFoundationAgents:mainfrom
jnMetaCode:fix-context-deserialize-cost-manager
Open

Fix Context.deserialize() discarding deserialized cost_manager#1959
jnMetaCode wants to merge 1 commit intoFoundationAgents:mainfrom
jnMetaCode:fix-context-deserialize-cost-manager

Conversation

@jnMetaCode
Copy link

Problem

Context.deserialize() in metagpt/context.py line 127 calls:

self.cost_manager.model_validate_json(cost_manager)

model_validate_json() is a Pydantic classmethod that creates and returns a new model instance from JSON. Since the return value is discarded, the deserialized cost manager data is silently lost — self.cost_manager retains its original (default) values.

Fix

Assign the returned instance:

self.cost_manager = CostManager.model_validate_json(cost_manager)

This means that when a Team is recovered from serialized state, the cost tracking (total_cost, max_budget, etc.) is correctly restored instead of being reset to defaults.

model_validate_json() is a classmethod that returns a new instance. Calling it on self.cost_manager and discarding the return value means the deserialized cost data is silently lost. The fix assigns the returned instance back to self.cost_manager. Signed-off-by: JiangNan <1394485448@qq.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant