Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 28 additions & 5 deletions src/uipath_langchain/_cli/_runtime/_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,9 @@ def serialized_output(self) -> Dict[str, Any]:
try:
if self.context.output is None:
return {}
if hasattr(self.context.output, "dict"):
return self.context.output.dict()
elif hasattr(self.context.output, "to_dict"):
return self.context.output.to_dict()
return dict(self.context.output)

return self._serialize_object(self.context.output)

except Exception as e:
raise LangGraphRuntimeError(
"OUTPUT_SERIALIZATION_FAILED",
Expand All @@ -158,6 +156,31 @@ def serialized_output(self) -> Dict[str, Any]:
UiPathErrorCategory.SYSTEM,
) from e

def _serialize_object(self, obj):
"""Recursively serializes an object and all its nested components."""
# Handle Pydantic models
if hasattr(obj, "dict"):
return self._serialize_object(obj.dict())
elif hasattr(obj, "model_dump"):
return self._serialize_object(obj.model_dump(by_alias=True))
elif hasattr(obj, "to_dict"):
return self._serialize_object(obj.to_dict())
# Handle dictionaries
elif isinstance(obj, dict):
return {k: self._serialize_object(v) for k, v in obj.items()}
# Handle lists
elif isinstance(obj, list):
return [self._serialize_object(item) for item in obj]
# Handle other iterable objects (convert to dict first)
elif hasattr(obj, "__iter__") and not isinstance(obj, (str, bytes)):
try:
return self._serialize_object(dict(obj))
except (TypeError, ValueError):
return obj
# Return primitive types as is
else:
return obj

async def process(self) -> UiPathRuntimeResult:
"""
Process the output and prepare the final execution result.
Expand Down
Loading