@@ -34,12 +34,18 @@ async def execute(self) -> Optional[UiPathRuntimeResult]:
3434 Dictionary with execution results
3535
3636 Raises:
37- UiPathLlamaRuntimeError : If execution fails
37+ UiPathLlamaIndexRuntimeError : If execution fails
3838 """
3939 await self .validate ()
4040
4141 try :
42- a = 2
42+ output = await self .context .workflow .run (self .context .input_json )
43+
44+ self .context .result = UiPathRuntimeResult (
45+ output = self ._serialize_object (output )
46+ )
47+
48+ return self .context .result
4349
4450 except Exception as e :
4551 if isinstance (e , UiPathLlamaIndexRuntimeError ):
@@ -98,17 +104,17 @@ async def validate(self) -> None:
98104 UiPathErrorCategory .DEPLOYMENT ,
99105 )
100106
101- # Get the specified graph
102- self .graph_config = self .context .config .get_workflow (self .context .entrypoint )
103- if not self .graph_config :
107+ # Get the specified workflow configuration
108+ self .workflow_config = self .context .config .get_workflow (self .context .entrypoint )
109+ if not self .workflow_config :
104110 raise UiPathLlamaIndexRuntimeError (
105111 "WORKFLOW_NOT_FOUND" ,
106112 "Workflow not found" ,
107113 f"Workflow '{ self .context .entrypoint } ' not found." ,
108114 UiPathErrorCategory .DEPLOYMENT ,
109115 )
110116 try :
111- self .context .workflow = await self .graph_config .load_workflow ()
117+ self .context .workflow = await self .workflow_config .load_workflow ()
112118 except ImportError as e :
113119 raise UiPathLlamaIndexRuntimeError (
114120 "WORKFLOW_IMPORT_ERROR" ,
@@ -120,7 +126,7 @@ async def validate(self) -> None:
120126 raise UiPathLlamaIndexRuntimeError (
121127 "WORKFLOW_TYPE_ERROR" ,
122128 "Invalid workflow type" ,
123- f"Workflow '{ self .context .entrypoint } ' is not a valid Workflow: { str (e )} " ,
129+ f"Workflow '{ self .context .entrypoint } ' is not a valid ` Workflow` : { str (e )} " ,
124130 UiPathErrorCategory .USER ,
125131 ) from e
126132 except ValueError as e :
@@ -141,3 +147,28 @@ async def validate(self) -> None:
141147 async def cleanup (self ) -> None :
142148 """Clean up all resources."""
143149 pass
150+
151+ def _serialize_object (self , obj ):
152+ """Recursively serializes an object and all its nested components."""
153+ # Handle Pydantic models
154+ if hasattr (obj , "dict" ):
155+ return self ._serialize_object (obj .dict ())
156+ elif hasattr (obj , "model_dump" ):
157+ return self ._serialize_object (obj .model_dump (by_alias = True ))
158+ elif hasattr (obj , "to_dict" ):
159+ return self ._serialize_object (obj .to_dict ())
160+ # Handle dictionaries
161+ elif isinstance (obj , dict ):
162+ return {k : self ._serialize_object (v ) for k , v in obj .items ()}
163+ # Handle lists
164+ elif isinstance (obj , list ):
165+ return [self ._serialize_object (item ) for item in obj ]
166+ # Handle other iterable objects (convert to dict first)
167+ elif hasattr (obj , "__iter__" ) and not isinstance (obj , (str , bytes )):
168+ try :
169+ return self ._serialize_object (dict (obj ))
170+ except (TypeError , ValueError ):
171+ return obj
172+ # Return primitive types as is
173+ else :
174+ return obj
0 commit comments