From 756e939543e6bcf05b628659e3ec94c2cad4407e Mon Sep 17 00:00:00 2001 From: Greyson LaLonde Date: Thu, 19 Mar 2026 20:13:54 -0400 Subject: [PATCH] fix: serialize callbacks to string only in JSON mode to preserve closures during copy --- lib/crewai/src/crewai/types/callback.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/crewai/src/crewai/types/callback.py b/lib/crewai/src/crewai/types/callback.py index e8f2021ea..cfbff623c 100644 --- a/lib/crewai/src/crewai/types/callback.py +++ b/lib/crewai/src/crewai/types/callback.py @@ -91,6 +91,6 @@ def callable_to_string(fn: Callable[..., Any]) -> str: SerializableCallable = Annotated[ Callable[..., Any], BeforeValidator(string_to_callable), - PlainSerializer(callable_to_string, return_type=str), + PlainSerializer(callable_to_string, return_type=str, when_used="json"), WithJsonSchema({"type": "string"}), ]