-
Notifications
You must be signed in to change notification settings - Fork 89
Description
Bug: list[dict] becomes list[str] when passed between functions using game_sdk.Agent
Summary
When chaining Python worker function calls using the game_sdk Agent, an issue occurs where the info dictionary returned by one function (function_a) contains a list of dictionaries, but this list is received by the next function (function_b) as a list of strings.
This leads to AttributeError or TypeError when function_b attempts to access dictionary attributes on the list items.
Impact
This issue prevents the correct flow of structured data between worker steps, making it unreliable to pass lists of dictionaries between functions.
Steps to Reproduce
-
Define two functions within a
game_sdk.game.worker.Worker, for examplefunction_aandfunction_b. -
In
function_a, prepare a dictionary namedparsed_datathat includes a key like"tokens"containing a list of dictionaries:parsed_data = { "tokens": [ {"id": "token1", "value": 10}, {"id": "token2", "value": 20} ], "changes": {...} } return FunctionResultStatus.DONE, "Success", parsed_data
-
In the
get_actionmethod of yourgame_sdk.game.agent.Agent, afterfunction_acompletes, initiate a call tofunction_b, passing theinfodictionary as an argument:{ "action_type": "call_function", "action_args": { "fn_name": "function_b", "args": {"data": function_result.info} } }Note: Based on logs, the SDK may internally wrap this further into a structure like
{"data": {"value": function_result.info}}, but the core issue remains. -
In
function_b, define the function to accept thedataargument:def function_b(data: dict): for token in data.get("tokens", []): print(token["id"]) # This fails if token is a string
-
Run the agent.
Expected Behavior
The data structure received by function_b should be:
{
"tokens": [
{"id": "token1", "value": 10},
{"id": "token2", "value": 20}
],
"changes": {...}
}Accessing data["tokens"][0]["id"] should work without error.
Observed Behavior
The list of dictionaries is instead received as a list of strings:
{
"tokens": [
"{'id': 'token1', 'value': 10}",
"{'id': 'token2', 'value': 20}"
]
}Attempting to access dictionary keys on these string items results in errors such as:
AttributeError: 'str' object has no attribute 'get'TypeError: string indices must be integers, not 'str'
Additional Notes
This appears to be caused by the SDK serializing and deserializing the info dictionary in a way that converts dictionaries inside lists to strings. The SDK should ensure consistent and safe handling of nested data structures to avoid this behavior.