-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathtest_agent.py
More file actions
3839 lines (3579 loc) · 163 KB
/
test_agent.py
File metadata and controls
3839 lines (3579 loc) · 163 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
from typing import Any
import pytest
from pydantic import TypeAdapter, ValidationError
from uipath.agent.models.agent import (
AgentA2aResourceConfig,
AgentBooleanOperator,
AgentBooleanRule,
AgentBuiltInValidatorGuardrail,
AgentContextResourceConfig,
AgentContextRetrievalMode,
AgentContextType,
AgentCustomGuardrail,
AgentDefinition,
AgentEscalationChannel,
AgentEscalationRecipient,
AgentEscalationRecipientType,
AgentEscalationResourceConfig,
AgentGuardrailActionType,
AgentGuardrailBlockAction,
AgentGuardrailEscalateAction,
AgentGuardrailLogAction,
AgentGuardrailSeverityLevel,
AgentGuardrailUnknownAction,
AgentIntegrationToolResourceConfig,
AgentInternalBatchTransformToolProperties,
AgentInternalDeepRagToolProperties,
AgentInternalToolResourceConfig,
AgentInternalToolType,
AgentIxpExtractionResourceConfig,
AgentIxpVsEscalationResourceConfig,
AgentMcpResourceConfig,
AgentMessageRole,
AgentNumberOperator,
AgentNumberRule,
AgentProcessToolResourceConfig,
AgentResourceType,
AgentToolArgumentPropertiesVariant,
AgentToolType,
AgentUnknownGuardrail,
AgentUnknownResourceConfig,
AgentUnknownToolResourceConfig,
AgentWordOperator,
AgentWordRule,
ArgumentEmailRecipient,
ArgumentGroupNameRecipient,
AssetRecipient,
BatchTransformFileExtension,
BatchTransformWebSearchGrounding,
CitationMode,
DeepRagFileExtension,
StandardRecipient,
TaskTitleType,
TextBuilderTaskTitle,
TextToken,
TextTokenType,
)
from uipath.platform.guardrails import (
EnumListParameterValue,
MapEnumParameterValue,
)
class TestAgentBuilderConfig:
def test_agent_with_all_tool_types_loads(self):
"""Test that AgentDefinition can load a complete agent package with all tool types"""
json_data = {
"version": "1.0.0",
"id": "e0f589ff-469a-44b3-8c5f-085826d8fa55",
"name": "Agent with All Tools",
"metadata": {"isConversational": False, "storageVersion": "22.0.0"},
"messages": [
{
"role": "System",
"content": "You are an agentic assistant.",
"contentTokens": [
{
"type": "simpleText",
"rawString": "You are an agentic assistant.",
}
],
},
{
"role": "User",
"content": "Use the provided tools. Execute {{task}} the number of {{times}}.",
"contentTokens": [
{
"type": "simpleText",
"rawString": "Use the provided tools. Execute ",
},
{
"type": "variable",
"rawString": "input.task",
},
{
"type": "simpleText",
"rawString": " the number of ",
},
{
"type": "variable",
"rawString": "input.times",
},
{
"type": "simpleText",
"rawString": ".",
},
],
},
],
"inputSchema": {
"type": "object",
"required": ["task"],
"properties": {"task": {"type": "string"}, "times": {"type": "number"}},
},
"outputSchema": {
"type": "object",
"properties": {
"task_summary": {
"type": "string",
"description": "describe the actions you have taken in a concise step by step summary",
}
},
"title": "Outputs",
"required": ["task_summary"],
},
"settings": {
"model": "gpt-5-2025-08-07",
"maxTokens": 16384,
"temperature": 0,
"engine": "basic-v1",
"byomProperties": {
"connectionId": "test-byom-connection-id",
"connectorKey": "uipath-openai-openai",
},
},
"resources": [
{
"$resourceType": "tool",
"type": "ProcessOrchestration",
"$guardrailType": "custom",
"id": "001",
"rules": [{"$ruleType": "always", "applyTo": "inputAndOutput"}],
"selector": {"scopes": ["Tool"]},
"inputSchema": {
"type": "object",
"properties": {"in_arg": {"type": "string", "title": "in_arg"}},
"required": [],
},
"outputSchema": {
"type": "object",
"properties": {
"out_arg": {"type": "string", "title": "out_arg"}
},
"required": [],
},
"arguments": {},
"settings": {"timeout": 0, "maxAttempts": 0, "retryDelay": 0},
"properties": {
"processName": "Basic.Agentic.Process.with.In.and.Out.Arguments",
"folderPath": "TestFolder/Complete Solution 30 Sept",
},
"name": "Maestro Workflow",
"description": "agentic process to be invoked by the agent",
},
{
"$resourceType": "escalation",
"id": "be506447-2cf1-47e6-a124-2930e6f0f3d8",
"channels": [
{
"name": "Channel",
"description": "Channel description",
"type": "ActionCenter",
"inputSchema": {
"type": "object",
"properties": {
"AgentName": {"type": "string"},
"Statement": {"type": "string"},
},
"required": ["AgentName", "Statement"],
},
"outputSchema": {
"type": "object",
"properties": {"Reason": {"type": "string"}},
},
"outcomeMapping": {
"Approve": "continue",
"Reject": "continue",
},
"properties": {
"appName": "AgentQuestionApp",
"appVersion": 1,
"folderName": "TestFolder/Complete Solution 30 Sept",
"resourceKey": "b2ecb40b-dcce-4f71-96ae-8fa895905ae2",
"isActionableMessageEnabled": True,
"actionableMessageMetaData": {
"fieldSet": {
"type": "fieldSet",
"id": "3705cfbb-d1fb-4567-b1dd-036107c5c084",
"fields": [
{
"id": "AgentName",
"name": "AgentName",
"type": "Fact",
"placeHolderText": "",
},
{
"id": "Statement",
"name": "Statement",
"type": "Fact",
"placeHolderText": "",
},
{
"id": "Reason",
"name": "Reason",
"type": "Input.Text",
"placeHolderText": "",
},
],
},
"actionSet": {
"type": "actionSet",
"id": "9ecd2de3-7ac3-47a6-836c-af1eaf67f9ca",
"actions": [
{
"id": "Approve",
"name": "Approve",
"title": "Approve",
"type": "Action.Http",
"isPrimary": True,
},
{
"id": "Reject",
"name": "Reject",
"title": "Reject",
"type": "Action.Http",
"isPrimary": True,
},
],
},
},
},
"recipients": [
{
"value": "a26a9809-69ee-427a-9f05-ba00623fef80",
"type": "UserId",
}
],
"taskTitle": "Test Task",
"priority": "Medium",
"labels": ["new", "stuff"],
}
],
"isAgentMemoryEnabled": True,
"escalationType": 0,
"name": "Human in the Loop App",
"description": "an app for the agent to ask questions for the human",
},
{
"$resourceType": "context",
"folderPath": "TestFolder",
"indexName": "MCP Documentation Index",
"settings": {
"threshold": 0,
"resultCount": 3,
"retrievalMode": "Semantic",
"query": {
"description": "The query for the Semantic strategy.",
"variant": "Dynamic",
},
"folderPathPrefix": {},
"fileExtension": {"value": "All"},
},
"name": "MCP Documentation Index",
"description": "",
},
{
"$resourceType": "tool",
"id": "13b3928e-fad8-4bc1-ac06-31718143ded1",
"referenceKey": "b54f2c33-40ee-4dda-b662-b6f787bc1ede",
"name": "Basic RPA Process",
"type": "process",
"description": "RPA process to execute a given task",
"location": "external",
"isEnabled": True,
"inputSchema": {
"type": "object",
"properties": {"task": {"type": "string"}},
"required": ["task"],
},
"outputSchema": {
"type": "object",
"properties": {"output": {"type": "string"}},
},
"settings": {},
"argumentProperties": {
"task": {
"variant": "argument",
"argumentPath": "$['task']",
"isSensitive": False,
}
},
"properties": {
"processName": "Basic RPA Process",
"folderPath": "TestFolder/Complete Solution 30 Sept",
},
},
{
"$resourceType": "tool",
"type": "Api",
"inputSchema": {"type": "object", "properties": {}},
"outputSchema": {
"type": "object",
"properties": {
"success": {"type": "boolean"},
"summary": {"type": "string"},
},
"title": "Outputs",
"required": ["success", "summary"],
},
"arguments": {},
"settings": {"timeout": 0, "maxAttempts": 0, "retryDelay": 0},
"properties": {
"processName": "Basic Http and Log API Wf",
"folderPath": "TestFolder/Complete Solution 30 Sept",
},
"name": "Basic Http and Log API Wf",
"description": "api workflow to be invoked by agent",
},
{
"$resourceType": "mcp",
"folderPath": "TestFolder/Complete Solution 30 Sept",
"slug": "time-mcp",
"availableTools": [
{
"name": "get_current_time",
"description": "Get current time in a specific timezones",
"inputSchema": {
"type": "object",
"properties": {
"timezone": {
"type": "string",
"description": "IANA timezone name (e.g., 'America/New_York', 'Europe/London'). Use 'UTC' as local timezone if no timezone provided by the user.",
}
},
"required": ["timezone"],
},
"argumentProperties": {
"timezone": {
"variant": "textBuilder",
"tokens": [
{
"type": "simpleText",
"rawString": "Europe/London",
},
],
"isSensitive": False,
},
},
},
{
"name": "convert_time",
"description": "Convert time between timezones",
"inputSchema": {
"type": "object",
"properties": {
"source_timezone": {
"type": "string",
"description": "Source IANA timezone name (e.g., 'America/New_York', 'Europe/London'). Use 'UTC' as local timezone if no source timezone provided by the user.",
},
"time": {
"type": "string",
"description": "Time to convert in 24-hour format (HH:MM)",
},
"target_timezone": {
"type": "string",
"description": "Target IANA timezone name (e.g., 'Asia/Tokyo', 'America/San_Francisco'). Use 'UTC' as local timezone if no target timezone provided by the user.",
},
},
"required": [
"source_timezone",
"time",
"target_timezone",
],
},
},
],
"name": "time_mcp",
"description": "mcp server to get the current time",
},
{
"$resourceType": "tool",
"type": "Agent",
"inputSchema": {"type": "object", "properties": {}},
"outputSchema": {
"type": "object",
"properties": {
"content": {
"type": "string",
"description": "Output content",
}
},
},
"arguments": {},
"settings": {"timeout": 0, "maxAttempts": 0, "retryDelay": 0},
"properties": {
"processName": "Current Date Agent",
"folderPath": "TestFolder/Complete Solution 30 Sept",
},
"name": "Current Date Agent",
"description": "subagent to be invoked by agent",
},
{
"$resourceType": "tool",
"type": "Integration",
"inputSchema": {
"type": "object",
"properties": {
"To": {"type": "string", "title": "To"},
"Subject": {"type": "string", "title": "Subject"},
},
"required": ["To"],
},
"outputSchema": {"type": "object", "properties": {}},
"arguments": {},
"settings": {"timeout": 0, "maxAttempts": 0, "retryDelay": 0},
"properties": {
"toolPath": "/SendEmail",
"objectName": "SendEmail",
"toolDisplayName": "Send Email",
"toolDescription": "Sends an email message",
"method": "POST",
"bodyStructure": {
"contentType": "multipart",
"jsonBodySection": "body",
},
"connection": {
"id": "cccccccc-0000-0000-0000-000000000004",
"name": "Gmail Connection",
"elementInstanceId": 0,
"apiBaseUri": "",
"state": "enabled",
"isDefault": False,
"connector": {
"key": "uipath-google-gmail",
"name": "Gmail",
"enabled": True,
},
"folder": {"key": "bbbbbbbb-0000-0000-0000-000000000004"},
"solutionProperties": {
"resourceKey": "cccccccc-0000-0000-0000-000000000004"
},
},
"parameters": [
{
"name": "To",
"displayName": "To",
"type": "string",
"fieldLocation": "body",
"value": "{{prompt}}",
"fieldVariant": "dynamic",
"sortOrder": 1,
"required": True,
},
],
},
"name": "Send Email",
"description": "Send an email via Gmail",
"isEnabled": True,
},
],
"features": [],
}
# Test that the model loads without errors
config: AgentDefinition = TypeAdapter(AgentDefinition).validate_python(
json_data
)
# Basic assertions
assert isinstance(config, AgentDefinition), (
"AgentDefinition should be a low code agent."
)
assert config.id == "e0f589ff-469a-44b3-8c5f-085826d8fa55"
assert config.name == "Agent with All Tools"
assert config.version == "1.0.0"
assert len(config.messages) == 2
assert len(config.resources) == 8 # All tool types + escalation + context + mcp
assert config.settings.engine == "basic-v1"
assert config.settings.max_tokens == 16384
assert config.settings.byom_properties is not None
assert (
config.settings.byom_properties.connection_id == "test-byom-connection-id"
)
assert config.settings.byom_properties.connector_key == "uipath-openai-openai"
# Validate resource types
resource_types = [resource.resource_type for resource in config.resources]
assert resource_types.count(AgentResourceType.ESCALATION) == 1
assert resource_types.count(AgentResourceType.TOOL) == 5
assert resource_types.count(AgentResourceType.CONTEXT) == 1
assert resource_types.count(AgentResourceType.MCP) == 1
# Validate tool types (ProcessOrchestration, Process, Api, Agent, Integration)
tool_resources = [
r for r in config.resources if r.resource_type == AgentResourceType.TOOL
]
assert len(tool_resources) == 5
tool_names = [t.name for t in tool_resources]
assert "Maestro Workflow" in tool_names # ProcessOrchestration
assert "Basic RPA Process" in tool_names # Process
assert "Basic Http and Log API Wf" in tool_names # Api
assert "Current Date Agent" in tool_names # Agent
assert "Send Email" in tool_names # Integration
# Validate MCP resource
mcp_resources = [
r for r in config.resources if r.resource_type == AgentResourceType.MCP
]
assert len(mcp_resources) == 1
mcp_resource = mcp_resources[0]
assert isinstance(mcp_resource, AgentMcpResourceConfig)
assert mcp_resource.name == "time_mcp"
assert mcp_resource.slug == "time-mcp"
assert len(mcp_resource.available_tools) == 2
assert mcp_resource.available_tools[0].name == "get_current_time"
assert mcp_resource.available_tools[1].name == "convert_time"
# Validate that outputSchema is None when not provided in JSON
assert mcp_resource.available_tools[0].output_schema is None
assert mcp_resource.available_tools[1].output_schema is None
# Validate escalation resource with detailed properties
escalation_resource = next(
r
for r in config.resources
if r.resource_type == AgentResourceType.ESCALATION
)
assert isinstance(escalation_resource, AgentEscalationResourceConfig)
assert escalation_resource.name == "Human in the Loop App"
assert escalation_resource.is_agent_memory_enabled is True
assert len(escalation_resource.channels) == 1
channel = escalation_resource.channels[0]
assert channel.name == "Channel"
assert channel.task_title == "Test Task"
assert channel.priority == "Medium"
assert channel.labels == ["new", "stuff"]
# Validate context resource
context_resources = [
r for r in config.resources if r.resource_type == AgentResourceType.CONTEXT
]
assert len(context_resources) == 1
assert context_resources[0].name == "MCP Documentation Index"
# Validate Integration tool resource
integration_tools = [
r
for r in config.resources
if isinstance(r, AgentIntegrationToolResourceConfig)
]
assert len(integration_tools) == 1
integration_tool = integration_tools[0]
assert integration_tool.type == AgentToolType.INTEGRATION
assert integration_tool.name == "Send Email"
assert integration_tool.properties.tool_path == "/SendEmail"
assert integration_tool.properties.method == "POST"
assert integration_tool.properties.connection.connector is not None
assert (
integration_tool.properties.connection.connector["key"]
== "uipath-google-gmail"
)
assert integration_tool.properties.body_structure is not None
assert integration_tool.properties.body_structure["contentType"] == "multipart"
assert len(integration_tool.properties.parameters) == 1
assert integration_tool.properties.parameters[0].name == "To"
def test_agent_config_loads_guardrails(self):
"""Test that AgentConfig can load and parse both Custom and Built-in guardrails from real JSON"""
json_data = {
"id": "55f89eb5-e4dc-4129-8c3d-da80f6c7f921",
"name": "NumberTranslator",
"version": "1.0.0",
"settings": {
"model": "gpt-4o-2024-11-20",
"maxTokens": 16384,
"temperature": 0,
"engine": "basic-v1",
},
"inputSchema": {
"type": "object",
"required": ["number"],
"properties": {"number": {"type": "string", "description": "number"}},
},
"outputSchema": {
"type": "object",
"properties": {
"content": {"type": "string", "description": "Output content"}
},
},
"metadata": {"storageVersion": "23.0.0", "isConversational": False},
"resources": [
{
"$resourceType": "tool",
"name": "StringToNumber",
"description": "Converts word to number",
"type": "agent",
"inputSchema": {
"type": "object",
"properties": {"word": {"type": "string"}},
"required": ["word"],
},
"outputSchema": {"type": "object", "properties": {}},
"arguments": {},
"settings": {"timeout": 0, "maxAttempts": 0, "retryDelay": 0},
"properties": {
"processName": "StringToNumber",
"folderPath": "solution_folder",
},
}
],
"guardrails": [
{
"$guardrailType": "builtInValidator",
"id": "2f36abe1-2ae1-457b-b565-ccf7a1b6d088",
"name": "PII detection guardrail",
"description": "This validator is designed to detect personally identifiable information using Azure Cognitive Services",
"validatorType": "pii_detection",
"validatorParameters": [
{
"$parameterType": "enum-list",
"id": "entities",
"value": ["Email", "Address"],
},
{
"$parameterType": "map-enum",
"id": "entityThresholds",
"value": {"Email": 1, "Address": 0.7},
},
],
"action": {
"$actionType": "escalate",
"app": {
"id": "cf4cb73d-7310-49b1-9a9e-e7653dad7f4e",
"version": "0",
"name": "-Guardrail Form",
"folderId": "d0195402-505d-54c1-0b94-5faa5bf69ad1",
"folderName": "solution_folder",
},
"recipient": {
"type": 1,
"value": "5f872639-fc71-4a50-b17d-f68eb357b436",
"displayName": "User Name",
},
},
"enabledForEvals": True,
"selector": {"scopes": ["Tool"], "matchNames": ["StringToNumber"]},
},
{
"$guardrailType": "custom",
"id": "7b2a9218-c3d2-4f19-a800-8d6fe77a64e2",
"name": "ExcludeHELLO",
"description": 'the input shouldn\'t be "hello"',
"rules": [
{
"$ruleType": "word",
"fieldSelector": {
"$selectorType": "specific",
"fields": [{"path": "word", "source": "input"}],
},
"operator": "doesNotContain",
"value": "hello",
}
],
"action": {"$actionType": "block", "reason": 'Input is "hello"'},
"enabledForEvals": True,
"selector": {"scopes": ["Tool"], "matchNames": ["StringToNumber"]},
},
],
"messages": [
{
"role": "system",
"content": "You are a English to Romanian translator",
},
{
"role": "user",
"content": "Use the tool StringToNumber to convert the string {{number}} into a number type, then write the obtained number in romanian. ",
},
],
}
# Parse with TypeAdapter
config: AgentDefinition = TypeAdapter(AgentDefinition).validate_python(
json_data
)
# Validate the main agent properties
assert isinstance(config, AgentDefinition), "Agent should be a AgentDefinition"
# Validate tool resource type discrimination
tool_resource = config.resources[0]
assert isinstance(tool_resource, AgentProcessToolResourceConfig), (
"Tool should be parsed as AgentProcessToolResourceConfig based on type='Agent'"
)
assert tool_resource.resource_type == AgentResourceType.TOOL
assert tool_resource.type == AgentToolType.AGENT # The discriminator field
# Validate agent-level guardrails
assert config.guardrails is not None
assert len(config.guardrails) == 2
# Test built-in validator at agent level
agent_builtin_guardrail = config.guardrails[0]
assert isinstance(agent_builtin_guardrail, AgentBuiltInValidatorGuardrail), (
"Agent guardrail should be AgentBuiltInValidatorGuardrail"
)
# Check base guardrail properties
assert agent_builtin_guardrail.id == "2f36abe1-2ae1-457b-b565-ccf7a1b6d088"
assert agent_builtin_guardrail.name == "PII detection guardrail"
assert (
agent_builtin_guardrail.description
== "This validator is designed to detect personally identifiable information using Azure Cognitive Services"
)
assert agent_builtin_guardrail.enabled_for_evals is True
assert agent_builtin_guardrail.selector is not None
assert agent_builtin_guardrail.selector.scopes == ["Tool"]
assert agent_builtin_guardrail.selector.match_names == ["StringToNumber"]
# Check built-in validator specific properties
assert agent_builtin_guardrail.guardrail_type == "builtInValidator"
assert agent_builtin_guardrail.validator_type == "pii_detection"
assert len(agent_builtin_guardrail.validator_parameters) == 2
# Check validator parameters
enum_param = agent_builtin_guardrail.validator_parameters[0]
assert isinstance(enum_param, EnumListParameterValue), (
"Should be EnumListParameterValue based on $parameterType='enum-list'"
)
assert enum_param.parameter_type == "enum-list"
assert enum_param.id == "entities"
assert enum_param.value == ["Email", "Address"]
map_param = agent_builtin_guardrail.validator_parameters[1]
assert isinstance(map_param, MapEnumParameterValue), (
"Should be MapEnumParameterValue based on $parameterType='map-enum'"
)
assert map_param.parameter_type == "map-enum"
assert map_param.id == "entityThresholds"
assert map_param.value == {"Email": 1, "Address": 0.7}
# Check action
escalate_action = agent_builtin_guardrail.action
assert isinstance(escalate_action, AgentGuardrailEscalateAction), (
"Should be EscalateAction based on $actionType='escalate'"
)
assert escalate_action.action_type == "escalate"
assert escalate_action.app.id == "cf4cb73d-7310-49b1-9a9e-e7653dad7f4e"
assert escalate_action.app.name == "-Guardrail Form"
assert escalate_action.app.folder_name == "solution_folder"
assert escalate_action.recipient.type == AgentEscalationRecipientType.USER_ID
assert escalate_action.recipient.value == "5f872639-fc71-4a50-b17d-f68eb357b436"
assert escalate_action.recipient.display_name == "User Name"
# Test custom guardrail at agent level
agent_custom_guardrail = config.guardrails[1]
assert isinstance(agent_custom_guardrail, AgentCustomGuardrail), (
"Agent custom guardrail should be AgentCustomGuardrail"
)
# Check base guardrail properties
assert agent_custom_guardrail.id == "7b2a9218-c3d2-4f19-a800-8d6fe77a64e2"
assert agent_custom_guardrail.name == "ExcludeHELLO"
assert agent_custom_guardrail.description == 'the input shouldn\'t be "hello"'
assert agent_custom_guardrail.enabled_for_evals is True
assert agent_custom_guardrail.selector.scopes == ["Tool"]
assert agent_custom_guardrail.selector.match_names == ["StringToNumber"]
# Check custom guardrail specific properties
assert agent_custom_guardrail.guardrail_type == "custom"
assert len(agent_custom_guardrail.rules) == 1
# Check rule
rule = agent_custom_guardrail.rules[0]
assert isinstance(rule, AgentWordRule), (
"Rule should be WordRule based on $ruleType='word'"
)
assert rule.rule_type == "word"
assert rule.operator == "doesNotContain" # Updated to use the correct operator
assert rule.value == "hello"
# Check field selector
assert rule.field_selector.selector_type == "specific"
assert len(rule.field_selector.fields) == 1
assert rule.field_selector.fields[0].path == "word"
assert rule.field_selector.fields[0].source == "input"
# Check action
block_action = agent_custom_guardrail.action
assert isinstance(block_action, AgentGuardrailBlockAction), (
"Should be BlockAction based on $actionType='block'"
)
assert block_action.action_type == "block"
assert block_action.reason == 'Input is "hello"'
def test_agent_with_gmail_send_email_integration(self):
"""Test agent with Gmail Send Email integration tool"""
json_data = {
"version": "1.0.0",
"id": "aaaaaaaa-0000-0000-0000-000000000001",
"name": "Agent with Send Email Tool",
"metadata": {"isConversational": False, "storageVersion": "26.0.0"},
"messages": [
{"role": "System", "content": "You are an agentic assistant."},
],
"inputSchema": {"type": "object", "properties": {}},
"outputSchema": {
"type": "object",
"properties": {"content": {"type": "string"}},
},
"settings": {
"model": "gpt-4o-2024-11-20",
"maxTokens": 16384,
"temperature": 0,
"engine": "basic-v2",
},
"resources": [
{
"$resourceType": "tool",
"type": "Integration",
"inputSchema": {
"type": "object",
"properties": {
"SaveAsDraft": {
"type": "boolean",
"title": "Save as draft",
"description": "Send an email message. By default, the email will be saved as draft.",
},
"CC": {
"type": "string",
"title": "CC",
"description": "The secondary recipients of the email, separated by comma (,)",
},
"Importance": {
"type": "string",
"title": "Importance",
"description": "The importance of the mail",
"enum": ["normal"],
"oneOf": [
{"const": "normal", "title": "Normal"},
{"const": "high", "title": "High"},
{"const": "low", "title": "Low"},
],
},
"ReplyTo": {
"type": "string",
"title": "Reply to",
"description": "The email addresses to use when replying, separated by comma (,)",
},
"BCC": {
"type": "string",
"title": "BCC",
"description": "The hidden recipients of the email, separated by comma (,)",
},
"To": {
"type": "string",
"title": "To",
"description": "The primary recipients of the email, separated by comma (,)",
},
"Body": {
"type": "string",
"title": "Body",
"description": "The body of the email",
},
"Subject": {
"type": "string",
"title": "Subject",
"description": "The subject of the email",
},
},
"additionalProperties": False,
"required": ["To"],
},
"outputSchema": {"type": "object", "properties": {}},
"arguments": {},
"settings": {"timeout": 0, "maxAttempts": 0, "retryDelay": 0},
"properties": {
"toolPath": "/SendEmail",
"objectName": "SendEmail",
"toolDisplayName": "Send Email",
"toolDescription": "Sends an email message",
"method": "POST",
"bodyStructure": {
"contentType": "multipart",
"jsonBodySection": "body",
},
"connection": {
"id": "cccccccc-0000-0000-0000-000000000001",
"name": "Gmail Connection",
"elementInstanceId": 0,
"apiBaseUri": "",
"state": "enabled",
"isDefault": False,
"connector": {
"key": "uipath-google-gmail",
"name": "Gmail",
"enabled": True,
},
"folder": {"key": "bbbbbbbb-0000-0000-0000-000000000001"},
"solutionProperties": {
"resourceKey": "cccccccc-0000-0000-0000-000000000001"
},
},
"parameters": [
{
"name": "body",
"displayName": "Body",
"type": "string",
"fieldLocation": "multipart",
"value": "{{prompt}}",
"description": "The message body\n",
"position": "primary",
"sortOrder": 1,
"required": True,
"fieldVariant": "dynamic",
"dynamic": True,
"isCascading": False,
"enumValues": None,
"loadReferenceOptionsByDefault": None,
"dynamicBehavior": [],
"reference": None,
},
{
"name": "SaveAsDraft",
"displayName": "Save as draft",
"type": "boolean",
"fieldLocation": "query",
"value": False,
"description": "",
"position": "primary",
"sortOrder": 2,
"required": False,
"fieldVariant": "static",
"dynamic": True,
"isCascading": False,
"enumValues": None,
"loadReferenceOptionsByDefault": None,
"dynamicBehavior": [],
"reference": None,
},
{
"name": "To",
"displayName": "To",
"type": "string",
"fieldLocation": "body",
"value": "{{prompt}}",
"description": "The primary recipients of the email, separated by comma (,)",
"position": "primary",
"sortOrder": 3,
"required": True,
"fieldVariant": "dynamic",
"isCascading": False,
"dynamic": True,
"enumValues": None,
"loadReferenceOptionsByDefault": None,
"dynamicBehavior": [],
"reference": None,
},
{
"name": "Subject",
"displayName": "Subject",
"type": "string",
"fieldLocation": "body",
"value": "{{prompt}}",
"description": "The subject of the email",
"position": "primary",
"sortOrder": 4,
"required": False,
"fieldVariant": "dynamic",
"isCascading": False,
"dynamic": True,
"enumValues": None,
"loadReferenceOptionsByDefault": None,
"dynamicBehavior": [],
"reference": None,
},
{
"name": "Body",
"displayName": "Body",
"type": "string",
"fieldLocation": "body",
"value": "{{prompt}}",
"description": "The body of the email",
"componentType": "RichTextEditorHTML",
"position": "primary",
"sortOrder": 5,
"required": False,