cleandataengineering.aiAgent Harness, drawn simply
You are here: End to end › Checks › 4 · Before the tool › tool-call budget

Agent Harness Tutorial · End to end · Zoom level 3

How we take care of it: tool-call budget

tool-call budget catches more than 8 a trip, 24 a turn.

Open: 11before loopopen ›Open: 22before modelopen ›Open: 33after modelopen ›Open: 44before toolopen ›Open: 55the toolopen ›Open: 66after toolopen ›Open: 77after loopopen ›Open: 88before replyopen ›It readshow many tool calls this trip andthis turn, and their signaturestool-call budgetrule · harnesspassCarries onfailIf it failsstop the turnWHERE IN THE CODE: plan.over_fan_out() · H loop/plan.py
The strip at the top shows every check point where this check runs, in dark.

How we took care of it.

  1. At most 8 calls a trip and 24 a turn.
  2. A signature (tool name + sorted arguments) seen a third time means going round in circles.
It readshow many tool calls this trip and this turn, and their signatures
Kindrule
Provided byharness
If it failsstop the turn
Where in the codeplan.over_fan_out() · H loop/plan.py
Runs at4 · Before the tool
Real exampleEnds are named tool_call_budget_exhausted and oscillation_detected.

More on this: When it stops.

How it is done: the real code

Cut from the live repositories each time the site is built, so it always matches what runs.

def signature(name: str, arguments: dict[str, object]) -> tuple[str, str]:
    """A call's identity for oscillation purposes: the tool and its arguments."""
    return name, json.dumps(arguments, sort_keys=True, default=str)
def over_fan_out(asked: int, so_far: int, budgets: Budgets) -> str | None:
    """`per_step` or `per_turn`: the bound a plan of `asked` calls would pass, after
    `so_far` calls already planned this turn; `None` when it passes neither."""
    if asked > budgets.max_tool_calls_per_step:
        return "per_step"
    if so_far + asked > budgets.max_tool_calls_per_turn:
        return "per_turn"
    return None