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

Principle:7onez Cti expert LLM Phased Investigation

From Leeroopedia
Knowledge Sources
Domains OSINT, LLM_Orchestration, Agent_Design
Last Updated 2026-10-28 14:00 GMT

Overview

Design pattern that runs an investigation as a sequence of LLM-driven phases (Plan→Collect→Correlate→Assess→Verify), each gated by a PreToolUse hook, bounded by a wall-clock timeout, and forced to structured output where applicable.

Description

LLM Phased Investigation addresses the problem of unbounded agent autonomy: a single LLM session given a full OSINT skill and no structure will flail — it will collect haphazardly, never decide it has enough to assess, and blow its context budget before reaching a judgment. The phased pattern decomposes the investigation into discrete phases, each with:

  • A pinned system prompt (the skill body) so the model always knows the tradecraft.
  • A restricted tool subset so each phase can only do what its stage requires (Plan phase cannot collect; Assess phase cannot re-collect).
  • A PreToolUse gate bound as a closure over (case, phase, hostile) — phases run concurrently (collect fan-out, parallel cluster judgment) and the hook fires on the SDK's own task, so a module global would attribute one phase's tool calls to another. The closure binds the right values at construction time.
  • A wall-clock timeout — a hung tool call must not stall a round forever; a timeout is a FAILED phase, never a silent pass.
  • An optional output schema (Pydantic) forcing structured output for the Assess phase.

Usage

Use this principle when designing any LLM-driven investigation or analysis pipeline where:

  • The investigation has distinct stages that must execute in order but may fan out within a stage.
  • Tool access must be gated per stage (collection tools are dangerous in the assessment stage).
  • Concurrency within a stage (parallel collection, parallel cluster judgment) requires per-call context isolation.
  • The model's output must be structured for downstream consumption (assessments, plans).

Theoretical Basis

The pattern rests on three invariants:

1. Phase isolation: each phase is an independent SDK query with its own tool set, system prompt, and context. A phase cannot reach into another phase's tools — the allowed_tools list is the enforcement boundary.

2. Closure-bound gating: the PreToolUse hook is a closure, not ambient state. This prevents the race where phase A's tool call is attributed to phase B because they share a ContextVar. The closure binds (case, phase, hostile) at construction time and cannot race.

# Abstract pattern (NOT real implementation)
async def phase(prompt, label, tools, hostile, case):
    gate = make_closure(case, label, hostile)  # bound HERE, not at call time
    options = AgentOptions(
        system_prompt=skill_body,
        allowed_tools=tools,
        hooks={"PreToolUse": [gate]},
        permission_mode="bypass",  # suppress prompts, NOT governance
    )
    return await asyncio.wait_for(query(prompt, options), timeout=PHASE_TIMEOUT)

3. Failure classification: a hard failure (auth, credits, backend down) raises BackendUnavailable so the harness can switch backends. A soft stop (max_turns) is logged, not raised — the tool calls it made still landed. An auth failure at $0.00 is never a ✓.

Related Pages

Implemented By

Used By Workflow

Uses Heuristic

Page Connections

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