Files

106 lines
5.6 KiB
TeX

\section{Introduction}
\label{sec:intro}
The promise of autonomous coding agents that improve with use has attracted
substantial research attention~\cite{shinn2023reflexion, wang2023voyager,
wang2024openhands, wu2023autogen}. The intuition is appealing: an agent that
can identify its own weaknesses and fix them should, over time, require less
human supervision and handle more complex tasks. Yet in practice, deployed
agents rarely exhibit reliable self-improvement, and the mechanisms proposed
in the literature frequently fail to transfer to production settings.
We argue that most existing approaches share a fundamental design flaw: they
rely on LLMs to accurately evaluate their own performance and decide when
improvement is warranted. This creates a circularity problem. The same model
whose behavior we wish to improve is asked to judge whether that behavior is
deficient---and to do so using the same context window that the deficient
behavior just consumed.
\paragraph{The Context Window Problem.}
A typical coding session accumulates thousands of tokens of interaction history.
After a long session, the agent's context window contains a dense mixture of
task descriptions, tool outputs, intermediate reasoning, code diffs, error
messages, and conversational repairs. When asked to reflect on ``what went
wrong,'' the LLM must process this entire narrative to produce a summary.
Information theory tells us this is lossy: any fixed-length summary of an
arbitrary-length sequence discards information. More practically, the
patterns most relevant to self-improvement---repeated tool failures, systematic
error modes, recurring user corrections---are precisely the patterns that
are most diluted by narrative summaries because they are distributed across
many non-contiguous tokens.
\paragraph{The Self-Evaluation Problem.}
Beyond lossy summarization, LLMs are systematically miscalibrated self-evaluators
during task execution~\cite{guo2017calibration, kadavath2022language}. An agent
engaged in a complex coding task allocates its attention to the task, not to
meta-level monitoring. When subsequently prompted to reflect, it exhibits
well-documented biases: recency bias (over-weighting the last few turns),
sycophancy (avoiding negative self-assessments that conflict with task
completion), and confabulation (generating plausible-sounding but inaccurate
retrospectives).
\paragraph{The Telemetry Thesis.}
We propose a different foundation. Every tool invocation produces a small,
structured, machine-readable record: which tool was called, with what arguments,
what the outcome was, and how long it took. These records are appended to a
JSONL log independently of the agent's context window. They are never
summarized, never compressed by the LLM, and never lost to attention decay.
They accumulate silently and are available for deterministic analysis at any
time. We call this the \emph{telemetry thesis}: immutable structured data about
tool invocations is a superior substrate for self-improvement than narrative
summaries of those invocations.
\paragraph{The Build-It-Now Protocol.}
A second failure mode of existing systems is deferral. When an agent notices a
recurring problem, it has two choices: fix it now, or record it for later. Every
system that records problems for later produces growing backlogs of
\texttt{OPPORTUNITIES.md} files that are never acted upon. We propose instead
the \emph{Build-It-Now} (BIN) protocol: when a deterministic trigger fires
(three identical failure modes in one session), the agent pauses its current
task, builds a targeted micro-tool to eliminate the friction, tests it, and
resumes. No backlog. No deferral. No aspirational documentation.
\paragraph{Contributions.}
This paper makes the following contributions:
\begin{enumerate}[leftmargin=1.5em]
\item \textbf{4-Loop Architecture:} A formal description of four
self-improvement loops operating at distinct timescales, with
precise trigger conditions, latency bounds, and interaction semantics
(Section~\ref{sec:architecture}).
\item \textbf{Build-It-Now Protocol:} An anti-deferral mechanism with a
formal algorithm (FRICTION-DETECT) and a multi-stage build pipeline
that guarantees atomic rollback on failure
(Section~\ref{sec:loop1}).
\item \textbf{Formal Analysis:} Convergence guarantees for the
trigger-based update rule, an information-theoretic bound on
telemetry entropy vs.\ narrative entropy, and a precision/recall
analysis of deterministic vs.\ LLM-based trigger detection
(Section~\ref{sec:analysis}).
\item \textbf{Anti-Pattern Catalog:} A systematic enumeration of the
design anti-patterns that the 4-Loop Architecture is engineered to
prevent (Section~\ref{sec:antipatterns}).
\item \textbf{Implementation:} A production TypeScript implementation
as a Hanzo bot plugin with full telemetry service, friction
detector, and active learning hooks (Section~\ref{sec:implementation}).
\end{enumerate}
\paragraph{Paper Outline.}
Section~\ref{sec:related} reviews related work.
Section~\ref{sec:architecture} presents the 4-Loop Architecture.
Section~\ref{sec:loop0} through Section~\ref{sec:loop4} detail each loop.
Section~\ref{sec:analysis} provides formal analysis.
Section~\ref{sec:antipatterns} catalogs anti-patterns.
Section~\ref{sec:implementation} describes the implementation.
Section~\ref{sec:evaluation} presents evaluation results.
Section~\ref{sec:discussion} discusses future directions.
% ============================================================================
% 2. RELATED WORK
% ============================================================================