Skip to content

Data structure corrupted when passing function result between Python workers (List of dicts becomes List of strings) #163

@Luisao4

Description

@Luisao4

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

  1. Define two functions within a game_sdk.game.worker.Worker, for example function_a and function_b.

  2. In function_a, prepare a dictionary named parsed_data that 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
  3. In the get_action method of your game_sdk.game.agent.Agent, after function_a completes, initiate a call to function_b, passing the info dictionary 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.

  4. In function_b, define the function to accept the data argument:

    def function_b(data: dict):
        for token in data.get("tokens", []):
            print(token["id"])  # This fails if token is a string
  5. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions