Apply to my task
arXiv:2507.03254 ★ 79 Jul 4, 2025

CodeAgents: pseudocode instead of a prompt. More accurate and many times cheaper in tokens

Key result

The paradox: a "language" model works more accurately when you talk to it like a programmer rather than like a person. CodeAgents lets you frame any complex request as a pseudo-program, with functions, variables and comments, and get a structured result without the logic leaking between steps. The trick: comments (#) inside the pseudocode work as a built-in chain of thought: the model understands not just what to do but why. It stops interpreting your intent and starts executing an algorithm. The upshot: fewer errors, fewer tokens, more accuracy.

CodeAgents: A Token-Efficient Framework for Codified Multi-Agent Reasoning inLLMs

Key Aspects of the Research:

The study shows that replacing ordinary text prompts with structured instructions in the form of pseudocode dramatically improves LLM efficiency and accuracy. Instead of describing the task in free form, you present it as a program with clear steps, variables and comments. This helps the model grasp the logic better, avoid mistakes and use far fewer tokens.

Key Result: Structuring a prompt as pseudocode makes the LLM more accurate and many times more economical.


The Core of the Method, Explained:

The essence of CodeAgents is to stop talking to an LLM like a person and start giving it instructions like a computer. Instead of writing "I want you to analyze the market and suggest ideas", you phrase the request as a program the model has to "execute".

For the user, the method boils down to this:

  1. Wrap the task in a "function": Start the prompt by defining a pseudo-function, for example def create_marketing_strategy(product, audience):. That immediately sets a clear goal and parameters.
  2. Break the task into logical steps: Instead of a wall of text, list the sequential actions to be performed.
  3. Use comments to explain: Before each step, add a comment (with #) explaining the purpose of that step. For the LLM this acts as an analog of "thinking out loud" (Chain-of-Thought), steering its reasoning in the right direction.
  4. Use "variables": Give names to intermediate results. For example, analysis_results = analyze_competitors(...), and then use analysis_results in the next step. This helps the model keep context and the logical thread.

This approach forces the user to think through the task's logic in advance, and the model to follow that logic without straying. The result: fewer errors, more relevant answers and, as a bonus, a sharp cut in "verbal clutter", which saves tokens and money.


Practical Applicability:

  • Direct applicability: Very high. Any user can immediately start structuring their prompts as pseudocode in any chatbot (ChatGPT, Claude, etc.). No special tools needed. Just change the format of your request using def constructs, # comments and step-by-step instructions.

  • Conceptual value: Huge. The study delivers a key idea: an LLM is not a conversation partner but a program executor. Understanding this changes how you prompt. The user stops thinking "how do I explain this more clearly?" and starts thinking "what algorithm leads to the result I need?". It drives home that, for an LLM, precision and structure matter more than politeness and nice phrasing.

  • Adaptation potential: Maximum. The complex multi-agent system from the paper adapts easily to a single user. When writing pseudocode in the prompt, the user simply plays the "Planner" role themselves. The LLM acts as the "Executor". The adaptation is a simplification: instead of real code and API calls, you use pseudocode and simple commands the LLM understands.


A Practical Example:

You are an experienced social media strategist. Your task is to create a content plan for a new blog about traveling light (minimalist travel).

Follow the algorithm below, written as pseudocode, to the letter. The comments (`#`) explain the purpose of each step.
python

def createcontentplan(topic="traveling light", platform="Instagram", goal="attract followers"): # Step 1: Identify and analyze the target audience. # Figure out who these people are, what they care about and what content they prefer. targetaudience = analyzeaudience(platform, topic)

# Step 2: Generate 3 key content pillars (themes).
# The pillars should be based on the audience's interests and cover the main topic.
content_pillars = generate_pillars(target_audience, goal, count=3)

# Step 3: For each pillar, come up with 4 specific post ideas.
# The ideas should be practical, inspiring or educational.
post_ideas = generate_post_ideas_for_each_pillar(content_pillars, count_per_pillar=4)

# Step 4: Put everything into a single plan and present it as a table.
# The table should have columns: "Pillar", "Post idea", "Format (Reels/Post/Stories)".
final_plan = format_as_markdown_table(post_ideas)

# Step 5: Output the final result.
final_answer(final_plan)

Why It Works:

This prompt is effective because it uses the key mechanics from the study:

  1. Structural decomposition: The task is broken into clear, sequential steps (analyze_audience, generate_pillars, etc.). This keeps the LLM from "losing its way" or skipping an important stage, as often happens with a solid block of text.
  2. Pseudocode as scaffolding: The def function(...) format and the pseudo-function calls give the LLM a rigid logical structure. The model understands that the output of step 1 (target_audience) is the input for step 2.
  3. Comments as an inner monologue: Lines starting with # act as guiding thoughts for the LLM. They explain why each step is needed, which improves how well that step gets done. For example, the comment # Figure out who these people are... gives the model extra context for analyze_audience.
  4. Less ambiguity: Instead of "come up with something for Instagram", we issue the command generate_post_ideas_for_each_pillar(content_pillars, count_per_pillar=4), which leaves no room for misinterpretation.

Another Practical Example

You are an experienced financial advisor. Your task is to put together a personal plan for me to get out of debt and start saving.

Use the following codified approach for this. Complete each step in order.
python

def createpersonalfinanceplan(monthlyincome=5000, totaldebt=12500, monthlyexpenses=3500): # Step 1: Calculate free cash flow. # This is the difference between income and essential expenses. freecashflow = calculatecashflow(monthlyincome, monthlyexpenses)

# Step 2: Propose a debt repayment strategy.
# Consider two methods: "Snowball" (smallest debt to largest) and "Avalanche" (highest interest rate to lowest).
# Recommend one of them based on the inputs.
debt_repayment_strategy = suggest_debt_strategy(total_debt, free_cash_flow, methods=["snowball", "avalanche"])

# Step 3: Draw up a plan for building an emergency fund.
# The goal is to save an amount equal to 3-6 months of expenses.
# Calculate how much to set aside each month.
emergency_fund_plan = create_emergency_fund_plan(monthly_expenses, free_cash_flow)

# Step 4: Put together the final document.
# The plan should be presented in clear sections:
# 1. Analysis of the current situation.
# 2. Debt repayment strategy (with calculations).
# 3. Emergency fund savings plan.
final_document = format_as_structured_report(debt_repayment_strategy, emergency_fund_plan)

# Step 5: Output the final result.
final_answer(final_document)

Why This Example Works: the Mechanism

This example works on the same principles, just in a different context:

  1. Enforced logic: The prompt makes the LLM calculate free_cash_flow first, and only then use that value to plan debt repayment and savings. That rules out illogical or mathematically wrong suggestions.
  2. Managing complexity: The complex task "create a financial plan" is broken into manageable subtasks. The LLM doesn't try to solve everything at once; it focuses on each step separately, which improves the quality of each one.
  3. Explicitly defined variables: Specifying the inputs (monthly_income, total_debt) as function arguments makes the request parameterized and easy to adapt. The user can just change the numbers without rewriting the whole logic.
  4. Control over the result: The command format_as_structured_report(...) tells the model directly what output format you want, making a well-structured, readable answer more likely than a solid stream of text.

Usefulness Score: 90

02

Main Evaluation Criteria

  • A. Relevance to prompting techniques: Very high. The study directly proposes a new framework, "CodeAgents", for structuring prompts as pseudocode, which is a fundamental prompting technique.
  • B. Better conversational answers: Very high. The results show a significant gain in accuracy (up to 36 percentage points) and success rate (SR) on complex tasks.
  • C. Direct practical applicability: High (with a caveat). Although the full framework with multiple agents and YAML configuration is complex for a regular user, the core principle, structuring a prompt as pseudocode, is extremely practical and can be applied immediately in any chatbot with no code or tools.
  • D. Conceptual value: Very high. The study gives the user a powerful mental model: "treat the LLM not as a conversation partner but as a code interpreter". It clearly shows why verbosity hurts while structure and logic help.
  • E. New useful practice (clustering): The work fits several key clusters at once:
    • 1. Prompt formulation techniques: Offers a whole approach of "codified prompting".
    • 2. LLM behavioral patterns: Shows that LLMs work much more efficiently and accurately with structured, code-like instructions than with free-form speech.
    • 3. Prompt structure optimization: The whole point of the work is optimizing structure through pseudocode, functions, comments and variables.
    • 7. Reliability and stability: The feedback (replan) and check (assert) mechanisms directly target fewer errors and greater reliability.
  • Practicality checklist (+15 points): Yes, the study provides ready-made constructs, shows how to structure complex queries and reveals the non-obvious effectiveness of a code-like format. That adds +15 points to the base score.
03

Numerical Usefulness Score

Arguments for a score of 90: The study offers what for many users is a revolutionary paradigm shift: from vague text descriptions to clear, algorithmic instructions in pseudocode format. It directly tackles LLM verbosity, ambiguity and "hallucinations". Key takeaways such as "structure beats verbosity" and "comments to explain intent" can be applied immediately. A huge bonus is the massive token savings (up to 87%), which is critical for anyone using paid APIs. It's one of the most practically valuable concepts for advanced prompting.

Counterarguments (why not 100): The full implementation of the CodeAgents framework, with multiple agents, feedback and tool calls, is out of reach for a regular user in a simple chat. The terminology (YAML, API calls, multi-agent) may scare off a non-technical audience, causing them to miss the simple, brilliant principle underneath. To benefit, the user has to mentally "adapt" a complex system to a simple prompt, which takes some abstract thinking.


Research digest

Key result

The paradox: a "language" model works more accurately when you talk to it like a programmer rather than like a person. CodeAgents lets you frame any complex request as a pseudo-program, with functions, variables and comments, and get a structured result without the logic leaking between steps. The trick: comments (#) inside the pseudocode work as a built-in chain of thought: the model understands not just what to do but why. It stops interpreting your intent and starts executing an algorithm. The upshot: fewer errors, fewer tokens, more accuracy.

Principle

A regular prompt is a request. Pseudocode is an instruction. The difference is huge. When you write def analyze_market(product, audience):, you're not setting a topic for conversation, you're setting a contract: here's the input, here's what needs to come back. Each step is a separate "function" with an explicit goal, and the output of one step becomes the input of the next. The model doesn't guess what you wanted: it follows logic you've already thought through yourself.

Why it works

LLMs were trained on enormous volumes of code alongside ordinary text. Code is unambiguous. The word "analyze" allows dozens of readings; analyze_competitors(product, region) doesn't. Comments (#) give the model an explanation of why each step is needed, not just what to do, and that improves the quality of each stage on its own. Plus, variables between steps preserve context. The model doesn't forget what it did in step one when it gets to step three, which is exactly where ordinary long prompts start to drift.

When to apply

Works for any multi-step task: a content plan, a financial review, market research, strategy documents, structured reports. It shines where step order matters and no stage can be skipped: the model literally can't jump over a step if the next one refers to the previous step's result. NOT suitable for: simple short questions and free-form creative writing with no structure. There, pseudocode just gets in the way.

Mini recipe

1. Open a "function": write def task_name(param1, param2):. This immediately sets the goal and the inputs. The model understands: here's what goes in, here's what must come out. 2. Break it into steps: each step is a separate line with a named result. For example: analysis = analyze_audience(parameter). 3. Add comments: put a # before each step and explain why it's needed, not what happens. This steers the model's reasoning. 4. Link the steps with variables: pass step 1's result into step 2 explicitly. This keeps the logical chain intact and stops the model from inventing data out of thin air. 5. Finish with a command: final_answer(final_variable) signals to the model that it's time to output the final result rather than keep reasoning.

Examples

[BAD]: `Analyze my market and come up with a marketing strategy for a new meditation app` [GOOD]: ``` def create_marketing_strategy(product='meditation app', audience='city dwellers aged 25-40'): # Step 1: Find competitors and understand where our product is stronger competitors = analyze_competitors(product) # Step 2: Find the audience's unmet needs based on the competitor analysis pain_points = find_gaps(audience, competitors) # Step 3: Create 3 key brand messages for the needs we found brand_messages = create_messages(pain_points, count=3) # Step 4: Put it into a table with promotion channels and key points final_answer(format_as_table(brand_messages)) ```

In plain words

The thing is, today's AI agents burn through resources shamelessly, tossing tons of text back and forth at each other. CodeAgents changes the very mechanics of the conversation: instead of writing long "essays" in natural language, agents communicate through executable code. It's a fundamental shift in architecture: the LLM stops just chatting and starts generating compact scripts that convey the essence of the task without the junk. The result is a system where logic is separated from noise, and accuracy on complex tasks goes up, because code doesn't tolerate ambiguity.

It's like handing a builder coordinates and a blueprint instead of waving your hands about where to dig a hole. Technically, you talked less, but the result will be ten times more accurate than after an hour-long lecture on "the depth and meaning of holes". In the usual multi-agent setup, models behave like office clerks in an endless status meeting; in CodeAgents they work like programmers in a shared repo: short, to the point, and with error checks.

The main trick here is codified reasoning. The system uses a Python interface to pass data between agents, which cuts the token count several times over. It's not just about saving money, it's about a clean context: the model doesn't clutter its memory with polite phrases and repetition. When one agent hands another a data object rather than a description of that object, the risk of the model "hallucinating" or forgetting an important detail approaches zero.

Although the method was tested on coding and math, the principle is universal. You can build it into any complex pipeline, whether it's data analysis, marketing automation or smart-home control. Anywhere you need several AI models to work in tandem, replacing text with code gives you a massive boost. It's the move from a chaotic chat to a structured protocol where every step is logically justified and verifiable.

Bottom line: the era of "chatty" agents is ending, because it's expensive and inefficient. CodeAgents proves the future belongs to brevity and strict structure. If you want your AI tools to run faster and not choke on long runs, make them write code, not letters. Whoever switches to these rails first will save budget and get a system that actually gets things done instead of just looking busy.

AI lab assistant

Apply this study to your task

Describe what you're working on. AI takes the method and the measured results from this paper and adapts them to your case, or writes a ready prompt built on them.

Based on CodeAgents: pseudocode instead of a prompt. More accurate and many times cheaper in tokens arXiv:2507.03254

Sign in to apply this study New accounts get 50 free credits.

Get the week’s best papers by email

One email on Sundays with the highest-rated new techniques. Unsubscribe with one click.