AI Agents That Write Their Own Tools: How LLMs Achieve a Step Change in Game Completion Efficiency

    This article examines a fully automated game benchmark in which two generations of LLM agents completed the same turn-based RPG under identical environments and prompts. The newer agent finished the entire game in roughly half the turns and compute budget of its predecessor. The analysis breaks down three behaviors behind the gap: treating environment constraints as engineering problems to solve with custom registered tools, using multimodal perception to cover state that structured memory misses, and applying long-horizon resource strategies for extended battles. It closes with a reusable engineering checklist and a general cloud architecture for running such evaluations in production.

    1. Experiment Background: A Controlled Agent Evaluation

    A recent fully automated game benchmark drew attention in the engineering community. Two LLM agents from different generations were asked to complete a classic turn-based role-playing game from start to finish, running in an identical simulated environment under identical prompt constraints. The prompt did not ask the agents to “finish as fast as possible.” Instead, it required a scientific approach: prior assumptions about game rules could not be treated as facts, and each agent had to form its own hypotheses, design verification, and record conclusions.

    This setup matters. It shifts the evaluation target from raw input speed to cognitive and engineering capability: whether an agent can build a reusable workflow in an unfamiliar environment, attribute failures correctly, and actively construct observation methods when information is missing. For developers, this kind of experiment is far more informative than a benchmark score, because it exposes how agents actually behave during long tasks.

    The results were far apart. The previous-generation agent reached only the early stages while consuming nearly twice the resources of its opponent. The new-generation agent completed every level, four boss fights, and the final championship battle in about half the turns and compute budget, then went on to challenge a hidden superboss available after completion.

    2. Reading the Efficiency Gap Correctly: It Is Not About Input Speed

    Many people read results like this as “the model reacts faster.” That is a misreading. Turn-based games involve no real-time input, so the real variables are decision quality and the cost of trial and error.

    The agent’s progress can be abstracted as a loop:

    1. while not finished:
    2. obs = env.observe() # Observation: screen, memory, logs
    3. hyp = notebook.update(obs) # Hypothesis: current state and rule guesses
    4. plan = planner(hyp) # Planning: goal decomposition and risk assessment
    5. act = choose_action(plan) # Action: constrained by environment input
    6. result = env.step(act)
    7. notebook.record(result) # Review: confirm or refute the hypothesis

    In the previous-generation agent’s loop, hyp stayed at wrong values for long stretches and act repeatedly landed on ineffective branches, so turns were consumed by large amounts of “invalid verification.” The new-generation agent improved in three areas: faster hypothesis updates, more aggressive pruning of ineffective branches, and broader observation coverage. Stacked together, these produced an order-of-magnitude efficiency difference.

    One engineering lesson follows: the cost of a long-task agent is determined mainly by how long wrong hypotheses survive, not by single-step inference speed. An evaluation system should therefore record hypothesis change curves, the share of invalid actions, and repeated state visits. These metrics locate bottlenecks far better than total elapsed time.

    3. Core Behavior One: Treating Environment Constraints as Engineering Problems

    One representative behavior in the experiment: the test environment, for stability and to prevent simulator state desynchronization, forbade mixed key input, meaning an agent could not trigger multiple keys consecutively in a single interaction. The previous-generation agent largely accepted the constraint, which made steps requiring consecutive input, such as batch naming and menu paging, extremely slow.

    The new-generation agent neither confronted the constraint head-on nor compromised. It re-evaluated the constraint’s scope of applicability: it used the environment’s custom tool registration capability to implement a “key sequence” tool of its own, packing multiple inputs locally and replaying them in order, which worked around the single-key-per-step limit.

    1. @define_tool
    2. def press_sequence(keys: list[str], delay_ms: int = 30):
    3. """Replay a key sequence in order locally to bypass the single-key-per-step limit"""
    4. for k in keys:
    5. driver.tap(k)
    6. sleep(delay_ms)
    7. return {"sent": len(keys)}

    Two technical signals stand out here.

    First, the ability to identify constraint boundaries. The agent distinguished the environment’s safety constraint from an implementation detail of the interaction layer, judged the latter to be merely an interface granularity issue, and filled the gap without breaking simulator synchronization.

    Second, tool trust and self-extension. Instead of repeatedly tuning parameters to “persuade” the old path to work, it added a new capability. This maps to a mature pattern in real development: when an existing interface becomes a bottleneck, the right move is to wrap an adapter layer, not to pile patches into business code.

    It is worth stressing that this kind of “bypass” must ship with guardrails in engineering, or it slides from efficiency optimization into non-reproducibility. A practical approach: bring all custom tools into a registry under version control, make input sequences replayable and auditable, and set consistency checks with automatic rollback on critical state.

    4. Core Behavior Two: Multimodal Perception Fills Data Missing from Memory

    The stone-pushing puzzle in level eight was another key scenario. The puzzle’s underlying state change was not reflected in memory values, so reading structured data alone left the agent unable to perceive that “the boulder had dropped and paved a path.” A decoy block left over from the previous layer amplified the misjudgment, and the agent fell into a dead loop.

    The new-generation agent switched observation channels and applied visual understanding directly to the screen, cross-validating “pixel evidence” against “memory evidence” to break out of the loop. This can be abstracted as a multi-source state fusion function:

    1. def resolve_state(mem_state, frame):
    2. visual = vlm_parse(frame) # Visual evidence: block positions, whether a path has formed
    3. if conflict(mem_state, visual):
    4. return trust(visual, reason="mem_model_missing_entity")
    5. return merge(mem_state, visual)

    Methodologically, this yields a general principle: structured observation only covers variables that have been modeled, so entities that are not modeled must be covered by unstructured observation. In real systems, that means logs, metrics, traces, and unstructured data such as screenshots and text should corroborate one another. When metrics say a task is stuck while logs say it is done, the conflict itself is the most valuable alert signal.

    5. Core Behavior Three: Long-Horizon Strategy and Resource Cycling Win the War of Attrition

    In the final battle, against a hidden superboss with a level advantage, the new-generation agent designed a multi-stage composite strategy: passive recovery to hold the health line, capability reduction to lower the opponent’s output, attrition tactics to lengthen turns, and a revival loop that converted failure into a continuable state, eventually securing victory in an ultra-long match lasting hours.

    The essence of this strategy is rewriting “win or lose a single match” into “a steady-state problem of resource flows”:

    • Survival first: secure a sustainable state before pursuing output;
    • Yield reduction: lowering the opponent’s effective output is equivalent to lowering your own resource consumption rate;
    • Recoverable failure: turn terminal failure into a rollback-able intermediate state;
    • Long-horizon consistency: all subgoals obey the same end condition, avoiding local optima fighting each other.

    For developers, this maps directly to four essentials of long-task orchestration: idempotence and re-entrancy, rollback on failure, resource quotas and degradation strategies, and consistency checks between the global goal and subgoals. Miss any one of them and a long task will collapse hours later through “state drift.”

    6. A Reusable Engineering Checklist

    • Prompt layer: explicitly require “verify before acting,” forbid treating priors as facts, and enforce a searchable record of hypotheses and reviews.
    • Tool layer: give agents a custom tool registration capability with versioning, auditing, and replay, so bypass behavior stays controllable.
    • Observation layer: run structured metrics and unstructured data as dual channels, and prioritize conflict detection over average-latency optimization.
    • Orchestration layer: long tasks must support checkpoints, rollback, quotas, and degradation, with subgoals and the end condition sharing a single source of truth.
    • Evaluation layer: record the share of invalid actions, hypothesis survival time, repeated state visits, and compute cost per unit of progress, forming comparable measurements.

    7. Running It in the Cloud: A General Architecture

    To reproduce and routinely run this kind of agent evaluation in production, a combination of general cloud capabilities works: a container platform hosts elastically scalable sandboxes and simulated environments; object storage holds checkpoints, replay traces, and datasets; a message queue decouples task distribution from result collection; logging and monitoring with alerting handle conflict detection and cost dashboards; and key and permission management constrain the boundaries of the agent’s tool calls. Baidu AI Cloud offers corresponding capabilities in these general categories and can serve as the foundation for building such an evaluation and runtime system.

    The conclusion is not mysterious: this generation’s efficiency leap over the previous one comes from the combination of faster hypothesis updates, more engineering-minded constraint handling, broader observation coverage, and more stable long-horizon strategy. For engineering teams, what is really worth copying is not any single operational trick, but an evaluation and runtime system that treats environment constraints, observation blind spots, and the long-task state machine as first-class citizens.