Skip to content

Commit 8902dcd

Browse files
refactor(agent/tools): extract create_task_for_channel from create_escalation_tool
Consolidate the per-channel task dispatch (Action Center vs QuickForm) into a single create_task_for_channel function; create_escalation_task collapses to one call. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 13c6b56 commit 8902dcd

1 file changed

Lines changed: 60 additions & 36 deletions

File tree

src/uipath_langchain/agent/tools/escalation_tool.py

Lines changed: 60 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,58 @@ def _get_exported_trace_id(trace_id: str | None) -> str | None:
252252
return trace_id
253253

254254

255+
async def create_task_for_channel(
256+
client: UiPath,
257+
channel: EscalationChannel,
258+
*,
259+
title: str,
260+
data: dict[str, Any],
261+
recipient: TaskRecipient | None,
262+
folder_path: str | None,
263+
) -> Task:
264+
"""Create the Action Center or quick-form task backing an escalation channel.
265+
266+
Quick-form channels (``actionCenterQuickForm``) dispatch to
267+
``create_quickform_async`` with their inline schema; all other channels
268+
dispatch to ``create_async`` against the channel's Action Center app.
269+
"""
270+
if isinstance(channel, AgentQuickFormEscalationChannel):
271+
schema_id = channel.properties.schema_id
272+
if schema_id is None:
273+
raise AgentRuntimeError(
274+
code=AgentRuntimeErrorCode.TERMINATION_ESCALATION_ERROR,
275+
title="Quick form escalation is missing a schema id",
276+
detail=(
277+
f"Escalation '{channel.name}' has a quick form "
278+
"schema without a schemaId."
279+
),
280+
category=UiPathErrorCategory.USER,
281+
)
282+
return await client.tasks.create_quickform_async(
283+
title=title,
284+
task_schema_key=schema_id,
285+
schema=channel.properties.form_schema,
286+
data=data,
287+
folder_path=folder_path,
288+
recipient=recipient,
289+
priority=channel.priority,
290+
labels=channel.labels,
291+
is_actionable_message_enabled=channel.properties.is_actionable_message_enabled,
292+
actionable_message_metadata=channel.properties.actionable_message_meta_data,
293+
)
294+
return await client.tasks.create_async(
295+
title=title,
296+
data=data,
297+
app_name=channel.properties.app_name,
298+
app_folder_path=folder_path,
299+
recipient=recipient,
300+
priority=channel.priority,
301+
labels=channel.labels,
302+
is_actionable_message_enabled=channel.properties.is_actionable_message_enabled,
303+
actionable_message_metadata=channel.properties.actionable_message_meta_data,
304+
)
305+
306+
255307
def create_escalation_tool(
256308
resource: AgentEscalationResourceConfig,
257309
agent: LowCodeAgentDefinition | None = None,
@@ -342,42 +394,14 @@ async def escalate(**_tool_kwargs: Any):
342394
@durable_interrupt
343395
async def create_escalation_task():
344396
client = UiPath()
345-
if isinstance(channel, AgentQuickFormEscalationChannel):
346-
schema_id = channel.properties.schema_id
347-
if schema_id is None:
348-
raise AgentRuntimeError(
349-
code=AgentRuntimeErrorCode.TERMINATION_ESCALATION_ERROR,
350-
title="Quick form escalation is missing a schema id",
351-
detail=(
352-
f"Escalation '{resource.name}' has a quick form "
353-
"schema without a schemaId."
354-
),
355-
category=UiPathErrorCategory.USER,
356-
)
357-
created_task = await client.tasks.create_quickform_async(
358-
title=task_title,
359-
task_schema_key=schema_id,
360-
schema=channel.properties.form_schema,
361-
data=serialized_data,
362-
folder_path=folder_path,
363-
recipient=recipient,
364-
priority=channel.priority,
365-
labels=channel.labels,
366-
is_actionable_message_enabled=channel.properties.is_actionable_message_enabled,
367-
actionable_message_metadata=channel.properties.actionable_message_meta_data,
368-
)
369-
else:
370-
created_task = await client.tasks.create_async(
371-
title=task_title,
372-
data=serialized_data,
373-
app_name=app_name,
374-
app_folder_path=folder_path,
375-
recipient=recipient,
376-
priority=channel.priority,
377-
labels=channel.labels,
378-
is_actionable_message_enabled=channel.properties.is_actionable_message_enabled,
379-
actionable_message_metadata=channel.properties.actionable_message_meta_data,
380-
)
397+
created_task = await create_task_for_channel(
398+
client,
399+
channel,
400+
title=task_title,
401+
data=serialized_data,
402+
recipient=recipient,
403+
folder_path=folder_path,
404+
)
381405

382406
if created_task.id is not None:
383407
_bts_context["task_key"] = str(created_task.id)

0 commit comments

Comments
 (0)