Context / Harness / Loop Engineering

Unified Context, Harness, and Loop (CHL) engineering principles for PraisonAI with a measurable rubric mapping each principle to modules, CLI commands, and evaluators.

PraisonAI implements three pillars of agentic reliability engineering — Context, Harness, and Loop (CHL). This page defines each principle, maps it to concrete modules and CLI commands, and specifies a measurable rubric with pass thresholds so teams can validate “framework compliance” consistently and gate releases on quantitative CHL scores.

Diagram

Context Engineering

CHL Rubric

Harness Engineering

Loop Engineering

Pass / Fail Gate


1. Principles

1.1 Context Engineering

Context Engineering governs what the model sees on every turn: keeping token usage within budget, compacting history without losing meaning, injecting the right artifacts, and handing off cleanly between agents.

Sub-principleMeaningCode anchor
BudgetTotal prompt tokens stay within a configured budgetcontext/ (token budgeter), eval/tokens.py
CompactionHistory is compressed with high semantic retentioncompaction/ (6 strategies)
InjectionRelevant files/artifacts are added deterministicallycontext/ (artifacts, fast context)
HandoffContext transfers between agents without lossagent/ handoff, ContextAgent PRP

1.2 Harness Engineering

Harness Engineering guarantees that the environment the agent runs in during testing matches production: identical tool schemas, reproducible turn context, and required trace/artifact outputs.

Sub-principleMeaningCode anchor
ParityPreparedTurnContext tool schemas match runtime exactlyruntime/turn_context.py
TracesEach turn emits a structured, replayable tracetrace/, harness runner
ArtifactsRequired output files are present after a runinteractive test harness / CSV runner

1.3 Loop Engineering

Loop Engineering makes autonomous iteration converge safely: reaching a quality threshold in a bounded number of iterations while doom-loop guards prevent unproductive repetition.

Sub-principleMeaningCode anchor
ConvergenceIterations reach the target score within a boundeval/loop.py (EvaluationLoop)
GuardrailsDoom-loop / repeat guards fire on stagnationagent/autonomy.py, loop guards
EfficiencyFewest iterations for a given quality targeteval/loop.py iteration metrics

2. Measurable rubric

Each row maps a principle to a metric, a pass threshold, and the evaluator that produces the score. Targets are defaults — override per project via config.

PrincipleMetricTargetEvaluator
Context handoffhandoff score 0–10≥ 8.0ContextEvaluator
Context budgettokens ≤ budget100% complianceContextEvaluator
Compaction losssemantic retention (judge score)≥ 7.0ContextEvaluator
Harness paritytool schema hash match100%HarnessEvaluator
Harness artifactsrequired files present100%HarnessEvaluator
Loop convergenceiterations to threshold≤ N (configurable)LoopEvaluator
Doom-loop safetyguard fires on repeat fixturerequiredLoopEvaluator

Interpreting scores


3. Cross-links

3.1 CLI commands

bash
# Context: budgeting and compaction
praisonai context            # inspect / manage context window
praisonai compaction         # run and inspect compaction strategies

# Harness: reproducible interactive testing
praisonai test interactive --suite smoke   # run a built-in harness suite
praisonai test interactive --list          # list available suites

# Loop: bounded autonomous iteration
praisonai loop               # run the evaluation / improvement loop

# Eval: run any evaluator (accuracy, safety, loop, ...)
praisonai eval

3.2 Python entry points

python
from praisonaiagents.eval import (
    EvaluationLoop,        # Loop convergence + efficiency
    estimate_tokens,       # Context budget checks
    count_tokens,
)
# Compaction judge and the interactive test harness cover the
# remaining Context and Harness rows until the dedicated
# ContextEvaluator / HarnessEvaluator / LoopEvaluator land.

3.3 Related docs


4. Running a CHL eval suite

Once the dedicated evaluators land, a CHL suite runs like any other evaluation:

python
from praisonaiagents.eval import EvalSuite

# Composes Context / Harness / Loop evaluators into one report,
# scored against the rubric thresholds in Section 2.
suite = EvalSuite(name="chl-compliance")
report = suite.run(print_summary=True)

Wire the resulting pass/fail into CI to gate releases on quantitative CHL scores.


5. Summary

PillarQuestion it answersRubric rows
ContextDoes the agent see the right, budgeted, well-compacted context?budget, compaction, handoff
HarnessDoes the test environment match production exactly?parity, artifacts
LoopDoes autonomy converge safely without doom loops?convergence, doom-loop safety

CHL turns scattered examples and code comments into a single, measurable definition of “framework compliance” that engineers can onboard against and CI can enforce.