Implementation:0xSteph Pentest ai AgentOrchestrator start engagement
| Knowledge Sources | |
|---|---|
| Domains | Security_Testing, Orchestration |
| Last Updated | 2026-10-23 12:00 GMT |
Overview
Concrete multi-phase engagement coordinator that runs a penetration test as ordered phases (recon → web → AD → cloud → mobile → chaining → validation → detection → report), each driven by a specialist agent.
Description
The AgentOrchestrator class coordinates the full engagement lifecycle. It builds a phase list from the engagement scope, then runs each phase in sequence. Each phase delegates to a specialist agent (ReconAgent, WebAgent, ADAgent, etc.) that inherits from BaseAgent.
Key behaviors:
- Phase building: `_build_phase_list()` selects phases based on scope (full, web, ad, cloud, mobile)
- Context propagation: Recon findings (open_ports, services) flow to web assessment via `agent.set_context()`
- Error isolation: Phase failures are logged but do not abort the engagement (except CancelledError and CostLimitError)
- Progress reporting: Callback fires at each phase start/complete with percentage
- Event emission: PhaseStarted, PhaseCompleted, CandidateFound, EngagementCompleted events
- Checkpoint/resume: `resume_engagement()` skips completed phases
- Target recovery: Before verification, waits for a wobbled target to recover (60s budget)
- Prove-or-kill: After verification, unverified third-party scanner findings are suppressed
Usage
Import this when you need to:
- Run a full engagement pipeline (CLI `ptai start`, MCP `start_engagement`)
- Resume an interrupted engagement
- Orchestrate phases with progress callbacks and events
Code Reference
Source Location
- Repository: pentest-ai
- File: engine/orchestrator.py
Signature
ProgressCallback = Callable[[str, str, float], None]
class AgentOrchestrator:
def __init__(
self,
db: FindingsDB,
llm: LLMClient | None = None,
scope: ScopeEnforcer | None = None,
event_bus: EventBus | None = None,
):
async def start_engagement(
self,
engagement: dict[str, Any],
on_progress: ProgressCallback | None = None,
) -> None:
"""Run all phases in sequence. Persists status updates to DB."""
async def resume_engagement(
self,
engagement: dict[str, Any],
on_progress: ProgressCallback | None = None,
) -> None:
"""Resume from last completed phase checkpoint."""
def set_auth(self, creds: AuthCredentials) -> None:
async def set_intensity(self, engagement_id: str, intensity: str) -> None:
@property
def phase_errors(self) -> dict[str, str]:
@property
def is_running(self) -> bool:
@property
def current_phase(self) -> str | None:
Import
from engine.orchestrator import AgentOrchestrator
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| engagement | dict[str, Any] | Yes | Engagement record with id, target, scope, intensity, rules_of_engagement |
| on_progress | ProgressCallback | No | Callback: (phase_name, message, percent) |
| db | FindingsDB | Yes | SQLite findings database (constructor) |
| llm | LLMClient | No | LLM client for agent reasoning |
| scope | ScopeEnforcer | No | Scope enforcement engine |
| event_bus | EventBus | No | Event bus for typed events |
Outputs
| Name | Type | Description |
|---|---|---|
| returns | None | Async. Persists status to DB, emits events |
| side effect | DB status | running → completed/failed/interrupted |
| side effect | Events | PhaseStarted, PhaseCompleted, EngagementCompleted |
Usage Examples
Running a Full Engagement
from engine.orchestrator import AgentOrchestrator
from engine.findings_db import FindingsDB
from engine.scope import build_enforcer
db = FindingsDB("findings.db")
scope = build_enforcer("https://app.example.com", mode="strict")
orchestrator = AgentOrchestrator(db, llm=my_llm, scope=scope, event_bus=bus)
engagement = await db.create_engagement(
target="https://app.example.com",
scope="full",
intensity="normal",
)
await orchestrator.start_engagement(engagement)