-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathagent_check.py
More file actions
executable file
·33 lines (26 loc) · 1.02 KB
/
Copy pathagent_check.py
File metadata and controls
executable file
·33 lines (26 loc) · 1.02 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
#!/usr/bin/env python3
"""In-agent self-check: after each step, run the step's output through doloop
before letting the agent continue.
A model in a loop cannot see its own loop. doloop can. Use this to catch the
agent slipping, repeating, or drifting that the agent will not catch itself.
"""
import json
import urllib.request
def check(text):
body = json.dumps({"text": text}).encode()
req = urllib.request.Request(
"https://api.doloop.io/v1/check",
data=body, headers={"content-type": "application/json"})
with urllib.request.urlopen(req) as r:
return json.load(r)
def step_ok(step_output):
verdict = check(step_output)
if verdict["verdict"] == "fail":
print("doloop blocked this step:")
for f in verdict["findings"]:
print(f" - [{f['layer']}] {f['message']}")
return False
return True
if __name__ == "__main__":
looping_output = "We we we keep going in circles, in circles, in circles."
print("ship this step?", step_ok(looping_output))