Agentic Loop Module (WindowsAgenticLoop.Common.psm1)#
A reusable PowerShell module for the planner/executor agentic loop pattern. Lets any project set up an autonomous coding loop with:
A planner (expensive model, e.g. Claude Fable 5 or GLM 5.2) that analyzes the codebase and writes tasks to
BACKLOG.md.An executor (cheaper model, e.g. Claude Sonnet or DeepSeek v4 Flash) that drains the queue one task at a time, building and testing as it goes.
Builds, tests, and quality gates on configurable intervals, cycling through different build configurations.
A build fixer: when a periodic build fails, the executor-tier model is dispatched with the build log tail to fix it, and the loop stops after N consecutive unfixable failures.
Engines#
Two agent CLI backends are supported; select via config engine,
$env:AGENTIC_ENGINE, or the -Engine parameter of Invoke-AgenticLoop:
Engine |
Invocation |
Role prompts |
Permissions |
|---|---|---|---|
|
|
|
Configured in |
|
|
|
Planner sandboxed via |
For claude, engines.claude.plannerFallbackModel maps to
--fallback-model so an overloaded planner model (e.g. claude-fable-5)
falls back automatically (e.g. to claude-opus-4-8).
Model resolution precedence: $env:AGENTIC_PLANNER_MODEL /
$env:AGENTIC_EXECUTOR_MODEL > engines.<engine>.plannerModel/executorModel
legacy
models.planner/executor.
Agent invocations retry with linear backoff (agentRetries ×
agentRetryDelaySeconds) and honor per-role timeouts
(plannerTimeoutSeconds / executorTimeoutSeconds, falling back to
timeoutSeconds; 0 = no timeout).
Prerequisites#
OpenCode CLI and/or Claude Code CLI installed and authenticated
PowerShell 7+ (cross-platform)
A
BACKLOG.mdfile in the repository root (task format:- [ ] Titlefor actionable tasks,- [b] Titlefor blocked/parked ones the executor must skip)jqon Linux (for config parsing in the Bash equivalent,linux/scripts/lib/agentic-loop.sh, which mirrors this module’s engine support)
Installation#
Place the module in your repository’s module path, then import it:
# If using Kataglyphis-ContainerHub as a submodule:
$modulePath = Resolve-Path 'ExternalLib/Kataglyphis-ContainerHub/windows/scripts/modules/WindowsAgenticLoop.Common.psm1'
Import-Module $modulePath -Force
Do not vendor a copy into the consumer repo — resolve it ContainerHub-first
(e.g. BeschleunigerBallett’s Resolve-BuildModule.ps1); vendored duplicates
are exactly the drift the 2026-08-02 dedup pass removed.
Quick Start#
Create a Run-AgenticLoop.ps1 script in your project:
# scripts/agentic-loop/Run-AgenticLoop.ps1
$repoRoot = (Resolve-Path (Join-Path $PSScriptRoot '..')).Path
$configPath = Join-Path $PSScriptRoot 'AgenticLoop.config.json'
$config = Get-Content $configPath -Raw | ConvertFrom-Json
Import-Module (Join-Path $repoRoot 'ExternalLib/Kataglyphis-ContainerHub/windows/scripts/modules/WindowsAgenticLoop.Common.psm1') -Force
Initialize-AgenticLoop -ConfigPath $configPath -RepoRoot $repoRoot
Invoke-AgenticLoop -Config $config -RepoRoot $repoRoot
Complete-AgenticLoop
That is the whole wrapper: build configs are selected from the config’s
platform-appropriate buildMatrix (legacy buildConfigurations fallback)
and the planner / refactor-planner / executor task prompts default to the
shared prompt files (see Default Task Prompts).
Pass -BuildConfigs / -PlannerPrompt / -ExecutorPrompt /
-RefactorPlannerPrompt only to override.
Module API#
Initialization & Lifecycle#
Function |
Purpose |
|---|---|
|
Set up logging, platform detection, global trap. Returns context hashtable. |
|
Write final summary and exit with the accumulated exit code. |
Logging#
Function |
Purpose |
|---|---|
|
Timestamped log to file + console. |
|
Decorated section header. |
|
Returns the current log file path. |
Platform Detection#
Function |
Purpose |
|---|---|
|
Returns |
|
|
Agent Invocation#
Function |
Purpose |
|---|---|
|
Resolve engine + models + prompt files + timeouts into a flat hashtable. |
|
Engine dispatcher with retry + linear backoff. Returns |
|
Passes message via stdin to |
|
Headless |
|
Low-level process runner (stdin prompt, streamed stdout/stderr, timeout). |
|
Dispatch the fixer role with the tail of the loop log after a build failure. |
|
StrictMode-safe config lookup (hashtable or PSCustomObject). |
|
Per-role timeout resolution. |
Default Task Prompts#
The per-phase TASK prompts (the message piped to each agent invocation — not the engine role/system prompts, which stay project-owned) are single-sourced as Markdown files in this repository:
shared/agentic-loop/prompts/planner.md
shared/agentic-loop/prompts/refactor-planner.md
shared/agentic-loop/prompts/executor.md
Function |
Purpose |
|---|---|
|
Read the shared default prompt for a role (throws if the file is missing). |
Invoke-AgenticLoop’s -PlannerPrompt, -RefactorPlannerPrompt, and
-ExecutorPrompt parameters are optional and default to these files, so
project wrappers do not need to hard-code prompt text. The Bash library’s
default_planner_prompt / default_refactor_planner_prompt /
default_executor_prompt (in linux/scripts/lib/agentic-loop.sh) read the
same files, keeping both platforms in lockstep — edit the prompt file once
and both loops pick it up.
Utility#
Function |
Purpose |
|---|---|
|
Count actionable |
|
Count blocked |
|
Detect a Claude usage/session-limit failure and return seconds to sleep until the stated reset (0 = not a limit failure). |
|
|
Build / Test / Quality Wrappers#
Function |
Purpose |
|---|---|
|
Execute a build command, log output, return |
|
Execute a test command, log output, return |
|
Execute a quality gate, log output. |
Build Matrix & Sanitizer-Aware Testing#
Function |
Purpose |
|---|---|
|
Normalize a string or JSON object to a hashtable with |
|
Return a hashtable of env vars for the given sanitizer ( |
|
Set sanitizer env vars, run tests, restore env. |
See agentic-loop-build-matrix.md for the
full build matrix documentation.
High-Level Loop#
Function |
Purpose |
|---|---|
|
Full planner/executor loop with build matrix cycling, sanitizer-aware tests, full matrix sweeps, and quality gates. |
Invoke-AgenticLoop Parameters#
Parameter |
Type |
Description |
|---|---|---|
|
|
Configuration object (from JSON: models, intervals, build, git, logging) |
|
|
Engine override ( |
|
|
Optional prompt message for the planner agent; defaults to the shared |
|
|
Optional prompt for refactor-focus iterations; defaults to the shared |
|
|
Optional prompt message for the executor agent; defaults to the shared |
|
|
Build matrix entries (string[] or object[] with name, sanitizer, testCommand, buildDir, buildType); optional — defaults to the platform’s |
|
|
|
|
|
Repository root directory |
|
|
Override max iterations (-1 = use config, 0 = unlimited) |
|
|
Skip builds |
|
|
Skip tests |
|
|
Skip quality gates |
|
|
Run planner once and exit |
|
|
Drain the queue and exit |
Config JSON Keys#
The config is read from AgenticLoop.config.json. Key sections:
Key |
Type |
Default |
Description |
|---|---|---|---|
|
|
|
Agent CLI backend: |
|
|
— |
Model ID for the planner (per engine) |
|
|
— |
Model ID for the executor (per engine) |
|
|
— |
|
|
|
— |
Repo-relative role prompt appended via |
|
|
— |
Repo-relative role prompt for executor/fixer |
|
|
— |
Space-separated |
|
|
|
Executor permission mode ( |
|
|
— |
Extra CLI args appended to every claude invocation |
|
|
|
Stream live progress (tool calls, per-turn text, final cost) via |
|
|
|
Legacy fallback model ID for the planner agent |
|
|
|
Legacy fallback model ID for the executor agent |
|
|
3 |
Build after every N completed tasks |
|
|
5 |
Quality gate every M tasks |
|
|
3 |
Refactor focus every R iterations |
|
|
0 |
Full matrix sweep every N iterations (0 = disabled) |
|
|
0 |
Max loop iterations (0 = unlimited) |
|
|
3 |
Retries before skipping a stuck task |
|
|
10 |
Delay between loop iterations |
|
|
0 |
Generic agent invocation timeout (0 = none) |
|
|
0 |
Planner timeout override |
|
|
0 |
Executor/fixer timeout override |
|
|
2 |
Retries per agent invocation (linear backoff) |
|
|
20 |
Base backoff delay between agent retries |
|
|
|
Dispatch the fixer agent after a failed build, then rebuild once |
|
|
3 |
Stop the loop after N consecutive failed build phases |
|
|
|
When an agent fails because the Claude usage/session limit was hit, sleep until the reset time stated in the message (+2 min) and retry without burning a retry attempt (capped at 10 waits per invocation) |
|
|
— |
Windows build matrix entries (objects with name, sanitizer, buildDir, buildType, testCommand) |
|
|
— |
Linux build matrix entries |
|
|
— |
Fallback test command for Windows |
|
|
— |
Fallback test command for Linux |
|
|
— |
Quality command for Windows |
|
|
— |
Quality command for Linux |
|
|
|
Auto-commit after each completed task |
|
|
|
Prefix for auto-commit messages |
|
|
|
Skip the planner phase while |
|
|
|
Prune completed ( |
Usage Examples#
Basic loop (with config file)#
Import-Module WindowsAgenticLoop.Common -Force
Initialize-AgenticLoop -ConfigPath 'AgenticLoop.config.json'
# ... configure and call Invoke-AgenticLoop ...
Complete-AgenticLoop
Dry run to test configuration#
Initialize-AgenticLoop -ConfigPath 'AgenticLoop.config.json' -DryRun
Invoke-AgenticLoop -Config $cfg -RepoRoot $repoRoot
Planner only (add tasks without executing)#
Invoke-AgenticLoop -Config $cfg -RepoRoot $repoRoot -PlannerOnly
Executor only (drain existing queue)#
Invoke-AgenticLoop -Config $cfg -RepoRoot $repoRoot -ExecutorOnly