Skip to content

richfrem/agent-plugins-skills / plugins/agent-orchestration/.apm/skills/orchestrating-agent-work

orchestrating-agent-work

Verified

Interactive orchestrator for complex engineering work. Analyzes the task, conducts a diagnostic interview to select the appropriate execution strategy (Directed Acyclic Graph versus Loop, and which Loop type), plans the artifact, and supervises execution and verification. Use for "how should I orchestrate this", "plan this workflow", "should this be a DAG or a loop", "run these jobs in parallel", "delegate this to a worker agent", or "run/resume this graph manifest". Not for single trivial edits or skill self-improvement.

FileKindSize
SKILL.mdskill md6.8 KB
assets/templates/dual-loop-meta-tasks.mdmarkdown1.6 KB
assets/templates/loop_retrospective_template.mdmarkdown1.5 KB
assets/templates/red_team_briefing_template.mdmarkdown747 B
assets/templates/scratchpad-template.mdmarkdown991 B
assets/templates/strategy-packet-template.mdmarkdown1.2 KB
assets/templates/workflow-retrospective-template.mdmarkdown1.3 KB
evals/evals.jsonconfig7.0 KB
references/PATTERN_GUIDE.mdmarkdown6.2 KB
references/acceptance-criteria.mdmarkdown6.8 KB
references/agentic-os-reuse-map.mdmarkdown2.5 KB
references/bot-delegation-patterns.mdmarkdown5.2 KB
references/cheapest_models.jsonconfig845 B
references/cheapest_models.mdmarkdown1.1 KB
references/cli-agent-executor.mdmarkdown3.5 KB
references/delegated-dag-refactoring-playbook.mdmarkdown5.5 KB
references/diagrams/agent_swarm.mmdother1.8 KB
references/diagrams/dual_loop_architecture.mmdother1.4 KB
references/diagrams/graph-planner-flow.mmdother540 B
references/diagrams/graph_execution_state_machine.mmdother823 B
references/diagrams/orchestrating_agent_work_architecture.mmdother4.5 KB
references/dispatch-preflight.mdmarkdown2.1 KB
references/fallback-tree.mdmarkdown9.7 KB
references/graph-execution.mdmarkdown4.1 KB
references/graph-manifest-schema.jsonconfig7.0 KB
references/graph-planning.mdmarkdown3.0 KB
references/learning-loop.mdmarkdown4.9 KB
references/patterns.jsonconfig2.0 KB
references/post_run_survey.mdmarkdown1.4 KB
references/routing-and-closure.mdmarkdown2.4 KB
references/strategy-agent-swarm.mdmarkdown2.1 KB
references/strategy-dual-loop.mdmarkdown1.6 KB
references/strategy-red-team-review.mdmarkdown2.0 KB
references/strategy-selection.mdmarkdown4.0 KB
references/topology-rules.mdmarkdown6.0 KB
scripts/agent_orchestrator.pyscript7.6 KB
scripts/dispatch_guard.pyscript1.1 KB
scripts/graph_runner.pyexecutablescript36.3 KB
scripts/select_strategy.pyscript13.1 KB
scripts/swarm_run.pyscript28.0 KB
scripts/validate_manifest.pyexecutablescript19.8 KB
scripts/work_loop.pyscript28.0 KB
tests/_loop_fixtures.pyscript2.5 KB
tests/test_graph_fixes.pyscript12.6 KB
tests/test_graph_runner.pyscript30.0 KB
tests/test_isolation.pyscript3.5 KB
tests/test_loop_strategies.pyscript7.7 KB
tests/test_select_strategy.pyscript7.8 KB
tests/test_swarm_run.pyscript9.4 KB
tests/test_swarm_run_models.pyscript3.1 KB
tests/test_validate_manifest.pyscript18.1 KB
tests/test_work_loop_e2e.pyscript3.8 KB
tests/test_work_loop_hardening.pyscript27.3 KB

tests/test_select_strategy.py

View on GitHub
"""
Tests for Deterministic Strategy Selector (PR C)
=================================================

Validates:
1. Mapping of diagnostic dimensions to expected patterns.
2. Comprehensive table-driven test covering all 72 answer combinations.
3. Strict validation: invalid answers and invalid overrides fail closed.
4. Override records 'override_requested' without claiming human authority.
5. Adversarial assurance acts as a modifier wrapper and does not overwrite build topology.
6. Ambiguous or missing inputs return 'needs_clarification'.
7. Non-interactive execution fails closed (exit code 2) when inputs are incomplete.
8. Clean tree guarantee: no files written unless --out is provided.
"""

import json
import itertools
import subprocess
import sys
from pathlib import Path
import pytest

sys.path.insert(0, str(Path(__file__).resolve().parents[1]))

from scripts.select_strategy import (
    decide_strategy,
    validate_answers,
    DIMENSION_OPTIONS,
    VALID_PATTERNS,
)


def test_rule_mapping_swarm_vs_graph():
    swarm_answers = {
        "unit_structure": "many_identical",
        "ordering_convergence": "none",
        "assurance_need": "normal",
        "task_nature": "build_fix",
    }
    swarm_dec = decide_strategy(swarm_answers)
    assert swarm_dec["status"] == "success"
    assert swarm_dec["pattern"] == "agent-swarm"
    assert swarm_dec["next_skill"] == "agent-swarm"

    graph_answers = {
        "unit_structure": "distinct_steps",
        "ordering_convergence": "none",
        "assurance_need": "normal",
        "task_nature": "build_fix",
    }
    graph_dec = decide_strategy(graph_answers)
    assert graph_dec["status"] == "success"
    assert graph_dec["pattern"] == "graph"
    assert graph_dec["next_skill"] == "graph-planner"


def test_rule_mapping_direct_minimal_change():
    direct_answers = {
        "unit_structure": "minimal_direct",
        "ordering_convergence": "none",
        "assurance_need": "normal",
        "task_nature": "build_fix",
    }
    dec = decide_strategy(direct_answers)
    assert dec["status"] == "success"
    assert dec["pattern"] == "direct"
    assert dec["next_skill"] is None


def test_rule_mapping_adversarial_is_wrapper():
    adv_answers = {
        "unit_structure": "distinct_steps",
        "ordering_convergence": "barrier",
        "assurance_need": "adversarial",
        "task_nature": "build_fix",
    }
    dec = decide_strategy(adv_answers)
    assert dec["status"] == "success"
    assert dec["pattern"] == "graph"
    assert dec["assurance"] == "adversarial"
    assert "red-team-review" in dec.get("advisory_wrappers", [])


def test_table_driven_all_72_combinations():
    units = DIMENSION_OPTIONS["unit_structure"]
    orderings = DIMENSION_OPTIONS["ordering_convergence"]
    assurances = DIMENSION_OPTIONS["assurance_need"]
    natures = DIMENSION_OPTIONS["task_nature"]

    combinations = list(itertools.product(units, orderings, assurances, natures))
    assert len(combinations) == 72

    for u, o, a, n in combinations:
        ans = {
            "unit_structure": u,
            "ordering_convergence": o,
            "assurance_need": a,
            "task_nature": n,
        }
        dec = decide_strategy(ans)
        assert dec["status"] == "success", f"Failed for {ans}"
        assert dec["pattern"] in VALID_PATTERNS, f"Unknown pattern {dec['pattern']} for {ans}"
        assert dec["rationale"], f"Empty rationale for {ans}"


def test_answer_validation_rejects_invalid_values():
    errs = validate_answers({"unit_structure": "banana"})
    assert len(errs) == 1
    assert "Invalid value 'banana'" in errs[0]

    errs_dim = validate_answers({"bogus_dim": "val"})
    assert len(errs_dim) == 1
    assert "Unknown dimension 'bogus_dim'" in errs_dim[0]


def test_cli_invalid_answers_exits_nonzero(tmp_path):
    script = Path(__file__).resolve().parents[1] / "scripts" / "select_strategy.py"
    cmd = [
        sys.executable,
        str(script),
        "--answers", '{"unit_structure": "banana"}',
        "--non-interactive",
    ]
    res = subprocess.run(cmd, capture_output=True, text=True)
    assert res.returncode == 1
    assert "Invalid value 'banana'" in res.stderr


def test_cli_invalid_override_rejected(tmp_path):
    script = Path(__file__).resolve().parents[1] / "scripts" / "select_strategy.py"
    answers = json.dumps({
        "unit_structure": "one_bounded",
        "ordering_convergence": "none",
        "assurance_need": "normal",
        "task_nature": "build_fix",
    })
    cmd = [
        sys.executable,
        str(script),
        "--answers", answers,
        "--override", "yolo",
    ]
    res = subprocess.run(cmd, capture_output=True, text=True)
    assert res.returncode == 1
    assert "Invalid override pattern 'yolo'" in res.stderr


def test_cli_override_records_requested_override_without_human_claim(tmp_path):
    script = Path(__file__).resolve().parents[1] / "scripts" / "select_strategy.py"
    answers = json.dumps({
        "unit_structure": "one_bounded",
        "ordering_convergence": "none",
        "assurance_need": "normal",
        "task_nature": "build_fix",
    })
    cmd = [
        sys.executable,
        str(script),
        "--answers", answers,
        "--out", str(tmp_path),
        "--override", "graph",
        "--override-reason", "Architect requested DAG checkpointing",
    ]
    res = subprocess.run(cmd, capture_output=True, text=True)
    assert res.returncode == 0
    decision_file = tmp_path / "select-loop-strategy-decision.json"
    assert decision_file.is_file()
    dec = json.loads(decision_file.read_text(encoding="utf-8"))
    assert dec["pattern"] == "graph"
    assert "override_requested" in dec
    assert dec["override_requested"]["from"] == "dual-loop"
    assert dec["override_requested"]["to"] == "graph"
    assert dec["override_requested"]["reason"] == "Architect requested DAG checkpointing"
    assert "overridden_by" not in dec  # Does not claim human authorization


def test_cli_no_out_flag_does_not_dirty_tree():
    script = Path(__file__).resolve().parents[1] / "scripts" / "select_strategy.py"
    answers = json.dumps({
        "unit_structure": "one_bounded",
        "ordering_convergence": "none",
        "assurance_need": "normal",
        "task_nature": "build_fix",
    })
    cmd = [
        sys.executable,
        str(script),
        "--answers", answers,
    ]
    res = subprocess.run(cmd, capture_output=True, text=True)
    assert res.returncode == 0
    assert not Path(".orchestration").exists()
    data = json.loads(res.stdout)
    assert data["status"] == "success"
    assert data["pattern"] == "dual-loop"


def test_pattern_catalog_parity():
    """
    Asserts exact parity across:
    1. Canonical references/patterns.json (agent-orchestration)
    2. Symlinked select-loop-strategy/references/patterns.json
    3. Fallback VALID_PATTERNS in select_strategy.py
    """
    repo_root = Path(__file__).resolve().parents[3]
    patterns_canonical = repo_root / "plugins" / "agent-orchestration" / "references" / "patterns.json"
    patterns_symlink = (
        repo_root
        / "plugins"
        / "agent-orchestration"
        / "skills"
        / "select-loop-strategy"
        / "references"
        / "patterns.json"
    )

    assert patterns_canonical.is_file(), f"Missing {patterns_canonical}"
    assert patterns_symlink.is_file(), f"Missing {patterns_symlink}"

    with open(patterns_canonical, "r", encoding="utf-8") as f:
        canon_data = json.load(f)

    with open(patterns_symlink, "r", encoding="utf-8") as f:
        symlink_data = json.load(f)

    canon_keys = set(canon_data.keys())
    symlink_keys = set(symlink_data.keys())
    valid_keys = set(VALID_PATTERNS)

    assert canon_keys == symlink_keys, "Symlink patterns.json does not match canonical"
    assert canon_keys == valid_keys, "select_strategy.py VALID_PATTERNS does not match patterns.json"


reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis.Stars: 471kUpdated Claude CodeCodexVerifiedInstall
diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness.Stars: 322kUpdated Claude CodeCodexVerifiedInstall
dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependenciesStars: 322kUpdated Claude CodeCodexVerifiedInstall
executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is availableStars: 322kUpdated Claude CodeCodexVerifiedInstall