Your agent prompts are too long. You know it. The model knows it. Your token bill knows it.

A team from the National University of Singapore and Sapiens AI agrees. Their new paper, CodeAgents, proposes a simple idea with big consequences: replace verbose natural language prompts with compact, code-like instructions.

The results are hard to argue with. Planning accuracy goes up. Token usage goes down. Multi-agent coordination gets cleaner.

The Problem

Most agent prompting today follows the same pattern. You write a paragraph of natural language explaining what the agent should do. The agent writes a paragraph back explaining its plan. Then another paragraph for each step. Multiply this across multiple agents and you get a token explosion.

Chain-of-Thought, ReAct, and Tree-of-Thoughts all helped. But they share a flaw. They use natural language as the reasoning medium. Natural language is verbose. It is ambiguous. It does not have control flow. You cannot write an if statement in English without spending 30 tokens on it.

The CodeAgents team identified three specific problems with current approaches:

  • Reasoning traces are too long, burning tokens and adding latency
  • Combining planner, solver, and verifier roles in one prompt sequence causes errors to compound
  • Existing methods ignore token cost as a metric, optimizing only for task success

The Idea

CodeAgents treats a reasoning task like a program. Instead of describing a plan in prose, the agent writes it as structured pseudocode. Typed variables. Loops. Conditionals. Assertions. Function calls with arguments.

Here is what a codified plan looks like for a simple task:

def initial_plan_for_eat_bread_on_sofa():
    # Step 1: Locate sofa and bread
    walk('livingroom')
    find('sofa')
    # Step 2: Pick up the bread
    assert('close' to 'bread')
    else: find('bread')
    grab('bread')
    # Step 3: Sit on the sofa
    sit('sofa')
    # Step 4: Eat the bread
    eat('bread')

That is the entire plan. No paragraphs. No "I will now walk to the living room and look for the sofa." Just the steps, the preconditions, and the recovery logic.

The framework codifies everything. Task definitions. Plans. Feedback. System roles. Tool invocations. All of it becomes modular pseudocode with typed variables and control structures.

Multi-Agent Architecture

CodeAgents supports both single-agent and multi-agent configurations. The multi-agent version splits work across three specialized roles:

  • Planner: generates high-level pseudocode plans from user instructions
  • ToolCaller: executes plan steps and invokes external tools
  • Replanner: receives structured error feedback and regenerates failed sub-plans

Agents communicate through pseudocode messages. Not natural language. Not free-form text. Structured, typed, code-like messages that leave no room for ambiguity.

Each agent gets a codified system prompt in YAML format. The prompt declares the agent's role, available tools, teammate agents, and execution cycle. This makes the prompts modular and reusable.

When something goes wrong, the system does not write a paragraph about what happened. It generates a structured diagnostic trace containing the failed step, error type, and current state. The Replanner reads this trace and produces an updated sub-plan. Clean. Fast. Token-efficient.

The Numbers

The team tested CodeAgents on three benchmarks: GAIA, HotpotQA, and VirtualHome. They ran it across multiple LLMs. The results are consistent.

Planning performance:

  • Absolute gains of 3 to 36 percentage points over natural language baselines
  • On VirtualHome, CodeAgents hit a 56% success rate, a new state-of-the-art for that benchmark

Token efficiency:

  • Input token usage dropped 55 to 87%
  • Output token usage dropped 41 to 70%

Think about that for a second. You cut input tokens by up to 87% and your planning quality goes up. Not down. Up. You are paying less and getting more.

Why It Works

Code-like instructions carry more information per token than natural language. A single assert() statement encodes a precondition check that would take a full sentence to describe in English. A for loop encodes iteration without explaining what iteration is. Typed variables eliminate ambiguity about what kind of data flows between steps.

The structure also helps the model. LLMs have seen millions of lines of code during training. They understand code patterns well. Giving them a code-like scaffold plays to their strengths. The model fills in a function body rather than generating free-form reasoning from scratch.

Error handling improves too. When an assertion fails, the system knows exactly which step broke and why. It can retry locally or escalate to replanning. No need to parse a natural language error description and guess what went wrong.

What This Means for Agent Design

The implications go beyond prompt engineering.

First, token cost becomes a design metric, not an afterthought. If you are building production agent systems, you care about cost per task. CodeAgents shows you can optimize for tokens and accuracy at the same time. They are not in conflict.

Second, multi-agent coordination gets more tractable. One of the hardest problems in multi-agent systems is communication overhead. Agents need to share state, plans, and results. Doing this in natural language is expensive and lossy. Doing it in code-like messages is compact and precise.

Third, debugging becomes possible. When a plan is structured pseudocode, you can trace failures to specific steps. You can inspect variable states. You can replay the execution. Natural language reasoning traces resist this kind of analysis.

Limitations

The code repository is currently hosted on anonymous.4open.science, which suggests the authors may be pursuing double-blind review. The paper has zero citations as of July 2025, so it is early days.

The benchmarks tested are simulation and QA tasks. GAIA tests general assistant capabilities. HotpotQA tests multi-hop question answering. VirtualHome tests household task planning. Real-world deployment on messier tasks like code generation or web automation remains untested.

The approach also assumes the underlying LLM can produce reliable pseudocode. Smaller models may struggle with the structured output format. The paper does not report results on models below a certain size threshold.

The Bigger Picture

The agent community has been pouring effort into making natural language prompts better. Better templates. Better few-shot examples. Better chain-of-thought variants. CodeAgents suggests a different direction entirely.

Stop writing better prose. Write code instead.

The token savings alone justify the shift. A 70% reduction in output tokens means 70% lower API costs for the reasoning portion of your pipeline. The accuracy gains are a bonus on top.

For anyone building multi-agent systems, this paper points toward a concrete design pattern: codify your agent communication, use typed pseudocode for plans, build assertion checks into your execution loop, and treat token efficiency as a first-class metric.

The full paper is available at arXiv:2507.03254. Code is at anonymous.4open.science/r/CodifyingAgent-5A86.


Authors: Bruce Yang, Xinfeng He, Huan Gao, Yifan Cao, Xiaofan Li, David Hsu. National University of Singapore, Southeast University, Sapiens AI. Published July 4, 2025.