Skip to content

Commit cd61aef

Browse files
committed
feat(guardrails_servie): callable func
1 parent bb1785d commit cd61aef

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

src/uipath/_services/guardrails_service.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ def evaluate_guardrail(
8282
async def execute_guardrail(
8383
self,
8484
validation_result: Dict[str, Any],
85+
callable_func: callable,
8586
guardrail: Guardrail,
8687
tool_name: str,
8788
) -> None:
@@ -95,23 +96,20 @@ async def execute_guardrail(
9596
action = guardrail.action
9697

9798
if isinstance(action, EscalateAction):
98-
from uipath._cli._runtime._hitl import HitlProcessor, HitlReader
99-
10099
action_data = {
101100
"GuardrailName": guardrail.name,
102101
"GuardrailDescription": validation_result.get(
103102
"reason", "No description provided"
104103
),
105-
# TODO must see where to i extract these
106-
# "TenantName": self.config.tenant_name,
107-
# "AgentTrace": must see,
104+
# "TenantName":
105+
# "AgentTrace": ,
108106
"Tool": tool_name,
109-
# "ExecutionStage": validation_result.get("execution_stage", ""),
107+
# "ExecutionStage": ,
110108
# "ToolInputs": ,
111109
# "ToolOutputs": validation_result.get("tool_outputs", {}),
112110
}
113111
# mandatory: app_name + tittle + data + app_version + assignee (def none) + appfolderpath + includemetadata = true
114-
create_action = CreateAction(
112+
callable_func(
115113
title="Guardrail Escalation: " + guardrail.name,
116114
data=action_data,
117115
assignee=action.recipient.value,
@@ -122,20 +120,21 @@ async def execute_guardrail(
122120
app_version=action.app.version,
123121
include_metadata=True,
124122
)
125-
# action_output = interrupt(create_action)
126-
print("Starting escalation action")
127-
processor = HitlProcessor(create_action)
128-
print(f"processor: {processor}")
129-
resume_trigger = await processor.create_resume_trigger()
130-
import json
131-
132-
if hasattr(resume_trigger, "payload") and isinstance(
133-
resume_trigger.payload, dict
134-
):
135-
resume_trigger.payload = json.dumps(resume_trigger.payload)
136-
print(f"resume_trigger: {resume_trigger}")
137-
action_output = await HitlReader.read(resume_trigger)
138-
print(f"action_output: {action_output}")
123+
124+
action_output = callable_func(
125+
CreateAction(
126+
title="Guardrail Escalation: " + guardrail.name,
127+
data=action_data,
128+
assignee=action.recipient.value,
129+
app_name=action.app.name,
130+
app_folder_path=action.app.folder_name,
131+
app_folder_key=action.app.folder_id,
132+
app_key=action.app.id,
133+
app_version=action.app.version,
134+
include_metadata=True,
135+
)
136+
)
137+
139138
print("Escalation action completed.")
140139

141140
if action_output:
@@ -166,8 +165,7 @@ async def execute_guardrail(
166165
print(f"GUARDRAIL LOG [{severity}]: {reason}")
167166

168167
elif isinstance(action, FilterAction):
169-
# TODO: see what it clearly does
170-
# implement filtering logic
168+
# TODO
171169
print(
172170
f"GUARDRAIL FILTER: Fields to filter: {[f.path for f in action.fields]}"
173171
)
@@ -191,6 +189,7 @@ def _should_apply_guardrail(self, guardrail: Guardrail, tool_name: str) -> bool:
191189
async def process_guardrails(
192190
self,
193191
input_data: Union[str, Dict[str, Any]],
192+
handle_guardrail_callable: callable,
194193
guardrails: List[Guardrail],
195194
tool_name: str = "unknown",
196195
*,
@@ -268,6 +267,7 @@ async def process_guardrails(
268267
# Execute the guardrail action
269268
await self.execute_guardrail(
270269
validation_result=validation_result,
270+
callable_func=handle_guardrail_callable,
271271
guardrail=guardrail,
272272
tool_name=tool_name,
273273
)

0 commit comments

Comments
 (0)