FrankYang0529 commented on code in PR #74729:
URL: https://github.com/apache/airflow/pull/74729#discussion_r4344107613


##########
providers/common/ai/src/airflow/providers/common/ai/operators/agent.py:
##########
@@ -1120,6 +1129,23 @@ def _complete_run(self, context: Context, result: Any, 
*, attempt_usage: RunUsag
         self._clear_usage_budget(context)
         return output
 
+    def _convert_output_for_xcom(self, output: Any) -> Any:
+        """Return the XCom value, with dicts in place of models that a 
downstream task could not load."""
+        if self._serialize_model_output and isinstance(output, BaseModel):
+            return output.model_dump()
+        if not _CORE_WALKER:
+            # iter_pydantic_models could not be imported, so the worker 
registers no class.
+            # _serialize_model_output is always True when that import fails, 
so a model at the top level was
+            # already dumped above. The class of a model inside a list, tuple 
or dict is not registered
+            # either, so this call passes an empty set of registered classes 
to dump that model too.
+            return _dump_unregistered_models(output, set())
+        # A downstream task can load a model from XCom only if the worker 
registered the model's class.
+        # The worker registers the classes that iter_pydantic_models finds in 
output_type.
+        # iter_pydantic_models finds no class in a list of output types, an 
output marker, an output
+        # function, a TypeAliasType or a NewType. For these output types the 
operator pushes each model
+        # as a dict, including models inside a list, tuple or dict.
+        return _dump_unregistered_models(output, 
set(iter_pydantic_models(self.output_type)))

Review Comment:
   Added the early return at the top of `_convert_output_for_xcom`. With 
`do_xcom_push=False`, the method now returns the output unchanged and dumps 
nothing.  Thanks for the review.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to