LLM-as-Code: Agentic Programming for Agent Harness

Junjia Qi, Zichuan Fu, Jingtong Gao, Wenlin Zhang, Hanyu Yan, Xian Wu, Xiangyu ZhaoarXiv 2026

TL;DR

Current LLM agent frameworks frequently suffer from control-flow hallucinations and token explosion because they mistakenly use probabilistic models to orchestrate deterministic logic. This paper introduces Agentic Programming (LLM-as-Code), a paradigm where traditional code governs the control flow and the LLM is treated as a scoped, functional component, drastically improving reliability and context efficiency.

What Problem Does This Paper Address?

Most mainstream LLM agent frameworks rely on the "Reason-and-Act" (ReAct) loop, where the LLM acts as the central orchestrator. The model itself decides what tool to call next, tracks its own progress, and determines when a task is complete.

While this works well for short, simple demonstrations, the authors argue it fundamentally breaks down during long-horizon tasks (such as multi-file code refactoring). This architectural flaw manifests as three major symptoms:

  1. Token Explosion: The context window grows monotonically with every step because the model must re-read its entire execution history to figure out "where it is" in the task.
  2. Control-Flow Hallucination: The model skips critical steps or prematurely declares a task resolved before running necessary verifications.
  3. Unreliable Completion: The model easily gets distracted by recent errors and abandons a correct path because there are no hard constraints guaranteeing execution order.

The authors point out that this is a category error: we are assigning deterministic work (looping, branching, sequencing) to a probabilistic system.

Methods

The authors propose Agentic Programming, a paradigm that strips the LLM of its orchestrator status and returns control flow to the program runtime.

Figure 1: A comparison of the two agent paradigms on a simple multi-step task. In the left panel (LLM-as-Orchestrator) the LLM drives the loop itself. In the right panel (LLM-as-Code) code owns the loop and the LLM is called only to summarize.

The framework consists of four core pillars:

  • Code-Driven Workflow: Control flow is written in standard code (e.g., Python for loops and if statements). The LLM is invoked only at specific leaf nodes requiring reasoning or text generation using a simple @agentic function decorator.
  • DAG-Structured Context: Instead of a flat, ever-growing conversation log, the execution history mirrors a standard programming call tree (a Directed Acyclic Graph). When an LLM sub-function returns, its detailed prompt history is cleared from the active stack, leaving behind only a concise summary for the parent function. This bounds the context length by call depth $O(\text{depth})$ rather than total steps $O(\text{steps})$.
  • Multi-Agent Collaboration: Agents interact via typed return values rather than free-form chat. This allows independent model invocations to run concurrently and fail gracefully without corrupting a shared global context.
  • Self-Programmed Evolution: When the agent attempts to optimize or modify its own functions, the proposed changes are treated as code modifications. They are only committed if they pass deterministic unit tests, ensuring that self-improvement is durable and reliable.

Datasets

The authors evaluated their approach on OSWorld, a unified, multimodal benchmark designed to evaluate agents on open-ended tasks in real computer environments (including operating systems, web browsers like Chrome, and multi-app workflows).

Key Insights and Ideas

  • Stop Prompting Loops: If you need a task done eight times, use a literal for i in range(8): loop in code. Forcing an LLM to count and track its iterations via prompting is an unnecessary gamble.
  • Context as a Call Stack: By treating context like function-call memory, the system automatically prunes irrelevant intermediate reasoning steps upon function return. This elegantly solves the "lost in the middle" phenomenon where LLMs degrade in performance when fed massive contexts.
  • Reliability by Construction: Moving constraints out of the prompt and into the code runtime ensures compliance. A rule is no longer something the model is "coached" to follow; it is enforced by the language runtime.

Key Results

The LLM-as-Code approach was paired with Claude Sonnet 4.6 and evaluated against several state-of-the-art agent frameworks on the OSWorld benchmark:

  • Superior Success Rate: LLM-as-Code achieved an 86.8% overall success rate, outperforming the strongest specialized baseline framework (Holo3-35B-A3B at 80.4%).
  • Extreme Step Efficiency: While baseline frameworks were allotted up to 100 steps to complete tasks (and often burned through them due to loop hallucinations), the LLM-as-Code agent completed its tasks in a maximum of 15 steps.
  • Domain Breakthroughs: The proposed method achieved a perfect 100% success rate in the OS domain and significantly raised the bar in the Chrome (93.5%) and Multi-Apps (80.0%) categories.

Limitations and Future Work

  • Not for Unstructured Exploration: The authors acknowledge that Agentic Programming is not intended for entirely open-ended, unstructured tasks (e.g., free-form brainstorming or open-ended research) where a fixed stage model or workflow structure does not exist.
  • Workflow Specification Overhead: This approach requires software engineers to explicitly design and code the structural skeleton of the workflow beforehand, trading away the "one-prompt-does-all" simplicity of pure ReAct agents for deterministic reliability.

Summary updated

BibTeX
@misc{qi2026llm,
  author = {Junjia Qi and Zichuan Fu and Jingtong Gao and Wenlin Zhang and Hanyu Yan and Xian Wu and Xiangyu Zhao},
  title = {{LLM-as-Code: Agentic Programming for Agent Harness}},
  year = {2026},
  eprint = {2606.15874},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2606.15874},
}

Loading related content...

Figure