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:7onez Cti expert Orchestrator Phase Run

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

Overview

Concrete tool for running one LLM-driven investigation phase under a wall-clock timeout, provided by the cti-expert orchestrator.

Description

The _phase_run function in orchestrator.py executes a single phase of the investigation loop (Plan, Collect, Correlate, Assess, Verify) as a Claude Agent SDK query. It constructs ClaudeAgentOptions with a pinned system prompt (the skill body), a restricted tool subset, a PreToolUse gate hook bound as a closure over (case, phase, hostile), and an optional Pydantic output schema. Headless mode uses bypassPermissions to suppress prompts — but NOT ungoverned: every tool call passes the PreToolUse gate that enforces hostile-egress, sandbox-submission, and metered-budget rules.

A timeout wrapper (_phase) enforces a wall-clock ceiling (PHASE_TIMEOUT); a timeout is a FAILED phase, never a silent pass. An auth/backend failure raises BackendUnavailable so the harness can switch backends.

Usage

Import this when you need to:

  • Run one phase of the LLM-driven investigation loop with structured output.
  • Enforce per-phase tool gating (the PreToolUse closure binds case/phase/hostile at construction time to prevent cross-phase attribution races).
  • Capture model cost (total_cost_usd) and failure classification per phase.

Code Reference

Source Location

  • Repository: cti-expert
  • File: intel_engine/harness/orchestrator.py
  • Lines: L262-335 (_phase, _phase_run)

Signature

async def _phase(prompt, *, label, **kw):
    """Run one phase under PHASE_TIMEOUT; a timeout is a FAILED phase (never a silent pass)."""

async def _phase_run(prompt, *, label, system, tools, servers, resume=None,
                     model=None, effort=None, output_schema=None, hostile=False, case=None):
    """Execute one phase as a Claude Agent SDK query with gated tools and optional
    structured output. Returns the ResultMessage, or raises BackendUnavailable /
    RuntimeError on hard failure."""

Import

# Internal to orchestrator.py — not a public import
from orchestrator import _phase, _phase_run

I/O Contract

Inputs

Name Type Required Description
prompt str Yes Phase task prompt
label str Yes Phase name (plan/collect/correlate/assess/verify)
system str Yes Skill body pinned as system_prompt
tools list Yes Phase tool subset (allowed_tools)
servers dict Yes MCP server configs
resume str No Resume token for continuation
model str No LLM model override
effort str No Reasoning effort level
output_schema BaseModel No Pydantic schema for structured JSON output
hostile bool No Deny direct egress (default False)
case str No Case ID for gate context

Outputs

Name Type Description
result ResultMessage SDK result with total_cost_usd, is_error, subtype

Usage Examples

Running the Plan Phase

from harness.schemas import Plan

result = await _phase(
    plan_prompt,
    label="plan",
    system=skill_body,
    tools=PLAN_TOOLS,
    servers=mcp_servers,
    model="claude-sonnet-5-5",
    effort="high",
    output_schema=Plan,
    case=case_id,
)
# result.total_cost_usd has the model spend

With Hostile Egress

# Collect phase with hostile=True: the PreToolUse gate denies direct fetches
result = await _phase(
    collect_prompt,
    label="collect",
    system=skill_body,
    tools=COLLECT_TOOLS,
    servers=mcp_servers,
    hostile=True,          # gate denies direct egress to attacker infra
    case=case_id,
)

Related Pages

Implements Principle

Requires Environment

Uses Heuristic

Page Connections

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