Skip to content

Commit d7950f0

Browse files
feat: add asset recipient support for guardrails
1 parent fe16c22 commit d7950f0

4 files changed

Lines changed: 217 additions & 45 deletions

File tree

src/uipath_langchain/agent/guardrails/actions/escalate_action.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from langchain_core.messages import AIMessage, AnyMessage, BaseMessage, ToolMessage
99
from langgraph.types import Command, interrupt
1010
from uipath._utils import UiPathUrl
11+
from uipath.agent.models.agent import AgentEscalationRecipient
1112
from uipath.platform.common import CreateEscalation, UiPathConfig
1213
from uipath.platform.guardrails import (
1314
BaseGuardrail,
@@ -17,6 +18,7 @@
1718

1819
from ...exceptions import AgentTerminationException
1920
from ...react.types import AgentGuardrailsGraphState
21+
from ...tools.escalation_tool import resolve_recipient_value
2022
from ..types import ExecutionStage
2123
from ..utils import _extract_tool_args_from_message, get_message_content
2224
from .base_action import GuardrailAction, GuardrailActionNode
@@ -35,20 +37,20 @@ def __init__(
3537
app_name: str,
3638
app_folder_path: str,
3739
version: int,
38-
assignee: str,
40+
recipient: AgentEscalationRecipient,
3941
):
4042
"""Initialize EscalateAction with escalation app configuration.
4143
4244
Args:
4345
app_name: Name of the escalation app.
4446
app_folder_path: Folder path where the escalation app is located.
4547
version: Version of the escalation app.
46-
assignee: User or role assigned to handle the escalation.
48+
recipient: Recipient object (StandardRecipient or AssetRecipient).
4749
"""
4850
self.app_name = app_name
4951
self.app_folder_path = app_folder_path
5052
self.version = version
51-
self.assignee = assignee
53+
self.recipient = recipient
5254

5355
def action_node(
5456
self,
@@ -74,6 +76,9 @@ def action_node(
7476
async def _node(
7577
state: AgentGuardrailsGraphState,
7678
) -> Dict[str, Any] | Command[Any]:
79+
# Resolve recipient value (handles both StandardRecipient and AssetRecipient)
80+
assignee = await resolve_recipient_value(self.recipient)
81+
7782
# Validate message count based on execution stage
7883
_validate_message_count(state, execution_stage)
7984

@@ -134,7 +139,7 @@ async def _node(
134139
app_folder_path=self.app_folder_path,
135140
title="Agents Guardrail Task",
136141
data=data,
137-
assignee=self.assignee,
142+
assignee=assignee,
138143
)
139144
)
140145

src/uipath_langchain/agent/guardrails/guardrails_factory.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
AgentUnknownGuardrail,
2121
AgentWordOperator,
2222
AgentWordRule,
23-
StandardRecipient,
2423
)
2524
from uipath.core.guardrails import (
2625
AllFieldsSelector,
@@ -432,18 +431,17 @@ def build_guardrails_with_actions(
432431
)
433432
)
434433
elif isinstance(action, AgentGuardrailEscalateAction):
435-
if isinstance(action.recipient, StandardRecipient):
436-
result.append(
437-
(
438-
converted_guardrail,
439-
EscalateAction(
440-
app_name=action.app.name,
441-
app_folder_path=action.app.folder_name,
442-
version=action.app.version,
443-
assignee=action.recipient.value,
444-
),
445-
)
434+
result.append(
435+
(
436+
converted_guardrail,
437+
EscalateAction(
438+
app_name=action.app.name,
439+
app_folder_path=action.app.folder_name,
440+
version=action.app.version,
441+
recipient=action.recipient,
442+
),
446443
)
444+
)
447445
elif isinstance(action, AgentGuardrailFilterAction):
448446
result.append((converted_guardrail, FilterAction(fields=action.fields)))
449447
return result

0 commit comments

Comments
 (0)