diff --git a/lib/crewai/src/crewai/events/utils/handlers.py b/lib/crewai/src/crewai/events/utils/handlers.py index 386da6b47..48d21bd75 100644 --- a/lib/crewai/src/crewai/events/utils/handlers.py +++ b/lib/crewai/src/crewai/events/utils/handlers.py @@ -11,11 +11,22 @@ from crewai.events.types.event_bus_types import AsyncHandler, SyncHandler @functools.lru_cache(maxsize=256) -def _get_param_count(handler: Any) -> int: - """Return the number of parameters a handler accepts, with caching.""" +def _get_param_count_cached(handler: Any) -> int: return len(inspect.signature(handler).parameters) +def _get_param_count(handler: Any) -> int: + """Return the number of parameters a handler accepts, with caching. + + Falls back to uncached introspection for unhashable handlers + like functools.partial. + """ + try: + return _get_param_count_cached(handler) + except TypeError: + return len(inspect.signature(handler).parameters) + + def is_async_handler( handler: Any, ) -> TypeIs[AsyncHandler]: