📘 Context
LLM agents can enter recursive tool-call loops (agent calls tool A, tool A
returns a result, agent calls tool A again with slightly different args,
forever). They can also burn API budget by issuing high-frequency calls.
This policy acts as a deterministic safety gate against runaway behavior at
the agent runtime layer, regardless of what the model decides to do.
🎯 The Goal
Write a tool-call recursion and rate-limit policy for any LLM agent runtime.
Variables you can use:
tool_name (String): Name of the tool being called.
tool_call_count_session (Integer): Total tool calls in the current agent session.
tool_call_count_last_minute (Integer): Tool calls in the last 60 seconds.
same_tool_consecutive_calls (Integer): Consecutive calls to the SAME tool.
same_args_repeat_count (Integer): Times this exact (tool, args) tuple has been called this session.
tool_cost_usd (Float): Cost-per-call estimate.
session_cost_so_far_usd (Float): Cumulative session cost.
session_budget_usd (Float): Configured session budget.
recursion_depth (Integer): Current call stack depth (agent → tool → agent → tool ...).
Requirements:
- BLOCK if
same_tool_consecutive_calls > 10 (recursion guard).
- BLOCK if
same_args_repeat_count > 3 (idempotency loop guard).
- BLOCK if
tool_call_count_last_minute > 30 (rate limit).
- BLOCK if
session_cost_so_far_usd + tool_cost_usd > session_budget_usd.
- BLOCK if
recursion_depth > 8.
- ESCALATE if
tool_call_count_session > 200.
- ESCALATE if
session_cost_so_far_usd > session_budget_usd * 0.8.
📚 Resources
- Start here:
docs/getting-started.md
- Check syntax:
quickstart/01_hello_world.csl
- See how examples are structured:
examples/community/
✅ Definition of Done
Submit a PR with: examples/community/ai_safety_tool_recursion_limit.csl
📘 Context
LLM agents can enter recursive tool-call loops (agent calls tool A, tool A
returns a result, agent calls tool A again with slightly different args,
forever). They can also burn API budget by issuing high-frequency calls.
This policy acts as a deterministic safety gate against runaway behavior at
the agent runtime layer, regardless of what the model decides to do.
🎯 The Goal
Write a tool-call recursion and rate-limit policy for any LLM agent runtime.
Variables you can use:
tool_name(String): Name of the tool being called.tool_call_count_session(Integer): Total tool calls in the current agent session.tool_call_count_last_minute(Integer): Tool calls in the last 60 seconds.same_tool_consecutive_calls(Integer): Consecutive calls to the SAME tool.same_args_repeat_count(Integer): Times this exact (tool, args) tuple has been called this session.tool_cost_usd(Float): Cost-per-call estimate.session_cost_so_far_usd(Float): Cumulative session cost.session_budget_usd(Float): Configured session budget.recursion_depth(Integer): Current call stack depth (agent → tool → agent → tool ...).Requirements:
same_tool_consecutive_calls > 10(recursion guard).same_args_repeat_count > 3(idempotency loop guard).tool_call_count_last_minute > 30(rate limit).session_cost_so_far_usd + tool_cost_usd > session_budget_usd.recursion_depth > 8.tool_call_count_session > 200.session_cost_so_far_usd > session_budget_usd * 0.8.📚 Resources
docs/getting-started.mdquickstart/01_hello_world.cslexamples/community/✅ Definition of Done
Submit a PR with:
examples/community/ai_safety_tool_recursion_limit.csl