1414 FlowConversationalDefinition ,
1515 FlowConversationalRouterDefinition ,
1616 FlowDefinition ,
17- FlowDefinitionDiagnostic ,
1817 FlowDictStateDefinition ,
1918 FlowHumanFeedbackDefinition ,
2019 FlowMethodDefinition ,
2322 FlowStateDefinition ,
2423 FlowUnknownStateDefinition ,
2524 _object_ref ,
25+ log_flow_definition_issues ,
2626)
2727from crewai .flow .flow_wrappers import (
2828 FlowMethod ,
@@ -116,7 +116,6 @@ def _is_json_serializable(value: Any) -> bool:
116116
117117def _serialize_static_value (
118118 value : Any ,
119- diagnostics : list [FlowDefinitionDiagnostic ],
120119 path : str ,
121120) -> Any :
122121 if value is None or _is_json_serializable (value ):
@@ -148,12 +147,11 @@ def _serialize_static_value(
148147 )
149148
150149 ref = _object_ref (value )
151- diagnostics .append (
152- FlowDefinitionDiagnostic (
153- code = "non_serializable_value" ,
154- path = path ,
155- message = f"value is not fully serializable; preserved import reference { ref } " ,
156- )
150+ logger .warning (
151+ "Flow definition value at %s is not fully serializable; "
152+ "preserved import reference %s." ,
153+ path ,
154+ ref ,
157155 )
158156 return {"ref" : ref }
159157
@@ -169,10 +167,7 @@ def _state_ref(value: Any) -> str | None:
169167 return None
170168
171169
172- def _build_state_definition (
173- flow_class : type ,
174- diagnostics : list [FlowDefinitionDiagnostic ],
175- ) -> FlowStateDefinition | None :
170+ def _build_state_definition (flow_class : type ) -> FlowStateDefinition | None :
176171 from pydantic import BaseModel as PydanticBaseModel
177172
178173 state_value = getattr (flow_class , "_initial_state_t" , None )
@@ -187,29 +182,23 @@ def _build_state_definition(
187182 if state_value is dict or isinstance (state_value , dict ):
188183 default = None
189184 if isinstance (state_value , dict ):
190- default = _serialize_static_value (state_value , diagnostics , "state.default" )
185+ default = _serialize_static_value (state_value , "state.default" )
191186 return FlowDictStateDefinition (default = default )
192187 if isinstance (state_value , type ) and issubclass (state_value , PydanticBaseModel ):
193188 return FlowPydanticStateDefinition (ref = _state_ref (state_value ))
194189 if isinstance (state_value , PydanticBaseModel ):
195190 return FlowPydanticStateDefinition (
196191 ref = _state_ref (state_value ),
197- default = _serialize_static_value (state_value , diagnostics , "state.default" ),
198- )
199- diagnostics .append (
200- FlowDefinitionDiagnostic (
201- code = "unknown_state_type" ,
202- path = "state" ,
203- message = f"could not serialize state type { _object_ref (state_value )} " ,
192+ default = _serialize_static_value (state_value , "state.default" ),
204193 )
194+ logger .warning (
195+ "Flow definition state could not serialize state type %s." ,
196+ _object_ref (state_value ),
205197 )
206198 return FlowUnknownStateDefinition (ref = _state_ref (state_value ))
207199
208200
209- def _build_config_definition (
210- flow_class : type ,
211- diagnostics : list [FlowDefinitionDiagnostic ],
212- ) -> FlowConfigDefinition :
201+ def _build_config_definition (flow_class : type ) -> FlowConfigDefinition :
213202 config_field_names = set (FlowConfigDefinition .model_fields )
214203 field_defaults = {
215204 name : field .get_default (call_default_factory = True )
@@ -225,15 +214,12 @@ def _build_config_definition(
225214 value if value is None or isinstance (value , str ) else _object_ref (value )
226215 )
227216 else :
228- values [field_name ] = _serialize_static_value (
229- value , diagnostics , f"config.{ field_name } "
230- )
217+ values [field_name ] = _serialize_static_value (value , f"config.{ field_name } " )
231218 return FlowConfigDefinition (** values )
232219
233220
234221def _build_human_feedback_definition (
235222 method : Any ,
236- diagnostics : list [FlowDefinitionDiagnostic ],
237223 path : str ,
238224) -> FlowHumanFeedbackDefinition | None :
239225 config = getattr (method , "__human_feedback_config__" , None )
@@ -248,7 +234,7 @@ def _build_human_feedback_definition(
248234 llm = getattr (config , "llm" , None ),
249235 default_outcome = getattr (config , "default_outcome" , None ),
250236 metadata = _serialize_static_value (
251- getattr (config , "metadata" , None ), diagnostics , f"{ path } .metadata"
237+ getattr (config , "metadata" , None ), f"{ path } .metadata"
252238 ),
253239 provider = getattr (config , "provider" , None ),
254240 learn = bool (getattr (config , "learn" , False )),
@@ -273,7 +259,6 @@ def _build_persistence_definition(value: Any) -> FlowPersistenceDefinition | Non
273259
274260def _build_conversational_router_definition (
275261 router_config : Any ,
276- diagnostics : list [FlowDefinitionDiagnostic ],
277262 path : str ,
278263) -> FlowConversationalRouterDefinition | None :
279264 if router_config is None :
@@ -284,12 +269,9 @@ def _build_conversational_router_definition(
284269 prompt = getattr (router_config , "prompt" , None ),
285270 response_format = _serialize_static_value (
286271 getattr (router_config , "response_format" , None ),
287- diagnostics ,
288272 f"{ path } .response_format" ,
289273 ),
290- llm = _serialize_static_value (
291- getattr (router_config , "llm" , None ), diagnostics , f"{ path } .llm"
292- ),
274+ llm = _serialize_static_value (getattr (router_config , "llm" , None ), f"{ path } .llm" ),
293275 routes = [str (route ) for route in routes ] if routes is not None else None ,
294276 route_descriptions = getattr (router_config , "route_descriptions" , None ),
295277 default_intent = getattr (router_config , "default_intent" , "converse" ),
@@ -300,7 +282,6 @@ def _build_conversational_router_definition(
300282
301283def _build_conversational_definition (
302284 flow_class : type ,
303- diagnostics : list [FlowDefinitionDiagnostic ],
304285) -> FlowConversationalDefinition | None :
305286 if not _is_conversational_flow (flow_class ):
306287 return None
@@ -324,12 +305,9 @@ def _build_conversational_definition(
324305 return FlowConversationalDefinition (
325306 enabled = True ,
326307 system_prompt = getattr (config , "system_prompt" , None ),
327- llm = _serialize_static_value (
328- getattr (config , "llm" , None ), diagnostics , "conversational.llm"
329- ),
308+ llm = _serialize_static_value (getattr (config , "llm" , None ), "conversational.llm" ),
330309 router = _build_conversational_router_definition (
331310 getattr (config , "router" , None ),
332- diagnostics ,
333311 "conversational.router" ,
334312 ),
335313 answer_from_history_prompt = getattr (config , "answer_from_history_prompt" , None ),
@@ -340,12 +318,10 @@ def _build_conversational_definition(
340318 ),
341319 intent_llm = _serialize_static_value (
342320 getattr (config , "intent_llm" , None ),
343- diagnostics ,
344321 "conversational.intent_llm" ,
345322 ),
346323 answer_from_history_llm = _serialize_static_value (
347324 getattr (config , "answer_from_history_llm" , None ),
348- diagnostics ,
349325 "conversational.answer_from_history_llm" ,
350326 ),
351327 visible_agent_outputs = (
@@ -365,7 +341,6 @@ def _build_conversational_definition(
365341
366342def _build_method_definition (
367343 method : Any ,
368- diagnostics : list [FlowDefinitionDiagnostic ],
369344 path : str ,
370345) -> FlowMethodDefinition :
371346 fragment = _get_flow_method_definition (method )
@@ -376,9 +351,7 @@ def _build_method_definition(
376351 deep = True , update = {"do" : _method_action (method )}
377352 )
378353
379- human_feedback = _build_human_feedback_definition (
380- method , diagnostics , f"{ path } .human_feedback"
381- )
354+ human_feedback = _build_human_feedback_definition (method , f"{ path } .human_feedback" )
382355 if human_feedback is not None :
383356 method_definition .human_feedback = human_feedback
384357 if human_feedback .emit :
@@ -444,7 +417,6 @@ def _build_flow_definition_from_class(
444417 flow_class : type ,
445418 namespace : dict [str , Any ] | None = None ,
446419) -> FlowDefinition :
447- diagnostics : list [FlowDefinitionDiagnostic ] = []
448420 methods : dict [str , FlowMethodDefinition ] = {}
449421 flow_methods = _iter_flow_methods (flow_class )
450422 if namespace is not None :
@@ -456,7 +428,7 @@ def _build_flow_definition_from_class(
456428
457429 for method_name , method in flow_methods .items ():
458430 methods [method_name ] = _build_method_definition (
459- method , diagnostics , f"methods.{ method_name } "
431+ method , f"methods.{ method_name } "
460432 )
461433
462434 description = None
@@ -467,15 +439,13 @@ def _build_flow_definition_from_class(
467439 definition = FlowDefinition (
468440 name = getattr (flow_class , "__name__" , "Flow" ),
469441 description = description ,
470- state = _build_state_definition (flow_class , diagnostics ),
471- config = _build_config_definition (flow_class , diagnostics ),
442+ state = _build_state_definition (flow_class ),
443+ config = _build_config_definition (flow_class ),
472444 persist = _build_persistence_definition (flow_class ),
473- conversational = _build_conversational_definition (flow_class , diagnostics ),
445+ conversational = _build_conversational_definition (flow_class ),
474446 methods = methods ,
475- diagnostics = diagnostics ,
476447 )
477- definition .diagnostics .extend (definition .validate_contract ())
478- definition .log_diagnostics ()
448+ log_flow_definition_issues (definition )
479449 return definition
480450
481451
0 commit comments