NumPy allowed · plain Python earns 10 bonus points
Implement cyclic tool-call chain detection, a real safety check preventing an agent from getting stuck in an infinite tool-calling loop (tool A triggers tool B triggers tool A again).
Implement has_cyclic_tool_chain(call_chain). call_chain is the ORDERED sequence of tool names called so far in the current agent turn. Return True if any CONSECUTIVE, CONTIGUOUS subsequence of length >= 2 repeats immediately after itself (e.g. [A,B,A,B] has [A,B] repeating -- a real detected loop). Check repeat-unit lengths from 1 up to len(call_chain)//2.
has_cyclic_tool_chain(call_chain: list[str]) -> bool