Repository: phidatahq/phidata
File: libs/agno/agno/run/base.py (Python)

Code before:
                from agno.run.team import TeamRunInput

                data["run_input"] = TeamRunInput.from_dict(run_input)
            else:
                from agno.run.agent import RunInput

                data["run_input"] = RunInput.from_dict(run_input)

                # Handle requirements

        # Handle requirements
        requirements_data = data.pop("requirements", None)
        if requirements_data is not None:
            from agno.run.requirement import RunRequirement

            requirements_list: List[RunRequirement] = []
            for item in requirements_data:
                if isinstance(item, RunRequirement):
                    requirements_list.append(item)
                elif isinstance(item, dict):
                    requirements_list.append(RunRequirement.from_dict(item))
            data["requirements"] = requirements_list if requirements_list else None

        # Filter data to only include fields that are actually defined in the target class
        from dataclasses import fields

        supported_fields = {f.name for f in fields(cls)}
        filtered_data = {k: v for k, v in data.items() if k in supported_fields}

        return cls(**filtered_data)

    @property
    def is_paused(self):
        return False

    @property
    def is_cancelled(self):
        return False


class RunStatus(str, Enum):
    """State of the main run response"""

    pending = "PENDING"
    running = "RUNNING"
    completed = "COMPLETED"
    paused = "PAUSED"
    cancelled = "CANCELLED"
    error = "ERROR"


Review comment (suggestion):
ah, i think we also need to handle for `to_dict`? can we do some tests to make sure a fix is not needed in `to_dict` because we use `asdict` there and i'm afraid if its even serializing it properly. Specially if we dynamically set the attributes for that custom event

Code after:
                from agno.run.team import TeamRunInput

                data["run_input"] = TeamRunInput.from_dict(run_input)
            else:
                from agno.run.agent import RunInput

                data["run_input"] = RunInput.from_dict(run_input)

                # Handle requirements

        # Handle requirements
        requirements_data = data.pop("requirements", None)
        if requirements_data is not None:
            from agno.run.requirement import RunRequirement

            requirements_list: List[RunRequirement] = []
            for item in requirements_data:
                if isinstance(item, RunRequirement):
                    requirements_list.append(item)
                elif isinstance(item, dict):
                    requirements_list.append(RunRequirement.from_dict(item))
            data["requirements"] = requirements_list if requirements_list else None

        # Filter data to only include fields that are actually defined in the target class
        # CustomEvent accepts arbitrary fields, so skip filtering for it
        if cls.__name__ == "CustomEvent":
            return cls(**data)

        from dataclasses import fields

        supported_fields = {f.name for f in fields(cls)}
        filtered_data = {k: v for k, v in data.items() if k in supported_fields}

        return cls(**filtered_data)

    @property
    def is_paused(self):
        return False

    @property
    def is_cancelled(self):
        return False


class RunStatus(str, Enum):
    """State of the main run response"""

    pending = "PENDING"
    running = "RUNNING"
    completed = "COMPLETED"
    paused = "PAUSED"