How to Detect AI Agent Loops Without Sending Sensitive Payloads A developer building AgentTrafficCop released SDK version 1.2.0, which adds a hash_only mode that computes a SHA-256 digest of an agent's tool-call payload locally and sends only the digest to the guard service, so repeated actions can be rejected without transmitting customer records, documents or prompts. In the documented example, with the default repeat threshold of three, the first two checks are approved and the third is rejected with REPEATED_PAYLOAD_LOOP. The developer cautions that the approach catches only exact repeats and repeating sequences, not semantic loops, and cannot stop operations that bypass the check. Your agent keeps calling the same tool with the same arguments. Every request succeeds, so retries are not the problem. You want to reject the next repeated action—but you do not want to send customer records, internal documents, or private prompts to another service. For exact repeats and repeating sequences, you can compare locally calculated hashes instead of transmitting raw action contents. AgentTrafficCop SDK 1.2.0 provides this through hash only=True . Your code still has to place the check before the action and stop on rejection. This guide gets you to a working test first, then explains what this approach cannot protect. It is not semantic loop detection, automatic instrumentation, or a guarantee of anonymous processing. Disclosure: I’m building AgentTrafficCop, the tool used in this example. Install or upgrade the SDK, then set your API key in the environment. Use a test key: the example makes real guard requests, consumes approved-message quota, and may add the two named agents to your tracked-agent allowance. It does not call a model or execute a tool. python -m pip install --upgrade 'agenttrafficcop==1.2.0' export ATC API KEY="your-api-key" python import os import uuid from agenttrafficcop import AgentTrafficCopError, GuardSync def main : run id = uuid.uuid4 .hex action = { "tool": "search docs", "arguments": {"query": "refund policy"}, } with GuardSync url="https://api.agenttrafficcop.com", api key=os.environ "ATC API KEY" , dry run=False, as guard: for attempt in range 1, 4 : try: result = guard.check session id=run id, sender="planner", recipient="researcher", intent="tool call", payload=action, hash only=True, except AgentTrafficCopError as exc: print "Action not executed:", exc.error code break if not result.approved: break Replace this print with the protected tool invocation. print "Approved attempt", attempt if name == " main ": main With the default repeat threshold of three, a fresh session, and no other blocking policy, the first two checks are approved and the third is rejected with REPEATED PAYLOAD LOOP . Custom thresholds can change that result. Expected console output under those defaults: Approved attempt 1 Approved attempt 2 Action not executed: REPEATED PAYLOAD LOOP A different error is not a successful loop test. Authentication, exhausted quota, agent limits, or an unavailable service can prevent the example from reaching its third check. Diagnose that response rather than treating every rejection as loop detection. Replace the approval print with your actual protected operation. Keep the guard before execution, preserve failures, and use one stable session ID throughout the run. The service cannot stop an operation that bypasses the check or undo work already completed. Put it after the application has selected a tool and its arguments, but before invoking that tool. Hash the action you are about to execute—not an unrelated status message. Only invoke the tool after approval. If an exception escapes the example, do not catch it higher up and execute the tool anyway. A check before a tool does not protect the earlier model call used to choose that tool. If you also need to guard repeated model requests, add a check at that boundary. There is no automatic protection for work outside the paths you guard. In ordinary mode, the application submits a payload and the server calculates its hash. In hash-only mode, the SDK calculates the SHA-256 digest locally and sends that digest instead. The action payload is omitted from the outgoing request. Session IDs, sender and recipient names, intent, and the digest still leave your application. Keep sensitive information out of those identifiers. The SDK rejects metadata in hash-only mode rather than transmitting it alongside the hash. Hash-only means less raw data transmitted. It does not mean anonymous, encrypted, or zero-data processing. Two identical canonical payloads produce the same digest. A sequence such as A → B → A → B also produces a repeating digest sequence. The detector can compare those values without reading the original action. This is deterministic comparison, not semantic understanding. Two differently worded requests can mean the same thing without producing the same digest. A repeated action can also be intentional; a detector decision is evidence to investigate, not proof of a software defect. The SDK uses sorted JSON keys, compact separators, unescaped Unicode, and UTF-8 encoding before SHA-256. This avoids a different hash solely because object keys were inserted in a different order. It is not a universal cross-language canonicalization standard. Timestamps, random IDs, and other changing values are not automatically removed. If every submitted payload includes a new random identifier, exact-repeat detection may miss repeated work. On the other hand, stripping meaningful arguments can make distinct actions appear identical. Decide which fields define the action before relying on its digest. The SDK rejects unsupported JSON values and non-finite numbers in hash-only mode. It never automatically falls back to raw transmission if an older backend rejects the request format. Add mode="shadow" to the check to observe supported detector warnings without rejecting actions for those detections. Inspect result.would block and result.shadow decision before deciding to enable enforcement. Shadow mode still enforces: It consumes normal approved-message quota. It is not the legacy dry run option; keep that option disabled for server-side evaluation. Shadow and enforcement histories are separate. Switching to enforcement does not replay the shadow history. Changing only between raw and hash-only representations does not reset detector history when their digests match within the same mode, key, and run. The server cannot validate the original action contents or verify that the submitted digest corresponds to the action actually executed. Hash-only checks rely on a trusted application supplying consistent hashes. An untrusted caller can change a digest, just as it can misrepresent an action. Hashes reveal equality, and predictable inputs can be guessed by hashing candidate values. Identical action payloads also hash identically even when the surrounding world has changed; intentional polling or retrying may need a different workflow policy. Do not treat SHA-256 as a substitute for access controls or as a guarantee of anonymization. Existing raw requests are not made private retroactively. Run budgets and rolling spend limits still apply, but hashing does not measure costs. Spending controls need an authorized cost-reporting integration, and delayed reports or in-flight actions can cause overshoot. They are not provider-side hard spending caps. Hash-only checks are useful when deterministic repetition signals are enough and raw payload exposure is a concern. They complement framework termination rules, action validation, and spending controls; they do not replace them. Start with one repeated action before changing production. Use a test key, inspect the third-check result, and verify your code stops.