ACL 2025 · Main ConferenceSelf-modifying agents

Gödel Agent: A Self-Referential Agent Framework for Recursively Self-Improvement

Xunjian Yin1, Xinyi Wang2, Liangming Pan3, Li Lin1, Xiaojun Wan1, William Yang Wang2

1 Peking University · 2 University of California, Santa Barbara · 3 University of Arizona

Gödel Agent can inspect and rewrite its own running code, using task feedback to revise both its problem-solving policy and the procedure that improves it.

Result
MGSM accuracy 64.2% for Gödel-base vs 53.4% for Meta Agent Search, both executing tasks with GPT-3.5 in a closed-book setting.
New vs prior
Meta Agent Search and natural-language-gradient methods improve agents through a fixed, human-designed meta-learning routine; this work lets the agent inspect and rewrite that routine as well as its task policy.
Limitation
Gains on DROP, MMLU and GPQA have overlapping 95% confidence intervals, and 14% of 100 MGSM optimization trials ended below the initial policy.
Illustration · Sections 3–4 and 6.3

A robot that rebuilds itself

Its glasses stand for how it reads feedback, its arms for how it solves tasks, and its wrench hand for the routine that edits it. That last part is editable too.

  1. Panel 1: Try the tasks. The agent runs its current policy on validation tasks and gets back scores and errors.

    01The agent runs its current policy on validation tasks and gets back scores and errors.

  2. Panel 2: See its own parts. It inspects its own running code: the policy that solves tasks and the routine that edits the agent.

    02It inspects its own running code: the policy that solves tasks and the routine that edits the agent.

  3. Panel 3: Swap in a stronger arm. It writes a new policy and patches it into itself while it keeps running.

    03It writes a new policy and patches it into itself while it keeps running.

  4. Panel 4: Get stronger. The revised policy is evaluated on the same tasks.

    04The revised policy is evaluated on the same tasks.

  5. Panel 5: Survive a bad part. Some edits break things. Error handling catches the failure and returns it as feedback.

    05Some edits break things. Error handling catches the failure and returns it as feedback.

  6. Panel 6: Upgrade the upgrader. The improvement routine is code too, so it can be revised: reported changes include keeping full error traces and optimizing in parallel.

    06The improvement routine is code too, so it can be revised: reported changes include keeping full error traces and optimizing in parallel.

Original illustration of the mechanism, not a record of one run. The score gauge is schematic; measured results appear in the evidence section.

What if the procedure that improves an agent could improve too?

A prompt optimizer revises the solver but keeps its own search routine fixed, and that routine decides which changes to propose, how to test them and how to recover from errors. Gödel Agent makes this routine editable too: the agent can rewrite both the code that solves tasks and the code that organizes its next revisions.

It can then change a prompt, add a verifier, replace an LLM call with an algorithm, or improve the diagnostics behind its next edit. The question is whether access to its own implementation helps an agent find better policies from task feedback.

Closest prior work

The paper groups earlier agents into hand-designed agents, which iterate over fixed modules, and meta-learning optimized agents, such as natural-language-gradient methods (Zhou et al., 2024) and Meta Agent Search (Hu et al., 2024), which update modules through a pre-defined meta-learning routine whose human priors cannot change at inference time. Gödel Agent makes that routine part of its own editable code. Unlike the Gödel machine (Schmidhuber, 2003), which relies on a proof searcher, or STOP (Zelikman et al., 2023), which recursively improves an optimizer for code generation, it uses an LLM to propose and apply modifications to the whole running agent.

Revisions change the running program

Scroll sideways to read the figure. Figure 3. The agent inspects and replaces functions in runtime memory. Later calls enter the revised implementation. Full size ↗

The agent reads its own Python variables, functions and classes at runtime, and a language model installs replacement code by monkey patching, that is, by overwriting functions in the running process. Its four actions (inspect the implementation, interact with the task, update code, continue improving) are invoked recursively, so later iterations run the revised improvement function.

Illustrative · Algorithm 1, Figure 3

One loop through the agent’s own runtime memory

Step through the four actions of Algorithm 1: which function each name is bound to, how self_improve recurses, and what feedback is carried forward.

Runtime memory · agent_module

solver
  1. solver v0asks the LLM
  2. solver v1+ checks with code
self_improve
  1. self_improve v0keeps error messages
  2. self_improve v1+ keeps tracebacks

Call stack newest first

  1. self_improve v1iteration 3
  2. self_improve v0iteration 2
  3. self_improve v0iteration 1

Action continue_improve

self_improve(E, solver, s, r, goal)# finds self_improve v1

Feedback carried forward SyntaxError: expected ':' · later errors arrive with the full traceback

continue_improve: the next call enters self_improve v1, so the procedure that proposes edits has changed. Such edits are the risky ones: the 4% of 100 MGSM trials that ended unexpectedly typically followed changes to this module (§6.2).

  1. Start: the designer supplies the initial policy (solver) and learning algorithm (self_improve), both ordinary functions in the running process.
  2. self_inspect: the agent reads the current code of solver and of self_improve, the function executing this step.
  3. interact: the utility function runs solver on validation tasks; the score and failing cases become the feedback r.
  4. self_update: an LLM writes a new solver and the agent rebinds the name to it without restarting. Every later call runs v1.
  5. self_update fails: the new code does not compile. Error handling halts this action sequence instead of ending the run and carries the error forward. Nothing was rebound: solver still runs v1.
  6. continue_improve: self_improve calls itself. The lookup still finds v0, so iteration 2 runs the same improvement code, with the error in its input.
  7. self_update on the improver itself: self_improve now points to a version that records full tracebacks. The two frames already running keep executing v0; only new calls enter v1.
  8. continue_improve: the next call enters self_improve v1, so the procedure that proposes edits has changed. Such edits are the risky ones: the 4% of 100 MGSM trials that ended unexpectedly typically followed changes to this module (§6.2).

Illustrative state, not a recorded run. Actions: Algorithm 1, §3; tools: goal prompt, Appendix A; rebinding: Figure 3; error handling: §4.2. The two edits are condensed pseudocode for changes reported in §6.3.

Feedback has two roles: validation scores assess the task policy, and execution errors diagnose a faulty edit. Error handling stops a failed action sequence and passes the error to the next step, so the next revision can change the solver, how errors are interpreted, or how changes are selected.

The designer still supplies the objective and the initial tools. Unlike the proof search of the theoretical Gödel machine, the agent accepts LLM-generated edits judged by task feedback, so it needs a useful evaluation signal and cannot guarantee that an edit helps.

  1. 01

    Inspect its implementation

    Expose the agent's functions, variables, and current policy through runtime introspection.

  2. 02

    Modify running code

    An LLM proposes changes and applies them through Python monkey patching.

  3. 03

    Evaluate and iterate

    Task feedback and error traces inform subsequent changes to the policy and improvement process.

Case study · Game of 24, Listings 5–6

From asking for an expression to searching for one

Make 24 from four numbers, each used once, with +, −, ×, ÷ and parentheses. In one reported run, after six failed optimization attempts, the agent replaced its LLM-based solver with search (§6.3).

Initial policy

Listing 5 ↗
def solver(numbers):
    prompt = describe_game(numbers)
    response = call_language_model(prompt)
    return response

The LLM proposes the expression; nothing checks that it follows the rules.

Rewritten policy

Listing 6 ↗
def search(values):
    if one_value_remains(values):
        return equals_24(values[0])
    for a, b, operation in choices(values):
        reduced = apply(a, b, operation)
        if search(reduced):
            return solution

Code tries combinations of numbers and operations; no LLM call is needed.

Run the search on four numbers

Local computation
3388

A verified solution

8 ÷ (3 − (8 ÷ 3)) = 24

Each input is used once. Intermediate fractions are kept exactly.

  1. 018 ÷ 3 = 8/3
  2. 023 − (8/3) = 1/3
  3. 038 ÷ (1/3) = 24

Three arithmetic operations combine the four input numbers.

Condensed pseudocode of Listings 5–6. The workbench runs a browser adaptation of the Listing 6 search (exact fractions, cached failed states) on inputs chosen for this page, not the agent. §6.3 reports 100% accuracy for the search-based case.

A strong gain in multilingual math, with smaller gains elsewhere

Recorded run · Figure 5

An LLM-based run: gains, failures, reverts

In this Game of 24 run, code-assisted verification and retrying with more data gave the largest gains; other edits failed or were reverted. The switch to search above is a different run.

Paper Figure 5: a nonmonotonic LLM-based Game of 24 optimization trajectory and a comparison of different initial policies.
Figure 5. Left: changes during an LLM-based run. Right: trajectories from different initial policies. Original vector figure; open full size ↗ · source ↗

GPT-4o proposes the code changes, while the optimized policies and all baselines execute tasks with GPT-3.5. The benchmarks cover multilingual math (MGSM), reading comprehension (DROP), general knowledge (MMLU) and graduate-level science (GPQA).

The search is also cheaper: the paper reports about $15 for a complete 30-iteration run across the four datasets, against $300 for Meta Agent Search. Gödel-free, which may call stronger models while solving tasks, is reported separately below.

All four tasks, with uncertainty visible

Against Meta Agent Search the MGSM gap is +10.8 percentage points; on DROP, MMLU and GPQA the confidence intervals overlap.

Table 1 · reported score ± 95% bootstrap confidence interval. DROP reports F1; the other columns report accuracy (%).

MethodDROPMGSMMMLUGPQA
Chain-of-Thought64.2 ± 0.928.0 ± 3.165.4 ± 3.329.2 ± 3.1
COT-SC64.4 ± 0.828.2 ± 3.165.9 ± 3.230.5 ± 3.2
Self-Refine59.2 ± 0.927.5 ± 3.163.5 ± 3.431.6 ± 3.2
LLM Debate60.6 ± 0.939.0 ± 3.465.6 ± 3.331.4 ± 3.2
Step-back-Abs60.4 ± 1.031.1 ± 3.265.1 ± 3.326.9 ± 3.0
Quality-Diversity61.8 ± 0.923.8 ± 3.065.1 ± 3.330.2 ± 3.1
Role Assignment65.8 ± 0.930.1 ± 3.264.5 ± 3.331.1 ± 3.1
Meta Agent Search79.4 ± 0.853.4 ± 3.569.6 ± 3.234.6 ± 3.2
Gödel-base80.9 ± 0.864.2 ± 3.470.9 ± 3.134.9 ± 3.3

How the comparison was run

Agent doing the optimization
GPT-4o-2024-05-13
Constrained policies and baselines
GPT-3.5-turbo-0125; closed-book execution
Search protocol
6 independent cycles per task; up to 30 iterations per cycle on validation data, then test evaluation
Validation / test questions
128 / 800 for DROP, MGSM and MMLU; 32 / 166 for GPQA, with GPQA evaluated five times
What about the higher Gödel-free scores?

DROP F1 90.5 ± 1.8, MGSM accuracy 90.6 ± 2.0, MMLU accuracy 87.9 ± 2.2, GPQA accuracy 55.7 ± 3.1. This version may call stronger models, including GPT-4o, while solving tasks. Its scores measure unrestricted tool use and belong to a different comparison from Gödel-base.

What makes continued improvement possible?

An agent that rewrites its own code needs a way to observe and recover from bad edits. Removing thinking before acting costs almost as much.

  • Full system
    64.2%
  • Without thinking before acting
    50.8%
  • Without error handling
    49.4%
  • Without code-running tool
    57.1%
  • Without LLM-calling tool
    60.4%

Table 2 and the full-system MGSM score from Table 1. Bars start at zero; no per-ablation confidence interval is supplied in Table 2.

Self-improvement is not monotonic

Across 100 MGSM optimization trials:

92%
encountered a temporary performance drop
14%
finished below the initial policy
4%
terminated unexpectedly

These are different, potentially overlapping events—not three parts of a whole. Editing the improvement procedure can also break the ability to continue improving.

Table 1 ↗ · Table 2 ↗ · Robustness ↗ · Experimental protocol ↗

Scope. The experiments support a broader empirical search over agent programs. They do not establish monotonic improvement, global optimality, or open-ended gains beyond current model capabilities. Read the study ↗

Further reading in the paperRuntime mechanism · Sections 3–4 ↗Game of 24 cases and source code ↗Main results and experimental settings ↗
Research summary

The rapid advancement of large language models (LLMs) has significantly enhanced the capabilities of agents across various tasks. However, existing agentic systems, whether based on fixed pipeline algorithms or pre-defined meta-learning frameworks, cannot search the whole agent design space due to the restriction of human-designed components, and thus might miss the more optimal agent design. In this paper, we introduce Gödel Agent, a self-evolving framework inspired by the Gödel Machine, enabling agents to recursively improve themselves without relying on predefined routines or fixed optimization algorithms. Gödel Agent leverages LLMs to dynamically modify its own logic and behavior, guided solely by high-level objectives through prompting. Experimental results on multiple domains demonstrate that the implementation of Gödel Agent can achieve continuous self-improvement, surpassing manually crafted agents in performance, efficiency, and generalizability.

Full paper ↗
Citation BibTeX
@inproceedings{yin-etal-2025-godel,
    title = {G{\"o}del Agent: A Self-Referential Agent Framework for Recursively Self-Improvement},
    author = {Yin, Xunjian and Wang, Xinyi and Pan, Liangming and Lin, Li and Wan, Xiaojun and Wang, William Yang},
    booktitle = {Proceedings of the 63rd Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers)},
    month = jul,
    year = {2025},
    address = {Vienna, Austria},
    publisher = {Association for Computational Linguistics},
    url = {https://aclanthology.org/2025.acl-long.1354/},
    doi = {10.18653/v1/2025.acl-long.1354},
    pages = {27890--27913}
}