Title: Method Mismatch in Function Serializatio · Issue #8 · Virtual-Protocol/virtuals-python · GitHub
Open Graph Title: Method Mismatch in Function Serializatio · Issue #8 · Virtual-Protocol/virtuals-python
X Title: Method Mismatch in Function Serializatio · Issue #8 · Virtual-Protocol/virtuals-python
Description: 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 t...
Open Graph Description: 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 c...
X Description: 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 ...
Opengraph URL: https://github.com/Virtual-Protocol/virtuals-python/issues/8
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Method Mismatch in Function Serializatio","articleBody":"## Method Mismatch in Function Serialization\r\n\r\n### Issue Description\r\nThere 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()`.\r\n\r\n### Current Behavior\r\nWhen attempting to simulate or deploy custom functions, the following error occurs:\r\n```python\r\nTraceback (most recent call last):\r\n File \"...\\agent_test_suite.py\", line 189, in \u003cmodule\u003e\r\n response = agent.simulate_twitter(session_id=\"research-session\")\r\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\r\n File \"...\\site-packages\\virtuals_sdk\\game.py\", line 214, in simulate_twitter\r\n return self.game_sdk.simulate(\r\n ^^^^^^^^^^^^^^^^^^^^^^^\r\n File \"...\\site-packages\\virtuals_sdk\\sdk.py\", line 41, in simulate\r\n \"customFunctions\": [x.to_dict() for x in custom_functions]\r\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\r\n File \"...\\site-packages\\virtuals_sdk\\sdk.py\", line 41, in \u003clistcomp\u003e\r\n \"customFunctions\": [x.to_dict() for x in custom_functions]\r\n ^^^^^^^^^\r\nAttributeError: 'Function' object has no attribute 'to_dict'\r\n```\r\n\r\n### Expected Behavior\r\nThe SDK should either:\r\n1. Use `toJson()` instead of `to_dict()` in sdk.py, or\r\n2. The Function class should implement both methods for compatibility\r\n\r\n### Code Analysis\r\n#### In game.py\r\n```python\r\n@dataclass\r\nclass Function:\r\n # ...\r\n def toJson(self):\r\n return {\r\n \"id\": self.id,\r\n \"fn_name\": self.fn_name,\r\n \"fn_description\": self.fn_description,\r\n \"args\": [asdict(arg) for arg in self.args],\r\n \"hint\": self.hint,\r\n \"config\": asdict(self.config)\r\n }\r\n```\r\n\r\n#### In sdk.py\r\n```python\r\ndef simulate(self, session_id: str, goal: str, description: str, world_info: str, functions: list, custom_functions: list):\r\n # ...\r\n \"customFunctions\": [x.to_dict() for x in custom_functions] # This line causes the error\r\n```\r\n\r\n### Current Workaround\r\nUsers can implement a wrapper class to provide the missing method:\r\n```python\r\nclass CustomFunction(game.Function):\r\n def to_dict(self):\r\n return self.toJson()\r\n```\r\n\r\n### Suggested Fix\r\n#### Option 1 (Preferred):\r\n```python\r\n# In sdk.py, change:\r\n\"customFunctions\": [x.toJson() for x in custom_functions]\r\n```\r\n\r\n#### Option 2:\r\n```python\r\n# In game.py, add to Function class:\r\ndef to_dict(self):\r\n return self.toJson()\r\n```\r\n\r\n### Impact\r\nThis issue affects any users trying to implement custom functions with the SDK, particularly when using the simulation or deployment features.\r\n\r\n### Additional Notes\r\n- The issue appears to be a simple naming inconsistency rather than a functional problem\r\n- The `toJson()` method works correctly when called directly\r\n- The fix should be backward compatible regardless of which option is chosen\r\n\r\n### Labels\r\n- bug\r\n- documentation\r\n- enhancement","author":{"url":"https://github.com/Hdpbilly","@type":"Person","name":"Hdpbilly"},"datePublished":"2024-12-21T07:25:54.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/8/virtuals-python/issues/8"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:b06a01e4-f0ec-dd42-7765-b758e6791556 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B832:24571B:B105F9:F16EF8:6A593CAB |
| html-safe-nonce | f1b695d1fb07f6f08a2e4d02b991f97950679ddf49eee941fbd11b09f8b1ae1c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCODMyOjI0NTcxQjpCMTA1Rjk6RjE2RUY4OjZBNTkzQ0FCIiwidmlzaXRvcl9pZCI6Ijg0MzU3NzI2NzQwNDQxNDg5MDciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | d0fc6eee71dfeb00b5a1f2011aac6aba8a85d2a605a428881de01e950cd789ec |
| hovercard-subject-tag | issue:2753821940 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/Virtual-Protocol/virtuals-python/8/issue_layout |
| twitter:image | https://opengraph.githubassets.com/bd6b26ef0d53aea703a5141e3a4821b7aea2a3b602693ea141a9a64756ddb538/Virtual-Protocol/virtuals-python/issues/8 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/bd6b26ef0d53aea703a5141e3a4821b7aea2a3b602693ea141a9a64756ddb538/Virtual-Protocol/virtuals-python/issues/8 |
| og:image:alt | 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 c... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Hdpbilly |
| hostname | github.com |
| expected-hostname | github.com |
| None | 1b31c9453e1607b2781513084b4770f67217e549834c85b76960d7b13626f7c8 |
| turbo-cache-control | no-preview |
| go-import | github.com/Virtual-Protocol/virtuals-python git https://github.com/Virtual-Protocol/virtuals-python.git |
| octolytics-dimension-user_id | 94182078 |
| octolytics-dimension-user_login | Virtual-Protocol |
| octolytics-dimension-repository_id | 902450046 |
| octolytics-dimension-repository_nwo | Virtual-Protocol/virtuals-python |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 902450046 |
| octolytics-dimension-repository_network_root_nwo | Virtual-Protocol/virtuals-python |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 220f27779da5b92b5e17fcaef93e474cc8affba3 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width