Metaprise Agent OS v4.2 — Harness protection layer now built into every plan. Read the changelog →
Platform Cloud Hybrid Enterprise Six Engines Orchestration Observability Harness Metaprise LLM
FREE WITH EVERY PLAN

Agent Harness

Five protection layers that guard context health, prevent execution loops, and enforce completion quality — so your agents stay sharp through even the longest-running missions.

PROTECTION STACK — 5 LAYERS
01
Context Summarization Memory
02
Loop Detection Middleware Guard
03
Pre-Completion Checklist Quality
04
Virtual Filesystem Backend Storage
05
Lifecycle Hooks Middleware
ALWAYS ON · ZERO CONFIG · EVERY AGENT
5
Protection Layers
0
Token Waste
Runtime Duration
$0
Extra Cost

Five layers that keep agents healthy

Long-running agents degrade — context windows fill up, execution loops form, and outputs drift from the original task. Harness prevents all of it, automatically.

01

Context Summarization

Prevent context window pollution

Automatic context compression that preserves critical information while freeing token budget. Your agents stay focused and coherent across hundreds of steps without losing important details.

Long Tasks Token Savings Coherence
02

Loop Detection Middleware

Break infinite cycles automatically

Tracks edit counts per file and per operation. When an agent exceeds N iterations on the same resource, Harness intervenes — escalating to a human, switching strategy, or halting gracefully.

Loop Break Cost Guard Escalation
03

Pre-Completion Checklist

Validate before you ship

Forces the agent to validate its output against the original task specification before marking a mission complete. No silent failures, no partial deliveries, no drift from requirements.

Quality Gate Spec Match Completeness
04

Virtual Filesystem Backend

Offload data, save tokens

Offloads tool results and intermediate files to persistent storage rather than keeping them in the context window. Agents reference stored artifacts by pointer — not by consuming tokens.

Token Offload Artifacts Persistence
05

Lifecycle Hooks (Before / After)

Pluggable middleware at every stage

Pluggable middleware triggered before agent start, after completion, and around every tool call. Inject logging, validation, cost controls, compliance checks — anything your workflow requires.

Middleware Extensible Compliance

DEEP DIVE 01

Context Summarization

Agents running 50+ step missions accumulate massive context. Without compression, they lose coherence, hallucinate, or fail silently. Context Summarization keeps your agents sharp by compressing stale context while preserving every critical detail.

HOW IT WORKS

Rolling Compression: As the context window fills, older conversation turns are automatically summarized into compact representations that preserve key decisions, data, and constraints
Importance Scoring: Each context segment is scored for relevance to the current task — high-value information (business rules, constraints, user requirements) is preserved in full, low-value information (verbose tool outputs) is compressed aggressively
Lossless Pointers: When full content is compressed, a pointer to the Virtual Filesystem copy is retained — the agent can request the original if needed
Adaptive Thresholds: Compression triggers are tuned per model and per context window size, ensuring optimal token utilization across GPT-4o, Claude, Llama, and other models

IMPACT

Up to 70% reduction in token consumption for missions exceeding 100 steps
Consistent output quality regardless of mission length
Eliminates "context amnesia" — the failure mode where agents forget earlier instructions

DEEP DIVE 02

Loop Detection Middleware

Infinite loops are the most expensive failure mode in agentic systems. An agent stuck retrying a failing API call or endlessly editing the same file can burn through thousands of dollars in tokens with no useful output. Loop Detection stops this before it starts.

DETECTION MECHANISMS

Per-File Edit Tracking: Counts how many times each file or resource has been modified — intervenes after a configurable threshold (default: 5 edits)
Output Similarity Analysis: Detects when consecutive outputs are semantically identical or near-identical, indicating the agent is stuck repeating itself
Cost Velocity Monitoring: Tracks token spend per unit of progress — a spike in cost without corresponding task advancement triggers an alert
Circular Dependency Detection: Identifies when agent A calls agent B, which calls agent C, which calls agent A — breaking multi-agent deadlocks

INTERVENTION STRATEGIES

Strategy Switch: Automatically change the orchestration architecture (e.g., from ReAct to Plan-and-Execute) to break the pattern
Human Escalation: Route to the Annotation Queue for human review when automated intervention fails
Graceful Halt: Stop the mission with a detailed report of what was attempted and where it got stuck

DEEP DIVE 03

Lifecycle Hooks

The extensibility layer of Harness. Lifecycle Hooks let you inject custom logic at every stage of agent execution — before start, around each tool call, and after completion. Build compliance, logging, cost controls, and custom validation without modifying agent code.

HOOK TYPES

before_start: Runs before the agent begins execution — validate inputs, check quotas, load configuration, enforce business hours
around_tool_call: Wraps every tool invocation — add logging, enforce rate limits, mask PII in tool inputs/outputs, apply cost ceilings
after_completion: Runs after the mission completes — audit trail generation, notification dispatch, cleanup, billing event emission
on_error: Triggered on any unhandled error — custom retry logic, fallback strategies, incident creation

MIDDLEWARE CHAIN

Hooks execute in a defined order — each can modify, pass through, or reject the request
Compose multiple hooks into a middleware chain (e.g., Auth → Rate Limit → PII Mask → Log → Execute)
Built-in hooks provided for common patterns — custom hooks via SDK or Dashboard configuration
Hook execution time tracked in Observability traces for performance monitoring

How Harness protects every mission

From the moment a mission starts to the moment it completes, Harness wraps every step in a protection pipeline — automatically, with zero configuration required.

01
Mission Start
Hook: before_start
02
Context Check
Compress if needed
03
Tool Execution
Hook: around_tool
04
Loop Check
Detect & intervene
05
FS Offload
Store artifacts
06
Checklist
Validate vs. spec
07
Complete
Hook: after_done

When Harness makes the difference

Every agent benefits from Harness, but these are the scenarios where protection layers become mission-critical.

Long-Running Analysis
"Analyze 500 pages of legal contracts and extract all risk clauses."

Context Summarization keeps the agent coherent across hundreds of pages. Virtual FS stores extracted clauses without consuming tokens. Pre-Completion Checklist ensures every contract was processed.

→ Context Summarization + Virtual FS
Iterative Code Generation
"Build a full-stack feature with tests, then fix any failures."

Loop Detection prevents the agent from endlessly editing the same file. If it retries a failing test 5 times, Harness intervenes — switching strategy or escalating to a human reviewer.

→ Loop Detection + Lifecycle Hooks
Compliance Workflow
"Review all transactions against our AML policy and flag violations."

Lifecycle Hooks inject compliance checks around every tool call. The before_start hook validates authorization. The Pre-Completion Checklist ensures all transactions were reviewed — not just most.

→ Lifecycle Hooks + Pre-Completion
Multi-Step Data Pipeline
"ETL 10 data sources, transform, validate, and load into the warehouse."

Virtual FS offloads intermediate datasets to storage instead of keeping them in context. Context Summarization preserves the pipeline state while freeing tokens for the next transformation step.

→ Virtual FS + Context Summarization
Multi-Agent Collaboration
"5 specialized agents working together on a research report."

Loop Detection catches circular delegation between agents. Lifecycle Hooks log every inter-agent handoff for audit. Pre-Completion Checklist validates the final assembled report against all section requirements.

→ Loop Detection + Lifecycle Hooks
24/7 Automation
"Monitor support tickets, classify, route, and draft responses continuously."

Context Summarization prevents context decay over hours of continuous operation. Loop Detection catches agents stuck retrying unreachable APIs. Lifecycle Hooks enforce rate limits and cost ceilings.

→ All 5 Layers Active

Always on, zero configuration: Every Harness protection layer activates automatically for every agent on every plan. No setup required, no extra cost. Thresholds are pre-tuned for production — customize them via the Dashboard or SDK when you need finer control.

Let your agents run longer, safer, and smarter.

Five protection layers, always on, always free. Included with every Metaprise plan.