From 47f192e112c47543c3787ddbb546a9214f2c284a Mon Sep 17 00:00:00 2001 From: Greyson LaLonde Date: Tue, 31 Mar 2026 15:59:43 +0800 Subject: [PATCH] fix: handle plain classes and callables in to_serializable Add __dict__ handler for non-Pydantic classes so their attributes are serialized rather than falling through to repr(). Guard with a callable check so functions/lambdas still get repr(). --- .../src/crewai/utilities/serialization.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lib/crewai/src/crewai/utilities/serialization.py b/lib/crewai/src/crewai/utilities/serialization.py index 0c3a79dff..6962423fa 100644 --- a/lib/crewai/src/crewai/utilities/serialization.py +++ b/lib/crewai/src/crewai/utilities/serialization.py @@ -116,6 +116,23 @@ def to_serializable( } except Exception: return repr(obj) + if callable(obj): + return repr(obj) + if hasattr(obj, "__dict__"): + try: + return { + _to_serializable_key(k): to_serializable( + v, + max_depth=max_depth, + _current_depth=_current_depth + 1, + _ancestors=new_ancestors, + context=context, + ) + for k, v in obj.__dict__.items() + if not k.startswith("_") + } + except Exception: + return repr(obj) return repr(obj)