Skip to main content

Crate harness_loop

Crate harness_loop 

Source
Expand description

ReAct agent loop with self-correction.

Minimal v0.0.1 implementation:

  • Applies guides once at the start.
  • Sends Context (with tools) to the model.
  • Dispatches each returned tool call via ToolRegistry.
  • Runs Sensor::SelfCorrect sensors after each action; auto-fix patches are applied directly to the world, blocking signals are fed back to the model.
  • Stops when the model returns no tool calls, when policy.max_iters is hit, or when a stuck-detector (StuckPolicy, MonotonyPolicy) says the run is spinning.

Re-exports§

pub use acceptance::Acceptance;
pub use acceptance::FilesExist;
pub use acceptance::NonEmptyAnswer;
pub use acceptance::Verdict;
pub use goal::Goal;
pub use goal::GoalStore;
pub use goal::Phase;
pub use goal::PhaseStatus;
pub use receipt::Receipt;
pub use receipt::ReceiptBuilder;
pub use seal::SealBreach;
pub use seal::SealSet;
pub use trajectory::GoldenDiff;
pub use trajectory::Report;
pub use trajectory::Rule;
pub use trajectory::RuleSet;
pub use trajectory::Step;
pub use trajectory::Trajectory;
pub use trajectory::TrajectoryCheck;
pub use trajectory::Violation;
pub use events::HostEvent;
pub use events::NoticeGuide;
pub use learning::*;
pub use memory_layer::*;
pub use boundary_guide::*;
pub use profile_guide::*;
pub use recall_layer::*;
pub use registry::*;
pub use replay::*;
pub use subagent::*;
pub use telemetry::*;

Modules§

acceptance
What “done” means, checked before the loop says so.
blueprint
Blueprint — deterministic + agent hybrid state machine (Stripe Minions pattern).
boundary_guide
Opt-in Guide for the requests an agent cannot fulfil.
compactor
Five-stage progressive compaction (DESIGN.md §9), borrowed from Claude Code.
daemon
Optional standalone scheduler for the harness-rs ecosystem.
events
What wakes a host that is not in the middle of a run.
experience
harness-experience — learn from what you did before
goal
A goal: the run itself, written down and survivable.
hooks
HookBus — dispatch the lifecycle events to registered Hooks.
learning
Self-evolving learning loop for crate::AgentLoop.
loop_engine
harness-loop-engine — loop engineering for harness-rs
memory_layer
Long-term-memory wiring for crate::AgentLoop.
meters
Metrics — what runs cost and how they behave, as numbers a dashboard can aggregate across thousands of runs. Traces answer “what happened in this run”; these answer “what is p95 tool latency this week” and “which model is eating the token budget”, which no amount of per-run spans can.
orchestrator
harness-orchestrator — single-machine async Run orchestration
profile_guide
Opt-in Guide that renders harness_core::UserProfile into the agent’s system prompt.
recall_layer
Cross-session recall wiring for crate::AgentLoop.
receipt
What the run can show for itself.
registry
A tiny name-keyed tool registry used by AgentLoop.
replay
Session record + replay (DESIGN.md §15 v0.2+).
sandbox
Sandbox trait + concrete backends.
scheduler
In-process agent scheduling + delivery for harness-rs. Optional — nothing else in the framework depends on it.
seal
Making the gate unforgeable.
subagent
Subagent: an isolated agent loop spawned from a parent.
telemetry
TelemetryHook — maps the agent’s lifecycle Event stream onto structured tracing spans and events, so a run becomes observable in any tracing subscriber.
templates
Pre-built Blueprint templates per DESIGN.md §15 (v0.1 roadmap).
timeline
A recorded run as a self-contained HTML timeline — one file, no server, no scripts or fonts fetched from anywhere. harness trace run.jsonl --html out.html writes one; render_html is the same thing as a function.
trajectory
Trajectory checking: did the agent take a correct path?

Macros§

node_async
Convenience: avoid the Box::pin boilerplate when the closure doesn’t borrow w.

Structs§

AgentLoop
The agent loop.
CancellationToken
The token AgentLoop::with_cancellation takes, re-exported so a caller can cancel a run without depending on tokio-util directly. A token which can be used to signal a cancellation request to one or more tasks.
CompactPolicy
Governs when and how far the loop compacts context. Hysteresis: only start compacting once usage crosses high_water, and stop as soon as it’s back under target — instead of running every stage above a threshold on every turn. This avoids over-compacting (needlessly reaching the lossy, main-model AutoCompact stage) and, because compaction rewrites history and invalidates the provider prefix cache, avoids nibbling the context every single turn.
MonotonyPolicy
A second stuck signal, orthogonal to StuckPolicy: the model calls one tool round after round — a different argument every time, so nothing ever repeats — and never moves on to anything else.
Session
A persistent multi-turn conversation over one AgentLoop.
StuckPolicy
Governs the loop’s stuck-detector. When the model repeats the same tool call (name + args) round after round without making progress, the loop first nudges it to change approach, then terminates cleanly with Outcome::Stuck rather than burning the rest of the budget spinning on a loop.
ToolResultPolicy
A ceiling on how much of one tool result reaches the context.

Enums§

Outcome
Where a run finished. Each variant is #[non_exhaustive] so new fields don’t break downstream matches — always include .. when destructuring.

Functions§

apply_patches
Apply auto-fix patches; return short descriptions of those that succeeded.
is_default_safe_fix
Audit #7: default safelist for FixPatch::RunCommand.