Skip to content

Commit f078693

Browse files
committed
Rename risky_agent_replay to open_world_tool_replay
1 parent ae16f2a commit f078693

7 files changed

Lines changed: 67 additions & 103 deletions

tools/src/test/java/dev/cel/tools/ai/AgenticPolicyCompilerTest.java

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import dev.cel.expr.ai.Agent;
2424
import dev.cel.expr.ai.AgentMessage;
2525
import dev.cel.expr.ai.Finding;
26+
import dev.cel.expr.ai.Tool;
27+
import dev.cel.expr.ai.ToolAnnotations;
2628
import dev.cel.expr.ai.ToolCall;
2729
import dev.cel.parser.CelStandardMacro;
2830
import dev.cel.policy.testing.PolicyTestSuiteHelper;
@@ -48,15 +50,15 @@ public class AgenticPolicyCompilerTest {
4850
.setStandardMacros(CelStandardMacro.STANDARD_MACROS)
4951
.addMessageTypes(Agent.getDescriptor())
5052
.addMessageTypes(ToolCall.getDescriptor())
53+
.addMessageTypes(Tool.getDescriptor())
54+
.addMessageTypes(ToolAnnotations.getDescriptor())
5155
.addMessageTypes(AgentMessage.getDescriptor())
5256
.addMessageTypes(Finding.getDescriptor())
53-
54-
// Granular Variables
5557
.addVar("agent.input", StructTypeReference.create("cel.expr.ai.AgentMessage"))
58+
.addVar("tool.name", SimpleType.STRING)
59+
.addVar("tool.annotations", StructTypeReference.create("cel.expr.ai.ToolAnnotations"))
5660
.addVar("tool.call", StructTypeReference.create("cel.expr.ai.ToolCall"))
57-
5861
.addFunctionDeclarations(
59-
// ai.finding("name", confidence)
6062
newFunctionDeclaration(
6163
"ai.finding",
6264
newGlobalOverload(
@@ -66,7 +68,6 @@ public class AgenticPolicyCompilerTest {
6668
SimpleType.DOUBLE
6769
)
6870
),
69-
// agent.input.threats() -> List<Finding>
7071
newFunctionDeclaration(
7172
"threats",
7273
newMemberOverload(
@@ -75,7 +76,6 @@ public class AgenticPolicyCompilerTest {
7576
StructTypeReference.create("cel.expr.ai.AgentMessage")
7677
)
7778
),
78-
// tool.call.sensitivityLabel("pii") -> List<Finding> (Empty list if no match)
7979
newFunctionDeclaration(
8080
"sensitivityLabel",
8181
newMemberOverload(
@@ -85,7 +85,6 @@ public class AgenticPolicyCompilerTest {
8585
SimpleType.STRING
8686
)
8787
),
88-
// list(Finding).contains(list(Finding)) -> bool
8988
newFunctionDeclaration(
9089
"contains",
9190
newMemberOverload(
@@ -131,14 +130,11 @@ public class AgenticPolicyCompilerTest {
131130
(args) -> {
132131
ToolCall tool = (ToolCall) args[0];
133132
String label = (String) args[1];
134-
135-
// Mock PII detection: if tool name contains "PII", return a finding
136133
if ("pii".equals(label) && tool.getName().contains("PII")) {
137134
return ImmutableList.of(
138135
Finding.newBuilder().setValue("pii").setConfidence(1.0).build()
139136
);
140137
}
141-
// Return empty list instead of Optional.empty()
142138
return ImmutableList.of();
143139
}
144140
),
@@ -148,18 +144,13 @@ public class AgenticPolicyCompilerTest {
148144
(args) -> {
149145
List<Finding> actualFindings = (List<Finding>) args[0];
150146
List<Finding> expectedFindings = (List<Finding>) args[1];
151-
for (Finding expected : expectedFindings) {
152-
boolean found = false;
153-
for (Finding actual : actualFindings) {
154-
if (actual.getValue().equals(expected.getValue()) &&
155-
actual.getConfidence() >= expected.getConfidence()) {
156-
found = true;
157-
break;
158-
}
159-
}
160-
if (found) return true;
161-
}
162-
return false;
147+
148+
return expectedFindings.stream().anyMatch(expected ->
149+
actualFindings.stream().anyMatch(actual ->
150+
actual.getValue().equals(expected.getValue()) &&
151+
actual.getConfidence() >= expected.getConfidence()
152+
)
153+
);
163154
}
164155
)
165156
)
@@ -182,6 +173,10 @@ private enum AgenticPolicyTestCase {
182173
REQUIRE_USER_CONFIRMATION_FOR_TOOL(
183174
"require_user_confirmation_for_tool.celpolicy",
184175
"require_user_confirmation_for_tool_tests.yaml"
176+
),
177+
OPEN_WORLD_TOOL_REPLAY(
178+
"open_world_tool_replay.celpolicy",
179+
"open_world_tool_replay_tests.yaml"
185180
);
186181

187182
private final String policyFilePath;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: "policy.safety.open_world_replay"
2+
default: allow
3+
4+
rules:
5+
- description: "Limit turn window for open-world tools (internet access)"
6+
condition: |
7+
tool.annotations.open_world
8+
effect: replay
9+
output_expr: |
10+
{
11+
'type': 'USER',
12+
'turn_window': 1,
13+
'reason': 'Tool interacts with the open world.'
14+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
description: "Open World Tool Replay Policy Tests"
2+
3+
section:
4+
- name: "Capability Checks"
5+
tests:
6+
- name: "Open World Tool (Replay)"
7+
input:
8+
tool.annotations:
9+
expr: >
10+
ToolAnnotations{ open_world: true }
11+
tool.call:
12+
expr: >
13+
ToolCall{ name: "internet_search" }
14+
output: >
15+
{
16+
"effect": "replay",
17+
"details": {
18+
"type": "USER",
19+
"turn_window": 1,
20+
"reason": "Tool interacts with the open world."
21+
}
22+
}
23+
24+
- name: "Closed World Tool (Allow)"
25+
input:
26+
tool.annotations:
27+
expr: >
28+
ToolAnnotations{ open_world: false }
29+
tool.call:
30+
expr: >
31+
ToolCall{ name: "calculator" }
32+
output: >
33+
{
34+
"effect": "allow",
35+
"message": ""
36+
}

tools/src/test/resources/risky_agent_replay.celpolicy

Lines changed: 0 additions & 13 deletions
This file was deleted.

tools/src/test/resources/risky_agent_replay_tests.yaml

Lines changed: 0 additions & 29 deletions
This file was deleted.

tools/src/test/resources/tool_walled_garden.celpolicy

Lines changed: 0 additions & 13 deletions
This file was deleted.

tools/src/test/resources/tool_walled_garden_tests.yaml

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)