-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_agent_loop_reminder_hook.py
More file actions
77 lines (61 loc) · 2.87 KB
/
Copy pathtest_agent_loop_reminder_hook.py
File metadata and controls
77 lines (61 loc) · 2.87 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
import unittest
from agent_loop_reminder_hook import AgentLoopReminderHook
class TestAgentLoopReminderHook(unittest.TestCase):
def setUp(self):
self.hook = AgentLoopReminderHook(agent_id="test_subagent_01")
def test_single_and_different_calls(self):
count, reminder = self.hook.record_tool_call("grep_search", {"query": "auth", "path": "src/"})
self.assertEqual(count, 1)
self.assertIsNone(reminder)
# Different query should reset count
count, reminder = self.hook.record_tool_call("grep_search", {"query": "payment", "path": "src/"})
self.assertEqual(count, 1)
self.assertIsNone(reminder)
def test_escalating_reminders_on_repeats(self):
args = {"query": "auth", "path": "src/"}
# Calls 1 and 2: no reminder
self.hook.record_tool_call("grep_search", args)
self.hook.record_tool_call("grep_search", args)
# Call 3: Advisory reminder
count, rem3 = self.hook.record_tool_call("grep_search", args)
self.assertEqual(count, 3)
self.assertIsNotNone(rem3)
self.assertIn("LOOP ADVISORY", rem3)
# Call 4: no new threshold
count, rem4 = self.hook.record_tool_call("grep_search", args)
self.assertEqual(count, 4)
self.assertIsNone(rem4)
# Call 5: Warning reminder
count, rem5 = self.hook.record_tool_call("grep_search", args)
self.assertEqual(count, 5)
self.assertIsNotNone(rem5)
self.assertIn("LOOP WARNING", rem5)
# Call 8: Critical reminder
self.hook.record_tool_call("grep_search", args)
self.hook.record_tool_call("grep_search", args)
count, rem8 = self.hook.record_tool_call("grep_search", args)
self.assertEqual(count, 8)
self.assertIsNotNone(rem8)
self.assertIn("LOOP CRITICAL", rem8)
def test_transparent_noise_tool_does_not_reset_loop(self):
args = {"file": "main.py"}
self.hook.record_tool_call("read_file", args)
self.hook.record_tool_call("read_file", args)
# Intermediate todo update
self.hook.record_tool_call("update_todo", {"task": "in progress"})
# Third read_file call should trigger 3-repeat advisory despite intermediate todo
count, rem3 = self.hook.record_tool_call("read_file", args)
self.assertEqual(count, 3)
self.assertIsNotNone(rem3)
self.assertIn("LOOP ADVISORY", rem3)
def test_order_invariant_argument_hashing(self):
# Different dictionary key ordering
args1 = {"a": 1, "b": 2, "c": 3}
args2 = {"c": 3, "a": 1, "b": 2}
self.hook.record_tool_call("custom_tool", args1)
self.hook.record_tool_call("custom_tool", args2)
count, rem = self.hook.record_tool_call("custom_tool", args1)
self.assertEqual(count, 3)
self.assertIsNotNone(rem)
if __name__ == "__main__":
unittest.main()