Self-Improving AI Agent Harnesses: Change Logs and Prompt Injection Defense
An AI agent’s harness—the prompts, tool policies, workflows, and memory surrounding its model—can improve without retraining the model itself. This article explains how to build a feedback-driven improvement loop, preserve useful experience in auditable change logs, avoid reward hacking, and incorporate prompt injection defenses, permission checks, and rollback into every release.
1. Understanding the Harness: The Programmable Layer Around the Model
In an AI application, the model is often treated as the “brain,” responsible for understanding and generation. But a programmable layer outside the model determines how it operates. This layer includes system prompts, tool-calling rules, workflow orchestration, retrieval strategies, output validation, and memory and note-taking mechanisms. Together, these components form the AI agent’s harness.
Changing the harness around the same model can substantially affect task completion, tool-use accuracy, cost, and latency.
Harness self-improvement does not directly modify model parameters. Instead, it uses task feedback to adjust prompts, tool-selection rules, and workflow steps automatically. This offers two immediate benefits: adaptation to new tasks without retraining, and improvement records that can be versioned, audited, and transferred.
However, the harness amplifies both capabilities and risks. The more permissions its tools have and the more external content it can read, the greater the consequences of manipulation or misuse.
2. The Improvement Loop: Execution, Evaluation, Revision, and Memory
A practical harness self-improvement loop typically has five stages:
- Task execution: An execution model uses the current harness to complete office-productivity, retrieval, data-processing, or similar tasks.
- Result evaluation: Rule-based scorers, model-based evaluators, or human spot checks provide feedback.
- Harness revision: Failures inform changes to prompts, tool allowlists, parameter constraints, or workflow branches.
- Memory recording: A change log captures what changed, why it changed, what it was expected to fix, and what actually happened.
- Regression validation: The revised harness is tested against held-out tasks and security cases. Passing versions are released; failed changes are rolled back.
A public preprint described an experiment with two phases: role-separated improvement and same-model self-improvement. In the first phase, one model executed tasks while another revised the harness over successive rounds. In the second, the same model handled both execution and revision.
For office-productivity tasks, continued improvement with change logs achieved a score of 84.75. Continuing with only the improved harness, without the logs, scored 73.42. Starting improvement from scratch scored 82.98. The experiment also noted that, outside coding tasks, some domains had only one run per strategy. These scores should therefore be treated as directional evidence rather than stable conclusions.
The central lesson is that a final configuration is not the same as accumulated experience. If a system retains only the improved harness, it knows what to do but not why those choices were made. When the task distribution changes, it has less evidence to guide further adjustments.
Change logs preserve hypotheses, failure causes, and measured outcomes, allowing subsequent improvements to build on earlier work. Starting from scratch may also uncover effective approaches, but it repeats trial and error at greater cost and with more variable results.
3. Why Change Logs Matter More Than the Final Configuration Alone
A harness change log is an auditable memory of improvement. At minimum, it should record the change identifier, baseline version, changes made, underlying hypothesis, expected impact, measured results, side effects, security review, and rollback point.
An illustrative record might look like this:
{"change_id": "shell-2026-001","baseline": "v12","target": "v13","hypothesis": "Labeling external document content as untrusted can reduce the risk of unintended execution","expected_impact": ["Reduce the rate of successful prompt injection","Maintain task completion rate"],"observed_metrics": {"task_score": 0.8475,"security_pass_rate": 0.96,"latency_delta": "+3%"},"side_effects": ["Slightly longer summaries of long documents"],"security_review": "passed","rollback": "v12"}
This structure provides three engineering benefits:
- Traceability: When a regression occurs, teams can identify the change that introduced it.
- Transferability: Experience can remain useful after a model replacement. It must still be revalidated so that preferences specific to the old model are not mistaken for general rules.
- Resistance to overfitting: Recording failed hypotheses and counterexamples helps prevent subsequent optimization from revolving entirely around one scorer.
Logs also introduce risks: memory growth, incorrect causal attribution, context contamination, and even injection into the logs themselves. They therefore need versioning, structured formats, access controls, and content sanitization and signature verification before entries are accepted.
4. Reward Hacking: When Better Scores Hide Worse Behavior
A subtle failure mode in self-improving systems is confusing a higher score with a better outcome. When the evaluator is fixed and the examples are limited, the harness may learn to cater to the evaluator by adding keywords, bypassing necessary steps, hiding failures, or selecting paths that are easy to present favorably.
This reward-hacking behavior may be difficult to notice in a single experiment but become more consequential in production.
The answer is not to abandon automated scoring. It is to use multiple evaluation layers:
- Held-out datasets and out-of-distribution tests
- Cross-checks across multiple evaluators
- Adversarial test cases
- Human spot checks
- Production business metrics
- Cost, latency, and security constraints
Every harness change should pass release gates: task scores must not decline, security tests must pass, tool permissions must not expand, and rollback must remain available.
Self-improving systems should also record the evaluator version. Otherwise, a change in scoring criteria may be mistaken for an improvement in capability.
5. Prompt Injection: A More Capable Harness Has a Larger Attack Surface
The core prompt injection problem is that a model does not inherently distinguish reliably between system instructions and external content it reads.
Hidden webpage text, white-on-white document text, email bodies, calendar descriptions, PDF layers, and image OCR results can all carry malicious instructions. As the harness gains the ability to read more content, call more tools, and issue more requests, the cost of a single misclassification increases.
Public tests and security research repeatedly indicate that an individual injection attempt may have a low success rate, while risk accumulates across many variations. Specific vulnerabilities can be patched, but complete immunity is difficult to establish.
Representative risks include:
- External content causing an automated reply system to send unauthorized emails
- Hidden text influencing an evaluation result
- Calendar invitations triggering smart-home actions
- Email content inducing an agent to transmit inbox information externally
These failures do not require a model to act maliciously. They arise when instructions and data are treated as equivalent within the same context.
Treat External Content as Untrusted Data
External content should be handled as data, not as authority to issue commands.
System prompts should explicitly state that external content is reference material only and must not change the task objective or authorize sensitive tool use. Before content enters the context, processing should address invisible characters, hidden text, and anomalous encodings.
Before a tool call executes, a policy engine should validate its parameters, target, and permissions. Sensitive actions require explicit confirmation.
An illustrative policy is:
tool_policy:default: denyallow:- read_public_document- summarize_textrequire_confirmation:- send_external_message- modify_calendar- access_private_dataconstraints:- external_content_must_be_labeled_untrusted: true- sensitive_operation_requires_human_approval: true- network_egress_allowlist_only: true
6. A Secure Improvement Loop: Making Change Logs an Auditable Asset
Harness self-improvement should optimize more than task scores. Security evaluation must be part of the same feedback loop.
Each change should answer four questions:
- Does it expand tool permissions?
- Does it introduce a new entry point for external content?
- Does it alter confirmation rules for sensitive operations?
- Could it allow improvement logs to become contaminated?
Before release, validation should include prompt injection regression tests, permission-difference checks, audit-log verification, and rollback drills.
The long-term value of harness self-improvement is the ability to replace the model while retaining useful experience. Models can change while prompts, tool specifications, workflows, and improvement records remain reusable assets. But that experience must be checked for bias, verifiable, and reversible.
Place change logs under version control and connect them with standard cloud components such as logging services, monitoring and alerting, secrets management, and policy engines. Together, these components support an auditable improvement process.
The goal is not unlimited autonomous modification. It is to ensure that every revision happens within explicit boundaries: capabilities can improve, permissions remain constrained, experience stays reusable, and failures remain containable.
