Lesson 3 of 5 · 2 min
Guard rails in code
Limits belong in code, where the model cannot talk its way past them: a step limit, a spending limit and a check for the same call repeating.
def run(calls, max_steps=8):
seen = set()
for i, call in enumerate(calls):
if i >= max_steps:
return "stopped: step limit"
if call in seen:
return f"stopped: repeated {call}"
seen.add(call)
return "finished"
print(run(["search a", "read b", "search a"]))
print(run([f"read {i}" for i in range(20)]))
