|
21 | 21 | from uipath.eval.mocks import mockable |
22 | 22 | from uipath.platform import UiPath |
23 | 23 | from uipath.platform.action_center.tasks import TaskRecipient, TaskRecipientType |
24 | | -from uipath.platform.common import CreateEscalation |
| 24 | +from uipath.platform.common import CreateEscalation, UiPathConfig |
25 | 25 | from uipath.runtime.errors import UiPathErrorCode |
26 | 26 |
|
27 | 27 | from uipath_langchain.agent.react.jsonschema_pydantic_converter import create_model |
@@ -107,6 +107,48 @@ def _get_user_email(user: Any) -> str | None: |
107 | 107 | return getattr(user, "emailAddress", None) |
108 | 108 |
|
109 | 109 |
|
| 110 | +def _parse_task_data( |
| 111 | + data: dict[str, Any], |
| 112 | + input_schema: dict[str, Any], |
| 113 | + output_schema: dict[str, Any] | None = None, |
| 114 | +) -> dict[str, Any]: |
| 115 | + """ |
| 116 | + Filter action center task data based on input/output schemas. |
| 117 | +
|
| 118 | + When output_schema is None, returns only fields not present in input_schema. |
| 119 | + When output_schema is provided, returns only fields defined in output_schema. |
| 120 | +
|
| 121 | + Args: |
| 122 | + data: Raw task data from action center |
| 123 | + input_schema: JSON schema defining the input fields |
| 124 | + output_schema: Optional JSON schema defining expected output fields |
| 125 | +
|
| 126 | + Returns: |
| 127 | + Filtered dictionary containing only relevant output fields |
| 128 | + """ |
| 129 | + filtered_fields: dict[str, Any] = {} |
| 130 | + |
| 131 | + if output_schema is None: |
| 132 | + input_field_names = set() |
| 133 | + if "properties" in input_schema: |
| 134 | + input_field_names = set(input_schema["properties"].keys()) |
| 135 | + |
| 136 | + for field_name, field_value in data.items(): |
| 137 | + if field_name not in input_field_names: |
| 138 | + filtered_fields[field_name] = field_value |
| 139 | + |
| 140 | + else: |
| 141 | + output_field_names = set() |
| 142 | + if "properties" in output_schema: |
| 143 | + output_field_names = set(output_schema["properties"].keys()) |
| 144 | + |
| 145 | + for field_name, field_value in data.items(): |
| 146 | + if field_name in output_field_names: |
| 147 | + filtered_fields[field_name] = field_value |
| 148 | + |
| 149 | + return filtered_fields |
| 150 | + |
| 151 | + |
110 | 152 | def create_escalation_tool( |
111 | 153 | resource: AgentEscalationResourceConfig, |
112 | 154 | ) -> StructuredTool: |
@@ -161,25 +203,31 @@ async def escalate(): |
161 | 203 |
|
162 | 204 | # Extract task info before validation |
163 | 205 | task_id = result.id |
| 206 | + task_url = f"{UiPathConfig.base_url}/actions_/tasks/{task_id}" |
164 | 207 | assigned_to = _get_user_email(result.assigned_to_user) |
165 | 208 |
|
166 | | - escalation_action = result.action |
167 | | - escalation_output = result.data or {} |
| 209 | + outcome = result.action |
| 210 | + escalation_output = _parse_task_data( |
| 211 | + result.data, |
| 212 | + input_schema=input_model.model_json_schema(), |
| 213 | + output_schema=EscalationToolOutput.model_json_schema(), |
| 214 | + ) |
168 | 215 |
|
169 | 216 | outcome_str = ( |
170 | | - channel.outcome_mapping.get(escalation_action) |
171 | | - if channel.outcome_mapping and escalation_action |
| 217 | + channel.outcome_mapping.get(outcome) |
| 218 | + if channel.outcome_mapping and outcome |
172 | 219 | else None |
173 | 220 | ) |
174 | | - outcome = ( |
| 221 | + escalation_action = ( |
175 | 222 | EscalationAction(outcome_str) if outcome_str else EscalationAction.CONTINUE |
176 | 223 | ) |
177 | 224 |
|
178 | 225 | return { |
179 | | - "action": outcome, |
| 226 | + "action": escalation_action, |
180 | 227 | "output": escalation_output, |
181 | | - "outcome": escalation_action, |
| 228 | + "outcome": outcome, |
182 | 229 | "task_id": task_id, |
| 230 | + "task_url": task_url, |
183 | 231 | "assigned_to": assigned_to, |
184 | 232 | } |
185 | 233 |
|
@@ -215,7 +263,7 @@ async def escalation_wrapper( |
215 | 263 | ) |
216 | 264 |
|
217 | 265 | return { |
218 | | - **result["output"], |
| 266 | + "output": result["output"], |
219 | 267 | "outcome": result["outcome"], |
220 | 268 | "task_id": result["task_id"], |
221 | 269 | "assigned_to": result["assigned_to"], |
|
0 commit comments