Method Mismatch in Function Serialization
Issue Description
There is a method name mismatch between the Function class implementation and the SDK's serialization expectations. The SDK attempts to call to_dict() on Function objects, but the Function class only implements toJson().
Current Behavior
When attempting to simulate or deploy custom functions, the following error occurs:
Traceback (mostrecentcalllast):
File"...\agent_test_suite.py", line189, in<module>response=agent.simulate_twitter(session_id="research-session")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^File"...\site-packages\virtuals_sdk\game.py", line214, insimulate_twitterreturnself.game_sdk.simulate(
^^^^^^^^^^^^^^^^^^^^^^^File"...\site-packages\virtuals_sdk\sdk.py", line41, insimulate"customFunctions": [x.to_dict() forxincustom_functions]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^File"...\site-packages\virtuals_sdk\sdk.py", line41, in<listcomp>"customFunctions": [x.to_dict() forxincustom_functions]
^^^^^^^^^AttributeError: 'Function'objecthasnoattribute'to_dict'
Expected Behavior
The SDK should either:
- Use
toJson() instead of to_dict() in sdk.py, or - The Function class should implement both methods for compatibility
Code Analysis
In game.py
@dataclassclassFunction:
# ...deftoJson(self):
return {
"id": self.id,
"fn_name": self.fn_name,
"fn_description": self.fn_description,
"args": [asdict(arg) forarginself.args],
"hint": self.hint,
"config": asdict(self.config)
}In sdk.py
defsimulate(self, session_id: str, goal: str, description: str, world_info: str, functions: list, custom_functions: list):
# ..."customFunctions": [x.to_dict() forxincustom_functions] # This line causes the error
Current Workaround
Users can implement a wrapper class to provide the missing method:
classCustomFunction(game.Function):
defto_dict(self):
returnself.toJson()
Suggested Fix
Option 1 (Preferred):
# In sdk.py, change:"customFunctions": [x.toJson() forxincustom_functions]
Option 2:
# In game.py, add to Function class:defto_dict(self):
returnself.toJson()
Impact
This issue affects any users trying to implement custom functions with the SDK, particularly when using the simulation or deployment features.
Additional Notes
- The issue appears to be a simple naming inconsistency rather than a functional problem
- The
toJson() method works correctly when called directly - The fix should be backward compatible regardless of which option is chosen
Labels
- bug
- documentation
- enhancement
Method Mismatch in Function Serialization
Issue Description
There is a method name mismatch between the
Functionclass implementation and the SDK's serialization expectations. The SDK attempts to callto_dict()on Function objects, but the Function class only implementstoJson().Current Behavior
When attempting to simulate or deploy custom functions, the following error occurs:
Expected Behavior
The SDK should either:
toJson()instead ofto_dict()in sdk.py, orCode Analysis
In game.py
In sdk.py
Current Workaround
Users can implement a wrapper class to provide the missing method:
Suggested Fix
Option 1 (Preferred):
Option 2:
Impact
This issue affects any users trying to implement custom functions with the SDK, particularly when using the simulation or deployment features.
Additional Notes
toJson()method works correctly when called directlyLabels