@@ -1332,32 +1332,41 @@ def test_non_json_serializable_state_throws_error():
13321332def  test_agent_state_breaks_dict_reference ():
13331333    ref_dict  =  {"hello" : "world" }
13341334    agent  =  Agent (state = ref_dict )
1335+ 
1336+     # Make sure shallow object references do not affect state maintained by AgentState 
13351337    ref_dict ["hello" ] =  object ()
13361338
1339+     # This will fail if AgentState reflects the updated reference 
13371340    json .dumps (agent .state .get ())
13381341
13391342
13401343def  test_agent_state_breaks_deep_dict_reference ():
13411344    ref_dict  =  {"world" : "!" }
13421345    init_dict  =  {"hello" : ref_dict }
13431346    agent  =  Agent (state = init_dict )
1347+     # Make sure deep reference changes do not affect state mained by AgentState 
13441348    ref_dict ["world" ] =  object ()
13451349
1350+     # This will fail if AgentState reflects the updated reference 
13461351    json .dumps (agent .state .get ())
13471352
13481353
13491354def  test_agent_state_set_breaks_dict_reference ():
13501355    agent  =  Agent ()
13511356    ref_dict  =  {"hello" : "world" }
1357+     # Set should copy the input, and not maintain the reference to the original object 
13521358    agent .state .set ("hello" , ref_dict )
13531359    ref_dict ["hello" ] =  object ()
13541360
1361+     # This will fail if AgentState reflects the updated reference 
13551362    json .dumps (agent .state .get ())
13561363
13571364
13581365def  test_agent_state_get_breaks_deep_dict_reference ():
13591366    agent  =  Agent (state = {"hello" : {"world" : "!" }})
1367+     # Get should not return a reference to the internal state 
13601368    ref_state  =  agent .state .get ()
13611369    ref_state ["hello" ]["world" ] =  object ()
13621370
1371+     # This will fail if AgentState reflects the updated reference 
13631372    json .dumps (agent .state .get ())
0 commit comments