# How is the agent loop and planning implemented?

> Open-source AI pentest and offensive-security agents — a good answer covers: Single agent vs multi-agent or role-based crews; how tasks are planned, decomposed and tracked; turn structure; stop conditions and iteration caps.

Canonical page: https://llms-technical-reviews.com/offensive-security-agents/q/agent-loop/

## Verdict

Shannon and PentestGPT keep the most control in code: Shannon's workflow fixes every phase, and PentestGPT validates each task the model proposes. For open-ended autonomous runs, Strix and Decepticon have the most complete multi-agent runtimes.

**Code-owned pipelines.** [Shannon](/p/shannon/) runs a Temporal workflow: recon, five vulnerability-class lanes, exploitation and report, with up to 50 retries per activity and resume from `session.json`. [RAPTOR](/p/raptor/)'s `/agentic` is a fixed phase pipeline that fans findings out to parallel LLM tasks or read-only `claude -p` children. A separate engagement supervisor stops after 8 passes. [Nebula](/p/nebula/) missions are LangGraph graphs, but the plan comes deterministically from operator-selected tools or stages, and run budgets default to unbounded. [Pentest Swarm AI](/p/pentest-swarm-ai/) has no planner: four agents react to blackboard findings whose "pheromone" weight decays, and a campaign ends after 20 minutes, 60 s idle or the cost cap.

**Model proposes, code checks.** [PentestGPT](/p/pentestgpt/)'s Supervisor may add one task per decision, and `compile_plan` rejects out-of-scope targets, cycles and an `EXPLOIT` without a completed `TEST`. The default cap is 20 decisions. [PentestAgent](/p/pentestagent/) forces a plan on iteration 1, tracks steps through `finish`, replans on failure and stops at 30 iterations. [CyberStrike](/p/cyberstrike/) inherits opencode's loop and injects a 13-phase methodology state. Only the proxy-pipeline sub-agents have step caps; the primary agent's limit is `Infinity` and its stuck detector ships disabled.

**Model-planned hierarchies.** [Strix](/p/strix/)'s root agent spawns children with `create_agent`. Planning is prompt skills, bounded by 500 turns and a shared dollar budget that stops sub-agents at 90%. [PentAGI](/p/pentagi/) has a generator agent write up to 15 subtasks and a refiner rewrite them after each one, with chains capped at 100 or 20 iterations. [Decepticon](/p/decepticon/)'s orchestrator holds no offensive tools; it keeps an objective DAG (OPPLAN) and delegates to about 18 specialists, with wrap-up messages at 80% of the step budget. [RedAmon](/p/redamon/) is one 14-node LangGraph ReAct graph (100 iterations) with optional parallel fireteams and tree search, which is off by default.

**Not applicable.** [HexStrike AI](/p/hexstrike-ai/) has no loop. Its "agents" are static Python tables, and the attached MCP client does the planning.

Pick: Shannon or PentestGPT when runs must be reproducible and auditable.
Pick: Strix or Decepticon for long unattended runs with delegation and budgets.
Pick: Pentest Swarm AI for an event-driven pipeline where code chooses the tools.

## Per-project answers

### usestrix/strix (answered)

Strix uses a **single root agent with multiple addressable child agents** arranged in a tree, not a flat crew. The root agent is a SandboxAgent (OpenAI Agents SDK) built in `agents/factory.py:build_strix_agent()` (lines 722–828), and it can spawn independent children via the `create_agent` tool (`tools/agents_graph/tools.py:494–606`).

**Planning and decomposition** are handled by the LLM itself through system-prompt skills. The root agent's prompt (rendered by `agents/prompt.py:render_system_prompt()`, lines 78–158) loads a chain of Jinja2 skill templates — scan modes (e.g. `scan_modes/deep`), analysis skills (`analysis/counterevidence`, `analysis/severity_calibration`), and root coordination skills (`coordination/root_agent`). The root agent decides when to spawn a specialist child by calling `create_agent`, passing a task string and optional skill list (e.g. `["xss", "sql_injection"]`). Each child calls `agent_finish` when done, posting a structured completion report back to the parent (`tools/agents_graph/tools.py:609–751`).

**Turn structure** — The inner loop runs in `core/execution.py:_run_cycle()` (lines 761–935). Each cycle: (1) marks the agent running, (2) enforces image budget and runs proactive context compaction, (3) calls `Runner.run_streamed()` for one model response, streaming events back, (4) handles lifecycle tool results (completion → stop, wait tools → park, plain text → recovery nudge). The `_finish_tool_use_behavior` callback in `agents/factory.py:600–618` determines whether a tool result is terminal. The outer loop (`_run_agent_loop`, lines 271–387) repeats cycles: in interactive mode it parks on `wait_for_user`/`wait_for_agents` with a 300s auto-resume timeout, waking on new messages; in non-interactive mode it returns immediately.

**Stop conditions** — `DEFAULT_MAX_TURNS = 500` (`config/settings.py:14`), a dollar-based `max_budget_usd` with three warn bands (70%/85%/95% via `hooks.py:57–58`), and a 90% subagent reserve (`hooks.py:60`). Recovery limit: interactive agents get 3 chances to produce a tool call after ending a turn with plain text (`execution.py:536`); non-interactive agents get the full max_turns.


Citations: [strix/core/runner.py:215-260](https://github.com/usestrix/strix/blob/6b7ae2ebe4d47037a927aade23265ff4e4f27e84/strix/core/runner.py#L215-L260) · [strix/core/execution.py:539-658](https://github.com/usestrix/strix/blob/6b7ae2ebe4d47037a927aade23265ff4e4f27e84/strix/core/execution.py#L539-L658) · [strix/agents/factory.py:722-828](https://github.com/usestrix/strix/blob/6b7ae2ebe4d47037a927aade23265ff4e4f27e84/strix/agents/factory.py#L722-L828) · [strix/core/agents.py:56-82](https://github.com/usestrix/strix/blob/6b7ae2ebe4d47037a927aade23265ff4e4f27e84/strix/core/agents.py#L56-L82) · [strix/tools/agents_graph/tools.py:494-606](https://github.com/usestrix/strix/blob/6b7ae2ebe4d47037a927aade23265ff4e4f27e84/strix/tools/agents_graph/tools.py#L494-L606) · [strix/core/hooks.py:165-450](https://github.com/usestrix/strix/blob/6b7ae2ebe4d47037a927aade23265ff4e4f27e84/strix/core/hooks.py#L165-L450)

### KeygraphHQ/shannon (answered)

Shannon uses a **multi-agent, single-model, phase-based** pipeline orchestrated by **Temporal workflows** (`apps/worker/src/temporal/workflows.ts`), not a dynamic model-driven loop. The `pentestPipeline` function runs five sequential phases: pre-recon, recon, vulnerability analysis (5 parallel agents: injection, xss, auth, authz, ssrf), exploitation (5 parallel agents + 1 miscellaneous), and reporting. Agents are defined declaratively in `apps/worker/src/session-manager.ts` with prompt templates, deliverables, and prerequisites — the workflow's explicit code structure enforces ordering and concurrency, not a model-authored plan. Each agent runs a single-turn-or-until-complete session via the **pi-coding-agent** harness (`apps/worker/src/ai/pi/pi-executor.ts:runPiPrompt`), which uses built-in tools (read, bash, edit, write, grep, find, ls) plus per-phase custom collectors. There is no iterative planning loop: the workflow calls activities (wrappers around `AgentExecutionService.execute()`) which handle the full lifecycle — load config, load prompt, git checkpoint, pi session, output validation, render deliverable, git commit (`apps/worker/src/services/agent-execution.ts:151-401`). Retry is owned by Temporal's activity retry policy: up to 50 attempts with exponential backoff (5 min initial, 30 min max) in production, with specific non-retryable error types (`apps/worker/src/temporal/workflows.ts:92-106`). Cancellation is handled via Temporal's cancellation scope with `WAIT_CANCELLATION_COMPLETED` for report operations, `TRY_CANCEL` for agents. Stop conditions: completed (all agents successful), partial (some degradation), failed (hard error), or cancelled (user-initiated). Capella (agentic SAST) runs as a Temporal child workflow overlapping the pentest, and its result is joined per-class before reconciliation. The miscellaneous exploitation lane runs concurrently with the five fixed classes. Resume is supported: detected via `session.json`, restoring git checkpoints and only running incomplete agents (`apps/worker/src/temporal/workflows.ts:1296-1342`).


Citations: [apps/worker/src/temporal/workflows.ts:361-381](https://github.com/KeygraphHQ/shannon/blob/b9744f6cecc5429333873b86a6762f1d70c54fc2/apps/worker/src/temporal/workflows.ts#L361-L381) · [apps/worker/src/session-manager.ts:21-123](https://github.com/KeygraphHQ/shannon/blob/b9744f6cecc5429333873b86a6762f1d70c54fc2/apps/worker/src/session-manager.ts#L21-L123) · [apps/worker/src/services/agent-execution.ts:151-276](https://github.com/KeygraphHQ/shannon/blob/b9744f6cecc5429333873b86a6762f1d70c54fc2/apps/worker/src/services/agent-execution.ts#L151-L276) · [apps/worker/src/ai/pi/pi-executor.ts:233-476](https://github.com/KeygraphHQ/shannon/blob/b9744f6cecc5429333873b86a6762f1d70c54fc2/apps/worker/src/ai/pi/pi-executor.ts#L233-L476) · [apps/worker/src/temporal/workflows.ts:1296-1342](https://github.com/KeygraphHQ/shannon/blob/b9744f6cecc5429333873b86a6762f1d70c54fc2/apps/worker/src/temporal/workflows.ts#L1296-L1342)

### vxcontrol/pentagi (answered)

The agent loop is structured as a three-tier hierarchy — flow → task → subtask — running inside a single backend process with Go-style concurrency (goroutines/channels).

**Multi-agent, not single-agent.** This is a role-based crew, not a single agent. The `MsgchainType` enum defines 15 agent roles (`pkg/database/models.go:197-212`): `primary_agent` orchestrates everything, `generator`/`refiner` plan subtasks, and specialist agents (`pentester`, `coder`, `searcher`, `installer`, `memorist`, `adviser`, `enricher`, `reporter`, `summarizer`, `tool_call_fixer`, `reflector`) each handle one dimension. An assistant (interactive chat) also exists as a separate role.

**Task planning and decomposition.** When user input arrives, `taskWorker.Run()` (`pkg/controller/task.go:341-376`) pops subtasks from a queue generated by the `generator` agent (via `stc.GenerateSubtasks`). After each subtask completes, the `refiner` agent is called (`stc.RefineSubtasks`, `pkg/controller/task.go:366`) to re-plan remaining subtasks. This generator/refiner pair is the planning loop — it creates an initial plan then revises it based on what actually happened.

**Turn structure.** Each subtask runs as an agent chain through `performAgentChain()` (`pkg/providers/performer.go:58-279`). The chain loops: call the LLM → execute tool calls → append results → summarize chain → repeat. The loop has iteration caps (`maxGeneralAgentChainIterations=100`, `maxLimitedAgentChainIterations=20`, `pkg/providers/performer.go:37-39`) and a `repeatingDetector` that aborts on consecutive identical tool calls. Barrier tools (`done`, `ask`) stop the loop early. A `reflector` agent steps in when the model returns text instead of a tool call.

**Stop conditions.** Subtasks complete on `done`/`ask` barrier calls or when the LLM returns no tool calls (triggering the reflector). Tasks complete when the subtask queue is empty or user input is awaited. The flow finishes by setting `FlowStatusFinished` after all tasks are done and a report is written.


Citations: [backend/pkg/database/models.go:194-212](https://github.com/vxcontrol/pentagi/blob/cffed9485aa1cca70762cd08a57ac62a80406258/backend/pkg/database/models.go#L194-L212) · [backend/pkg/controller/task.go:341-376](https://github.com/vxcontrol/pentagi/blob/cffed9485aa1cca70762cd08a57ac62a80406258/backend/pkg/controller/task.go#L341-L376) · [backend/pkg/providers/performer.go:58-279](https://github.com/vxcontrol/pentagi/blob/cffed9485aa1cca70762cd08a57ac62a80406258/backend/pkg/providers/performer.go#L58-L279) · [backend/pkg/controller/flow.go:1288-1351](https://github.com/vxcontrol/pentagi/blob/cffed9485aa1cca70762cd08a57ac62a80406258/backend/pkg/controller/flow.go#L1288-L1351)

### GreyDGL/PentestGPT (answered)

The autonomous loop uses **two deterministic LLM roles** — Supervisor and Executor — with no speculative backlog, always-on judge, or parallel scheduler. The Supervisor receives a bounded projection of the run state (open tasks, four recent closed tasks, required dependency context, selected observations, aggregate history, and recent diagnostics) and proposes at most **one new task** or selects one existing ready task, or signals finish. Its typed decision goes through `compile_plan()` (`plan.py:157`) which validates target scope, task kind rules (e.g. EXPLOIT requires a completed TEST on the same target), dependency cycles, basis-ID existence, and finish preconditions — all in pure deterministic code with no model involvement. Once validated, `MemoryKernel.commit_plan()` (`memory.py:431`) atomically inserts the new task, transitions the selected task to ACTIVE, creates an Attempt record, and advances the revision counter. The Executor then receives exactly one leased task with explicit kind, turn budget, basis observations, and optional retry diagnostic. Its output goes through `compile_execution()` (`execution.py:271`) which verifies that the evidence_excerpt is an exact contiguous substring of one eligible command/tool output receipt, CRLF-normalized only. No model reviews the model's own output. The loop in `PentestLoop.run()` (`loop.py:44`) runs decision cycles until the run completes, a `max_decisions` cap (default 20) is reached, or a non-recoverable error occurs. Each episode is a fresh provider session (`resume = null`); provider conversation history is not memory. The legacy client (`pentestgpt_legacy/`) is a human-driven interactive session using three model roles (reasoning, generation, parsing) with no autonomous loop.


Citations: [pentestgpt_agent/src/pentestgpt_agent/loop.py:26-81](https://github.com/GreyDGL/PentestGPT/blob/e8b1bb77d1ac00329675cec3b060aba971ec1ac8/pentestgpt_agent/src/pentestgpt_agent/loop.py#L26-L81) · [pentestgpt_agent/src/pentestgpt_agent/agents.py:99-216](https://github.com/GreyDGL/PentestGPT/blob/e8b1bb77d1ac00329675cec3b060aba971ec1ac8/pentestgpt_agent/src/pentestgpt_agent/agents.py#L99-L216) · [pentestgpt_agent/src/pentestgpt_agent/plan.py:157-332](https://github.com/GreyDGL/PentestGPT/blob/e8b1bb77d1ac00329675cec3b060aba971ec1ac8/pentestgpt_agent/src/pentestgpt_agent/plan.py#L157-L332)

### 0x4m4/hexstrike-ai (answered)

**There is no AI agent loop in this codebase.** The "12+ autonomous AI agents" listed in the README (IntelligentDecisionEngine, BugBountyWorkflowManager, CTFWorkflowManager, CVEIntelligenceManager, AIExploitGenerator, VulnerabilityCorrelator, etc.) are all deterministic Python classes with no LLM inference loop. The `IntelligentDecisionEngine` (line 572) uses hardcoded tool-effectiveness ratings per target type and predefined attack patterns (e.g., `web_reconnaissance` has 8 steps from nmap to gobuster) — it selects tools by matching target type to a static dict, not via any planning or decomposition. `BugBountyWorkflowManager` (line 2447) builds phase-based workflows (subdomain discovery → HTTP probing → content discovery → parameter discovery → vulnerability hunting) as static Python dicts with estimated times and tool lists. `CTFChallengeAutomator.auto_solve_challenge()` (line 3864) executes steps sequentially or in parallel, checking if the output contains a flag candidate and breaking early — but execution is simulated (`# In a real implementation, this would execute the command` at line 3939). There is no multi-agent crew, no role-based turn structure, no iteration caps, and no task-decomposition loop. The project is purely an MCP tool server: an external AI client (Claude, GPT, Copilot) connects and drives the interaction loop; HexStrike just provides the tool endpoints.


Citations: [hexstrike_server.py:572-770](https://github.com/0x4m4/hexstrike-ai/blob/d689933ff579d839c676c82b231f8e98326c5f04/hexstrike_server.py#L572-L770) · [hexstrike_server.py:2447-2575](https://github.com/0x4m4/hexstrike-ai/blob/d689933ff579d839c676c82b231f8e98326c5f04/hexstrike_server.py#L2447-L2575) · [hexstrike_server.py:3855-3947](https://github.com/0x4m4/hexstrike-ai/blob/d689933ff579d839c676c82b231f8e98326c5f04/hexstrike_server.py#L3855-L3947) · [hexstrike_server.py:2795-2975](https://github.com/0x4m4/hexstrike-ai/blob/d689933ff579d839c676c82b231f8e98326c5f04/hexstrike_server.py#L2795-L2975) · [hexstrike_mcp.py:267-310](https://github.com/0x4m4/hexstrike-ai/blob/d689933ff579d839c676c82b231f8e98326c5f04/hexstrike_mcp.py#L267-L310)

### BitterSecurity/Decepticon (answered)

**Single orchestrator, multi-agent role delegation.** The system uses a single orchestrator (the `decepticon` agent) that plans and delegates to ~20 specialist sub-agents rather than a multi-agent crew working jointly. The orchestrator is built by `create_decepticon_agent()` in `agents/standard/decepticon.py` (lines 80–216), which compiles a LangGraph agent with a middleware stack including `EngagementContextMiddleware`, `SkillsMiddleware`, `SubAgentMiddleware`, `OPPLANMiddleware`, and `StepBudgetMiddleware`. The orchestrator carries **no offensive tools** — `tools=[]` — all work is delegated via the `task()` tool (`SubAgentMiddleware`) to specialist sub-agents like recon, exploit, ad_operator, cloud_hunter, and finding_verifier.

**Planning and decomposition.** Planning happens ahead of execution via Soundwave (interview-based planner generating 7 engagement documents plus RoE) or Autohunt (additive bootstrap planner). The orchestrator then projects an **OPPLAN** (Operations Plan) — a DAG of tactical objectives persisted at `/workspace/plan/opplan.json`. Each objective has phases, status, blocked_by dependencies, and owner. The OPPLAN is managed through tools like `commit_opplan`, `update_objective`, `list_objectives`, and `load_opplan` registered via `OPPLANMiddleware` (`middleware/opplan.py`, lines 1–58). Workflows (`workflows/catalog/`) define multi-stage templates (scope→discover→prove→verify→report) with `WorkflowStage` models specifying required artifacts and their specialist assignments. The `WorkflowMiddleware` dispatches stages when preconditions (completed stages, required artifacts) are met.

**Turn structure and stop conditions.** Each sub-agent runs its own LangGraph ReAct loop with a configurable `recursion_limit` (default 400 for orchestrator, 1000 for recon/exploit). The `StepBudgetMiddleware` (`middleware/step_budget.py`, lines 24–65) injects wrap-up system messages at 80% of the budget and a hard-stop directive at 100%, giving the model a chance to consolidate before the runtime hard cap raises `GraphRecursionError`. Sub-agents can also be paused by `HITLApprovalMiddleware` for high-impact actions requiring operator sign-off, or halted by `BudgetEnforcementMiddleware` when USD spend caps are reached.


Citations: [packages/decepticon/decepticon/agents/standard/decepticon.py:80-216](https://github.com/BitterSecurity/Decepticon/blob/cd252a5467b91ccfdb46fde9562c75d671d33604/packages/decepticon/decepticon/agents/standard/decepticon.py#L80-L216) · [packages/decepticon/decepticon/middleware/opplan.py:1-58](https://github.com/BitterSecurity/Decepticon/blob/cd252a5467b91ccfdb46fde9562c75d671d33604/packages/decepticon/decepticon/middleware/opplan.py#L1-L58) · [packages/decepticon/decepticon/middleware/step_budget.py:24-65](https://github.com/BitterSecurity/Decepticon/blob/cd252a5467b91ccfdb46fde9562c75d671d33604/packages/decepticon/decepticon/middleware/step_budget.py#L24-L65) · [packages/decepticon/decepticon/workflows/catalog/red-team/WORKFLOW.md:1-59](https://github.com/BitterSecurity/Decepticon/blob/cd252a5467b91ccfdb46fde9562c75d671d33604/packages/decepticon/decepticon/workflows/catalog/red-team/WORKFLOW.md#L1-L59) · [packages/decepticon/decepticon/agents/middleware_slots.py:124-186](https://github.com/BitterSecurity/Decepticon/blob/cd252a5467b91ccfdb46fde9562c75d671d33604/packages/decepticon/decepticon/agents/middleware_slots.py#L124-L186) · [packages/decepticon/decepticon/agents/build.py:352-491](https://github.com/BitterSecurity/Decepticon/blob/cd252a5467b91ccfdb46fde9562c75d671d33604/packages/decepticon/decepticon/agents/build.py#L352-L491)

### gadievron/raptor (answered)

RAPTOR does not use multi-agent or role-based crews. It is a **single-agent system orchestrated by a mechanical supervisor loop** (`core/engagement/supervise.py`). The workflow is artifact-centric: an engagement ledger (`core/engagement/ledger.py`) inventories all files in a target directory into artifact rows with content hashes, DT_NEEDED links, and exposure features. The **depth governor** (`core/engagement/governor.py`) mechanically assigns each artifact a tier (T0–T3) based purely on deterministic exposure signals — no LLM ever assigns depth (M3a doctrine). The **supervisor** (`supervise()`) runs scheduling passes: each pass iterates the governor's priority-ordered artifact list (deepest tier first), and for each artifact calls `chain_elf.run_chain()` which invokes the per-class analysis chain: investigate → import → study → checklist → audit → siblings → seed re-review → validate. Tasks are not dynamically planned by an LLM; they are statically sequenced by the chain module, which is resumable — per-artifact state is durable in `chain-state.json`, so an interrupted run continues from the first unsettled stage. Stop conditions include the `_MAX_PASSES` cap (8 passes), the `PARK_AFTER_DEATHS` bound (3 consecutive unreconciled segment deaths park the artifact), operator envelope exhaustion (reservations over budget park the engagement), and wall-clock bounds from `core.run.supervisor.supervisor_wall_bound`. The supervisor also respects fleet drain requests and operator acknowledgment parks (M5: parks are sticky until acknowledged).

> **Editor's note.** Correction: the engagement supervisor is a separate mode for long binary engagements; the main /agentic flow is a fixed phase pipeline (scan, validate, prep, then per-finding LLM tasks dispatched in parallel to external models or to read-only `claude -p` children), and /crash-analysis and /oss-forensics use Claude Code sub-agents defined in .claude/agents/.

Citations: [core/engagement/supervise.py:786-1218](https://github.com/gadievron/raptor/blob/265236fc9f328be7df46cee36969fd447463c3c6/core/engagement/supervise.py#L786-L1218) · [core/engagement/governor.py:370-503](https://github.com/gadievron/raptor/blob/265236fc9f328be7df46cee36969fd447463c3c6/core/engagement/governor.py#L370-L503) · [core/engagement/chain_elf.py:1-50](https://github.com/gadievron/raptor/blob/265236fc9f328be7df46cee36969fd447463c3c6/core/engagement/chain_elf.py#L1-L50) · [core/engagement/ledger.py:1-132](https://github.com/gadievron/raptor/blob/265236fc9f328be7df46cee36969fd447463c3c6/core/engagement/ledger.py#L1-L132)

### CyberStrikeus/CyberStrike (answered)

**Single agent with multi-agent crew dispatch.** CyberStrike uses a primary agent (cyberstrike, general, or user-chosen) that dispatches work to 13+ specialized subagents via the `task()` tool. The architecture is not a fixed crew — subagents are spawned dynamically per task/request through a `SessionPrompt.loop()` function that runs the LLM turn loop.

**Planning & decomposition.** The methodology engine defines 13 sequential phases (scope_analysis → passive_recon → active_recon → technology_profiling → authentication_testing → session_management → authorization_testing → input_validation → business_logic → data_protection → api_security → infrastructure → reporting). Each phase has prerequisites, required tags, and minDeliverables tracked in a SQLite database via `Methodology.computeState()`. Phase status (not_started/in_progress/completed/blocked) is persisted and reported to the agent as prompt context via `Methodology.formatForPrompt()`.

**Turn structure.** The loop at `session/prompt.ts:310-378` (`SessionPrompt.loop`) is a `while(true)` that: (1) streams messages from SQLite, (2) finds the last user/assistant messages, (3) increments step counter, (4) resolves the LLM provider model (with optional small-model downgrade via `useSmallModel`), (5) builds tools filtered by the current agent's permission ruleset, (6) calls the LLM, (7) processes response (tool calls or finish). The loop breaks when the assistant finishes with a non-tool-calls reason or when the abort signal fires.

**Stop conditions & iteration caps.** Hard step caps are defined in `Agent.STEP_CAPS` (orchestrator: 40, analyzer: 20, proxy-tester-*: 60). A stuck detector (`StuckDetector`, line 333) and repeat detector (`RepeatDetector`, line 343) guard against infinite loops. The loop also checks for abort signals (`abort.aborted`). Session compaction runs when token counts approach the model's context limit.

**Agent definitions** are registered in `Agent.Info` with mode (primary/subagent), permission rulesets, model overrides, step caps, and specialization prompts loaded from embedded text files like PROMPT_WEB_APPLICATION, PROMPT_CLOUD_SECURITY, etc.

> **Editor's note.** Correction: the stuck detector ships disabled and both loop detectors run only for native sub-agents; the primary agent has no step cap (maxSteps is Infinity) and stops on a tool-free turn, an abort, or the within-turn doom_loop ask.

Citations: [packages/cyberstrike/src/agent/agent.ts:1-200](https://github.com/CyberStrikeus/CyberStrike/blob/61044eddf31d1549b54cea64a5c0dd694ab0341b/packages/cyberstrike/src/agent/agent.ts#L1-L200) · [packages/cyberstrike/src/session/prompt.ts:310-420](https://github.com/CyberStrikeus/CyberStrike/blob/61044eddf31d1549b54cea64a5c0dd694ab0341b/packages/cyberstrike/src/session/prompt.ts#L310-L420) · [packages/cyberstrike/src/methodology/methodology.ts:1-100](https://github.com/CyberStrikeus/CyberStrike/blob/61044eddf31d1549b54cea64a5c0dd694ab0341b/packages/cyberstrike/src/methodology/methodology.ts#L1-L100) · [packages/cyberstrike/src/methodology/phase.ts:1-100](https://github.com/CyberStrikeus/CyberStrike/blob/61044eddf31d1549b54cea64a5c0dd694ab0341b/packages/cyberstrike/src/methodology/phase.ts#L1-L100)

### samugit83/redamon (answered)

**Single-agent ReAct with multi-agent Fireteam extensions.** The main loop is a single LangGraph `StateGraph` compiled in `AgentOrchestrator._build_graph()` (`orchestrator.py:606`). It is a single agent — not a role-based crew — but it can optionally deploy "fireteams": parallel child agents (`build_fireteam_member_graph()`, `fireteam_member_graph.py:78`), each an independent ReAct subgraph, for concurrent tool waves.

**Planning.** The agent uses an LLM-managed todo list (`TodoItem` model, `state.py:142`) and attack-path-type routing (`attack_path_type` in `AgentState`). On each new message, the `initialize_node` (`initialize_node.py:295`) classifies the attack path via `classify_attack_path()`, sets the phase and creates a `ConversationObjective`. The think node (`think_node.py`) assembles a system prompt from the active skill workflow, tool registry, phase definitions, chain memory, and todo list; the LLM produces a structured `LLMDecision` with `action` (use_tool, plan_tools, deploy_fireteam, transition_phase, switch_skill, ask_user, complete). Planning is entirely LLM-driven — there is no hardcoded planner decomposition beyond the phase model.

**Turn structure.** The graph has 14 nodes (orchestrator.py:681-813). Routing: START → initialize → think → (execute_tool | execute_plan | deploy_fireteam | await_approval | await_question | await_tool_confirmation | generate_response). After execute_tool/execute_plan, control returns to think (analyze output → plan next step). Pause nodes (await_approval, await_question, await_tool_confirmation) exit to END; resumption methods (`resume_after_approval_with_streaming`, etc.) feed the user's response back into the graph via `astream()`. 

**Stop conditions.** The loop terminates when `current_iteration >= max_iterations` (default 100, `_route_after_think:849`), `task_complete` is set, the LLM emits `action=complete`, a guardrail blocks the target, or `recursion_limit` (MAX_ITERATIONS × 5) is hit.

**LATS search.** For exploitation phases, an optional Language Agent Tree Search (`lats.py`) replaces the linear ReAct loop with UCT-guided tree search. `lats_hook()` (`lats.py:1985`) runs inside think_node: it evaluates prior probes, backpropagates scores, selects the next node to expand, generates candidate probes via `lats_expand()`, and overrides the LLM decision with the next wave. LATS supports shadow mode (observe-only) and drive mode (probes issued by the tree).


Citations: [agentic/orchestrator.py:606-816](https://github.com/samugit83/redamon/blob/b13da9cb5ad35ae75428b8f21794e799a25fd201/agentic/orchestrator.py#L606-L816) · [agentic/orchestrator.py:847-918](https://github.com/samugit83/redamon/blob/b13da9cb5ad35ae75428b8f21794e799a25fd201/agentic/orchestrator.py#L847-L918) · [agentic/orchestrator_helpers/fireteam_member_graph.py:1-78](https://github.com/samugit83/redamon/blob/b13da9cb5ad35ae75428b8f21794e799a25fd201/agentic/orchestrator_helpers/fireteam_member_graph.py#L1-L78) · [agentic/state.py:978-1078](https://github.com/samugit83/redamon/blob/b13da9cb5ad35ae75428b8f21794e799a25fd201/agentic/state.py#L978-L1078)

### GH05TCREW/pentestagent (answered)

**Single-agent (default) vs crew mode.** The primary agent is `PentestAgentAgent` (`agents/pa_agent/pa_agent.py:15`), which extends `BaseAgent` (`agents/base_agent.py:142`). In **crew mode**, a `CrewOrchestrator` (`agents/crew/orchestrator.py:19`) manages a `WorkerPool` (`agents/crew/worker_pool.py:15`) that spawns independent `PentestAgentAgent` workers, each in its own `LocalRuntime` for state isolation. The orchestrator calls `spawn_agent`, `wait_for_agents`, `formulate_strategy`, and `finish` via dedicated crew tools (`agents/crew/tools.py:14`).

**Task planning and tracking.** On iteration 1 of the agent loop, `_auto_generate_plan()` (`base_agent.py:816`) forces the LLM to decompose the user request into a `TaskPlan` (`tools/finish/__init__.py:44`) of `PlanStep` objects (id, description, status). Steps advance via the `finish` tool (complete/skip/fail). If a step is marked `fail`, `_replan()` (`base_agent.py:924`) generates a new plan or declares the task infeasible. The loop blocks completion until `plan.is_complete()` returns true (`base_agent.py:474`).

**Turn structure.** The core loop `_run_loop()` (`base_agent.py:316`) iterates: (1) LLM generates a response with tool definitions; (2) if the response has tool calls they execute with bounded concurrency (`_execute_tools`, line 736); (3) text-only responses do NOT terminate the loop — they are treated as thinking aloud (`line 365`); (4) after tool execution the plan is checked for failures and completeness. This contrasts with **assist mode** (single LLM call + one tool round, `_assist_loop`, line 1077), **interact mode** (streaming chat with tool calls, `_interact_loop`, line 1175), and **MCP mode** (autonomous loop terminating on stop with no tools, `run_mcp`, line 1265).

**Stop conditions.** The loop exits when: all plan steps are complete (auto-summary generated), a step fails and replanning determines it infeasible, `AGENT_MAX_ITERATIONS` (default 30 from `config/constants.py:67`) is reached — emits a forced-stop warning — or the LLM returns an empty response.


Citations: [pentestagent/agents/base_agent.py:246-275](https://github.com/GH05TCREW/pentestagent/blob/8dde193e41d34ac53ee87374316e5d2fe7cec946/pentestagent/agents/base_agent.py#L246-L275) · [pentestagent/agents/base_agent.py:316-505](https://github.com/GH05TCREW/pentestagent/blob/8dde193e41d34ac53ee87374316e5d2fe7cec946/pentestagent/agents/base_agent.py#L316-L505) · [pentestagent/agents/base_agent.py:816-922](https://github.com/GH05TCREW/pentestagent/blob/8dde193e41d34ac53ee87374316e5d2fe7cec946/pentestagent/agents/base_agent.py#L816-L922) · [pentestagent/tools/finish/__init__.py:44-69](https://github.com/GH05TCREW/pentestagent/blob/8dde193e41d34ac53ee87374316e5d2fe7cec946/pentestagent/tools/finish/__init__.py#L44-L69) · [pentestagent/agents/crew/orchestrator.py:147-404](https://github.com/GH05TCREW/pentestagent/blob/8dde193e41d34ac53ee87374316e5d2fe7cec946/pentestagent/agents/crew/orchestrator.py#L147-L404) · [pentestagent/config/constants.py:60-70](https://github.com/GH05TCREW/pentestagent/blob/8dde193e41d34ac53ee87374316e5d2fe7cec946/pentestagent/config/constants.py#L60-L70)

### Armur-Ai/Pentest-Swarm-AI (answered)

The project implements **two execution modes**: a sequential 5-phase state-machine pipeline (`internal/engine/runner.go`) and a newer **stigmergic swarm** (`internal/engine/swarm_runner.go` + `internal/swarm/`). The swarm is the primary mode, selected by `--swarm` CLI flag.

**Multi-agent architecture**: The swarm has four specialist agents — recon, classifier, exploit, report — each implementing the `swarm.Agent` interface (`internal/swarm/agent.go:19-36`). Agents are stateless between `Handle` calls; all persistent state lives on the blackboard. There is no central planner. Each agent declares a `Trigger()` predicate (e.g. `TARGET_REGISTERED` for recon, raw recon findings for classifier, CVE matches for exploit); the scheduler subscribes and dispatches matching findings as they appear (`swarm_runner.go:750-775`, `scheduler.go:296-418`).

**Planning and decomposition**: Planning emerges from **pheromone-weighted shared state**. Every finding on the blackboard has a `PheromoneBase` (initial weight 0-1) and a `HalfLifeSec` decay. Findings decay over time; agents gate on a `MinPheromone` floor, so stale/unreinforced signals naturally die. The quality tier system (`internal/swarm/quality/quality.go:41-53`) discounts inferential findings from cheap models by up to 40%, forcing them to earn attention through corroboration. Tool-grounded observations bypass discount entirely.

**Turn structure**: The `Scheduler.runAgent` loop (`scheduler.go:299-418`) subscribes to a channel, pulls findings one by one respecting `MaxConcurrency`, calls `Handle()`, commits a cursor for exactly-once delivery, and updates the aggregate and per-agent budgets. Each Handle invocation is a complete turn — the agent reads board state and writes new findings.

**Stop conditions**: The scheduler terminates on: (1) `CAMPAIGN_COMPLETE` finding written to the board, (2) context cancellation (SIGINT), (3) per-campaign time budget (default 20 min in `swarm_runner.go:914`), (4) a `$MaxCostUSD` cost cap watcher in `swarm_runner.go:245-268`, (5) quiescence auto-complete after 60 s of no activity (`scheduler.go:232-271`). Budget exhaustion writes `CAMPAIGN_COMPLETE` rather than aborting, so the report agent fires on partial findings.


Citations: [internal/engine/swarm_runner.go:112-135](https://github.com/Armur-Ai/Pentest-Swarm-AI/blob/40985e3184a5622fa76dc0b491ccb51b48d7acdf/internal/engine/swarm_runner.go#L112-L135) · [internal/swarm/scheduler.go:18-56](https://github.com/Armur-Ai/Pentest-Swarm-AI/blob/40985e3184a5622fa76dc0b491ccb51b48d7acdf/internal/swarm/scheduler.go#L18-L56) · [internal/swarm/scheduler.go:149-294](https://github.com/Armur-Ai/Pentest-Swarm-AI/blob/40985e3184a5622fa76dc0b491ccb51b48d7acdf/internal/swarm/scheduler.go#L149-L294) · [internal/swarm/scheduler.go:296-418](https://github.com/Armur-Ai/Pentest-Swarm-AI/blob/40985e3184a5622fa76dc0b491ccb51b48d7acdf/internal/swarm/scheduler.go#L296-L418) · [internal/swarm/agent.go:1-36](https://github.com/Armur-Ai/Pentest-Swarm-AI/blob/40985e3184a5622fa76dc0b491ccb51b48d7acdf/internal/swarm/agent.go#L1-L36) · [internal/swarm/quality/quality.go:1-76](https://github.com/Armur-Ai/Pentest-Swarm-AI/blob/40985e3184a5622fa76dc0b491ccb51b48d7acdf/internal/swarm/quality/quality.go#L1-L76)

### berylliumsec/nebula (answered)

Nebula uses a **single supervisor/multiple-specialist** architecture built on LangGraph's StateGraph (`orchestration.py:511-556`). A `MissionRuntime` compiles a graph with five nodes — **plan → dispatch → approval → verify → synthesize** — with a conditional edge from dispatch that loops back to dispatch until every task is terminal, then routes to fail/verify/synthesize/approval (`orchestration.py:541-555`, `orchestration.py:1832-1848`).

The **supervisor** (the `Supervisor` protocol at `orchestration.py:245-256`) is a model-backed or static agent that produces a `MissionPlan` containing a DAG of `PlannedTask` objects, each assigned one of eight `SpecialistRole` values: `SCOPE_PLANNING`, `PASSIVE_RECON`, `NETWORK_SERVICE`, `WEB_API`, `VULNERABILITY_INTELLIGENCE`, `CODE_ANALYSIS`, `EVIDENCE_VERIFICATION`, `REPORTING_REMEDIATION` (`orchestration.py:107-116`). Tasks declare `depends_on` dependencies, and the plan validates acyclicity (`orchestration.py:139-172`).

The **specialists** (`BrokeredToolSpecialist` in `agent_tooling.py:259-295`) execute one tool call per model turn. Each specialist is bound to a `SpecialistRole` and sees only its own subset of tools (derived from a `role_for_tool()` prefix map at `agent_tooling.py:74-86`). Turn structure: the model receives the task objective, allowed tools, and prior results; it either calls a tool or calls `nebula.finish_task` (`agent_tooling.py:87-88, 343-346, 776-900`). Finish requires `status` (complete/blocked), `summary`, and `rationale`; it aggregates evidence IDs, reproducible steps, and candidate findings from the specialist's prior turns.

Stop conditions: the model may loop indefinitely within one task until it calls `finish_task`, or hit `_MAX_CONSECUTIVE_ROUTING_DEVIATIONS` (3) empty routing responses (`agent_tooling.py:93`). A `RunBudget` caps max tokens, cost, duration, tool calls, delegation depth (default 3), and retries (default 2) (`domain.py:2560-2569`). Missions enforce budgets at dispatch (`orchestration.py:805-807` throws `BudgetExceeded`). The API layer also sets `MAX_API_MISSION_TOKENS=200K`, `MAX_API_MISSION_COST_USD=100`, and `MAX_API_MISSION_RETRIES=2` (`missions.py:60-64`).

The graph's `_approval` node (`orchestration.py:1961-1980`) pauses the entire mission via LangGraph's `interrupt()` when a tool call requires operator approval; the run enters `WAITING_APPROVAL` status and can be resumed with the approval response (`orchestration.py:639` resume method via `Command(resume=response)`).

> **Editor's note.** Correction: mission planning is deterministic, not model-backed. ToolMissionSupervisor builds the task graph from the operator-selected tools or stages, and the model only drives each specialist's tool turns. The 200K-token / $100 API constants are ceilings on requested budgets; RunBudget caps default to unbounded.

Citations: [src/nebula/v3/orchestration.py:511-556](https://github.com/berylliumsec/nebula/blob/7332d9a05127933d2cc649e6797c9586466cfa8a/src/nebula/v3/orchestration.py#L511-L556) · [src/nebula/v3/orchestration.py:107-116](https://github.com/berylliumsec/nebula/blob/7332d9a05127933d2cc649e6797c9586466cfa8a/src/nebula/v3/orchestration.py#L107-L116) · [src/nebula/v3/orchestration.py:139-172](https://github.com/berylliumsec/nebula/blob/7332d9a05127933d2cc649e6797c9586466cfa8a/src/nebula/v3/orchestration.py#L139-L172) · [src/nebula/v3/orchestration.py:1832-1848](https://github.com/berylliumsec/nebula/blob/7332d9a05127933d2cc649e6797c9586466cfa8a/src/nebula/v3/orchestration.py#L1832-L1848) · [src/nebula/v3/agent_tooling.py:86-93](https://github.com/berylliumsec/nebula/blob/7332d9a05127933d2cc649e6797c9586466cfa8a/src/nebula/v3/agent_tooling.py#L86-L93) · [src/nebula/v3/agent_tooling.py:259-295](https://github.com/berylliumsec/nebula/blob/7332d9a05127933d2cc649e6797c9586466cfa8a/src/nebula/v3/agent_tooling.py#L259-L295)
