Principle:0xSteph Pentest ai Autonomous Agent Loop
| Knowledge Sources | |
|---|---|
| Domains | Security_Testing, LLM_Agents, Autonomous_Systems |
| Last Updated | 2026-10-23 12:00 GMT |
Overview
An LLM-driven reasoning loop that replaces fixed-pipeline orchestration by iteratively observing engagement state, proposing the next highest-value action, dispatching it to a handler, and recording the result until termination.
Description
Autonomous Agent Loop is the principle that an LLM can drive a penetration test by reasoning over engagement state and choosing each action dynamically, rather than following a fixed phase sequence. It solves the limitation that fixed pipelines cannot adapt to target-specific findings — the LLM sees what has been tried and what was found, then picks the most valuable next step.
The loop follows a five-step cycle:
- Observe: WorkingMemory.summary_for_llm() produces a compact state snapshot (findings by severity, endpoints seen, untried bug-class/endpoint pairs, captured auth, last action result)
- Propose: The LLM agent receives the state and returns an Action(name, args, rationale)
- Dispatch: The action name maps to a registered handler function in a global registry
- Record: The handler returns an Observation (success, findings_added, endpoints_added, auth_added) that updates WorkingMemory
- Check: Termination conditions (LLM proposed finish, coverage threshold, max iterations, cost limit)
Safety nets ensure the loop does not silently produce zero findings:
- Early-finish detection: If the LLM proposes finish below an iteration floor with 0 findings, the deterministic fallback runs
- Non-cooperative detection: N consecutive unparseable/unknown-handler responses trip the fallback
- Unproductive detection: Clean exit (max_iter/coverage) with 0 findings trips the fallback
- Cost limit: CostTracker.over_budget() stops spending immediately
Usage
Use this principle when:
- The target is unknown and the LLM should adapt its strategy based on findings
- Fixed pipelines are too rigid for the engagement type
- You need coverage-based termination (stop when most bug-class/endpoint pairs are tried)
- An LLM is available and you want to leverage its reasoning for action selection
Theoretical Basis
The loop is a Markov decision process where the LLM is the policy:
Failed to parse (syntax error): {\displaystyle \pi(s) = \text{LLM}(\text{summary\_for\_llm}(s)) \to \text{Action} }
Coverage is a matrix of (endpoint, bug-class) pairs:
Failed to parse (syntax error): {\displaystyle \text{coverage} = \frac{|\text{tried\_pairs}|}{|\text{endpoints\_seen}| \times |\text{BUG\_CLASSES}|} }
Termination is a disjunction:
# Abstract loop (NOT real implementation)
while not should_stop(memory, config):
state = memory.summary_for_llm()
action = await agent.decide_next_action(state)
if is_finish_action(action):
break
handler = _HANDLERS[action.name]
observation = await handler(memory, action.args)
memory.record(observation)
Related Pages
Implemented By
- Implementation:0xSteph_Pentest_ai_run_agent_loop
- Implementation:0xSteph_Pentest_ai_WorkingMemory_summary_for_llm
- Implementation:0xSteph_Pentest_ai_register_handler
- Implementation:0xSteph_Pentest_ai_LoopConfig