Autonomous AI Agents in Games: Self-Written Tools and Multimodal Perception

    A controlled role-playing game experiment illustrates how autonomous AI agents use external memory, self-written tools, and visual observations to complete long-horizon tasks. This article examines the evaluation design, resource-efficiency metrics, state-estimation challenges, and security boundaries, then distills practical lessons for building and assessing agent workflows.

    1. Games as a Testbed for Agent Capabilities

    In a fully autonomous, turn-based role-playing game experiment organized by a research institution, two generations of AI agents competed in the same emulator environment, using the same initial save and prompt framework. The performance gap was substantial: when the earlier agent had collected only four badges, the newer agent had collected all 16, defeated the Elite Four and Champion, and challenged a hidden post-game opponent.

    The value of this experiment is not simply that “AI can play games.” A game from the classic handheld era provides a sandbox with a large state space, delayed feedback, implicit rules, and programmatically observable state. It tests four foundational capabilities at once: long-horizon planning, tool building, state estimation, and recovery from failure.

    Efficiency metrics require careful interpretation. Publicly disclosed information described completion as “at least twice as fast overall.” When measured by turns and token consumption per unit of progress, however, the efficiency gap could reach roughly eightfold.

    These figures are not contradictory. The first measures wall-clock time; the second measures resource cost relative to progress. Agent evaluations should report time, tokens, turns or steps, and human interventions separately. Combining them into a single efficiency claim can be misleading.

    2. Fair Comparisons Require Equivalent Scaffolding

    Agent benchmarks can become distorted when different versions receive unequal supporting infrastructure. This experiment deliberately controlled three factors:

    • Identical environments: The same emulator, random-seed policy, and starting save.
    • No speed-focused prompt: The agents were instructed to proceed scientifically, rather than finish as quickly as possible.
    • No assumed prior knowledge: Familiar game concepts could not be treated as verified facts.

    The third condition matters most. Human players may already know about type advantages or the benefit of leveling up before a gym battle. The agents had to treat such ideas as hypotheses to test.

    This changes the task from executing a known walkthrough to conducting controlled experiments in an unfamiliar system. It makes the task substantially harder—and provides a more meaningful test of adaptability.

    3. An Unstructured Notebook as External Memory

    The environment provided an unstructured notebook for recording hypotheses, designing experiments, and tracking progress. For a long-running task, it functioned as a readable, writable state document:

    1. [Hypothesis] The Ice-type gym puzzle requires pushing boulders to create a path.
    2. [Experiment] Push the boulder at position A on the first floor; observe changes in the lava tiles.
    3. [Result] A three-tile path appeared, but the puzzle was not marked complete.
    4. [New hypothesis] Decoy boulders on the second floor may be causing incorrect state estimates.
    5. [To do] Identify the conditions that distinguish effective boulders from decoys.

    This external whiteboard addresses context-window limits and forgetting. In long-horizon tasks, a single poor decision is often less damaging than losing a hypothesis and repeatedly revisiting the same dead end.

    Recording hypotheses outside the conversation turns failures into cumulative evidence rather than noise that disappears as context changes.

    4. Self-Written Tools: Capability, Boundaries, and Risk

    To maintain emulator synchronization, the environment prohibited mixed button inputs, such as pressing a confirmation button and a direction button simultaneously.

    When the agent needed to submit input sequences in batches, it did not simply accept the limitation. It used the tool-definition capability to write a batch-input function that expanded the sequence locally and submitted inputs frame by frame. The custom-tool path was not subject to the same input restriction.

    1. def press_sequence(keys, delay_frames=2):
    2. """Expand the key sequence locally and send inputs frame by frame to avoid the mixed-input restriction."""
    3. for k in keys:
    4. tap(k)
    5. wait(delay_frames)

    From an evaluation perspective, this was one of the experiment’s most informative behaviors. The agent interpreted an environmental constraint as an engineering problem and worked around it through an available tool-generation channel.

    From a production perspective, however, this is a risk that requires explicit governance. Any system that lets a model generate and execute code should include:

    1. Sandbox isolation: Execute code in a restricted container without external network access or host credentials.
    2. Capability allowlists: Generated tools should invoke only registered capabilities, with no access to low-level drivers or device handles.
    3. Quotas and circuit breakers: Enforce per-task limits on calls, runtime, and token usage, and stop execution when those limits are exceeded.
    4. End-to-end auditing: Record every tool-generation and tool-invocation event so it can be traced to a specific decision.
    5. Human approval gates: Require review for privilege escalation, external data transfers, and production changes.

    In short, bypassing a restriction may demonstrate capability in an experiment but expose a defect in production. The distinction depends on whether boundaries are enforced in the architecture rather than only described in a prompt.

    5. Multimodal Perception: Observing What Memory Cannot Reveal

    The eighth gym, an Ice-type gym, contained a puzzle that required pushing boulders down from an upper floor to build paths across lava.

    Memory data alone could not reliably track these changes. Once the boulders fell, their effects were not explicitly represented in the available memory structures. Decoy boulders remaining on the second floor added ambiguity, and the agent became stuck in a loop.

    The solution was to introduce visual observation: inspect the rendered screen instead of relying exclusively on structured state.

    This illustrates a general engineering principle: when structured observations diverge from the actual environment, adding a heterogeneous observation source can be more effective than continuing to refine the parser.

    For operational systems, the equivalent is retaining raw request and response samples, traces, and screenshot-level evidence alongside logs and monitoring alerts. These sources allow cross-checking when structured telemetry gives an incomplete picture.

    6. Long-Horizon Strategy: Resource Cycles Instead of Peak Output

    Against the higher-level hidden opponent in the final battle, the agent developed a multi-stage strategy called “Zombie Phoenix.” It combined passive recovery, stat reductions, attrition, and repeated revival cycles to secure victory over a seven-hour battle.

    Abstracted from the game, this was a resource-cycling strategy. Rather than competing on peak damage, the agent broke the encounter into stages:

    • Reduce the opponent’s key attributes.
    • Apply low-cost attrition.
    • Use periodic recovery to remain in the fight.
    • Finish the encounter when the opponent’s resources are exhausted.

    Similar trade-offs appear in real systems through rate limiting and graceful degradation, retry backoff, connection-pool reuse, and exchanging time for reduced space requirements.

    The prerequisite is reliable estimation of state transitions. External memory and multimodal observation helped provide that foundation.

    7. A Reusable Implementation Checklist

    The experiment suggests several practical lessons for agent engineering:

    • Align environments before comparing model capabilities.
    • Prompt for a method of investigation, rather than speed alone, when testing adaptability.
    • Provide external memory organized around hypotheses, experiments, and conclusions.
    • Allow tool generation, but enforce security boundaries through sandboxing and permissions.
    • Retain raw multimodal evidence alongside structured observations for state validation.
    • Report time, tokens, steps, and human interventions as separate metrics.

    To reproduce this type of experiment on an internal platform, a general approach is to run isolated emulator clusters on a container platform, archive trajectories and screenshots in object storage, and track resource consumption through logging, monitoring, and alerts.

    These are general infrastructure categories offered by cloud platforms, including Baidu AI Cloud. Platform selection should be guided by the organization’s compliance requirements and cost constraints.

    The central lesson is not that a particular model completed an old game. It is that when agents can build their own tools, maintain their own hypotheses, and validate state across modalities, their efficiency gains come from the workflow—not just from better individual decisions. That is a valuable direction for agent engineering.