Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:0xSteph Pentest ai LoopConfig

From Leeroopedia
Knowledge Sources
Domains Security_Testing, LLM_Agents
Last Updated 2026-10-23 12:00 GMT

Overview

Concrete dataclass holding termination and safety knobs for the autonomous agent loop, controlling iteration limits, coverage thresholds, cost enforcement, and deterministic fallback behavior.

Description

LoopConfig is the configuration dataclass for `run_agent_loop`. It controls when the loop stops and how it handles edge cases:

  • max_iterations: Hard cap on loop iterations (default: 50)
  • coverage_threshold: Stop when tried_pairs / (endpoints × bug_classes) exceeds this (default: 0.8)
  • min_iterations_before_finish: Don't let the LLM give up too early (default: 5, env: PTAI_MIN_ITERATIONS_BEFORE_FINISH)
  • bad_response_threshold: Consecutive non-VALID LLM responses before deterministic fallback (default: 3, env: PTAI_AGENT_FALLBACK_THRESHOLD)
  • cost_tracker: Optional CostTracker; loop checks over_budget() after each LLM call
  • fallback_to_deterministic: On LLM unavailable, run all probe.* handlers instead of stopping (default: True)
  • scope: Optional ScopeEnforcer exposed to handlers via contextvar

Usage

Import this when you need to:

  • Configure the autonomous agent loop's termination and safety parameters
  • Enforce a cost budget on the engagement
  • Control the deterministic fallback behavior

Code Reference

Source Location

Signature

@dataclass
class LoopConfig:
    max_iterations: int = 50
    coverage_threshold: float = 0.8
    min_iterations_before_finish: int = field(
        default_factory=lambda: _env_int("PTAI_MIN_ITERATIONS_BEFORE_FINISH", 5)
    )
    bad_response_threshold: int = field(
        default_factory=lambda: _env_int("PTAI_AGENT_FALLBACK_THRESHOLD", 3)
    )
    cost_tracker: CostTrackerLike | None = None
    fallback_to_deterministic: bool = True
    scope: Any | None = None

Import

from engine.agent_loop import LoopConfig

I/O Contract

Inputs (constructor)

Name Type Required Description
max_iterations int No Hard iteration cap (default: 50)
coverage_threshold float No Coverage ratio to stop at (default: 0.8)
min_iterations_before_finish int No Iteration floor before finish accepted (default: 5)
bad_response_threshold int No Bad LLM response count before fallback (default: 3)
cost_tracker None No Budget enforcement
fallback_to_deterministic bool No Run probe.* handlers on LLM failure (default: True)
scope None No ScopeEnforcer for contextvar exposure

Usage Examples

Configuring the Loop

from engine.agent_loop import LoopConfig
from engine.scope import build_enforcer
from engine.llm.cost import make_tracker_from_env

config = LoopConfig(
    max_iterations=100,
    coverage_threshold=0.9,
    min_iterations_before_finish=10,
    bad_response_threshold=5,
    cost_tracker=make_tracker_from_env(),
    fallback_to_deterministic=True,
    scope=build_enforcer("https://app.example.com"),
)

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment