Inspiration

The right action at the wrong time is the wrong action.

Most AI demos let the world wait for the model’s response. We wanted to explore what happens when it doesn’t. Can an AI make useful decisions while the situation keeps changing?

That led us to Metro-Clef, a project using Cloudflare Clef to control an open-source Mini Metro simulator. Passengers keep arriving while the model thinks. Routes need connecting, trains need assigning, and growing queues turn slow decisions into real consequences.

What it does

Metro-Clef gives Clef a structured view of the transit network and lets it choose route and fleet operations. The game continues running during inference, so decisions must be both useful and timely.

We compared three approaches:

  • A hand-written heuristic: a simple, code-only baseline.
  • Clef alone: the model chooses from a menu of available actions.
  • Tree-guided Clef: code narrows the options, and Clef answers smaller, more concrete questions.

How we built it

We connected the Python simulator to Clef through an asynchronous decision loop. Every five seconds, the controller captures the game state and requests a decision without pausing gameplay.

Responses are checked against a three-second deadline and the current game state. Late, invalid, or no-longer-legal decisions are rejected rather than silently replaced by a fallback strategy.

Our first approach asked Clef one broad question: “Which action is best?”

Our improved approach uses a pruned decision tree. Code removes illegal or pointless options, then Clef answers three smaller questions in a single request. This keeps the model involved in the decision while giving it a more focused task.

We also built telemetry and gameplay recordings to compare approaches and show what happens while the model is thinking.

Challenges we faced

### The world changes during inference

A decision can be valid when requested but outdated when it arrives. We had to separate requesting a decision from applying it, then validate the response against the live simulation.

### Legal actions are not necessarily useful actions

Clef could select valid operations, but building a successful network requires anticipating consequences. A route change may take tens of seconds to help, while passengers are already accumulating.

### Results and demos tell different stories

Model-driven runs varied, even on the same seed. A compelling gameplay clip was not enough to establish improvement, so we evaluated the controllers across the same five seeds and kept recorded demonstrations separate from aggregate results.

What we learned

Giving a model a smaller, better-shaped decision can matter more than giving it more freedom.

In our five-seed evaluation, Clef alone averaged 22.0 delivered passengers and had two game overs. Tree-guided Clef averaged 28.8 delivered passengers with zero game overs, matching the hand-written heuristic’s average deliveries.

That is a promising result, not proof of general superiority: we tested five seeds with one run per approach per seed. Our structured controller avoided the collapses seen in that evaluation, but it did not beat the baseline’s delivery performance.

The biggest lesson was architectural: let code enforce constraints and narrow the choices; let the model make focused judgments. In a real-time system, how you frame and execute a decision matters alongside the model’s answer.

What’s next

We want to add look-ahead planning so decisions account for how the network will evolve, not just its current state. We also want to explore faster inference and fine-tuning on simulator outcomes.

Metro-Clef is our exploration of a broader question: how do we make AI useful when the world refuses to pause?

Built With

Share this project:

Updates

Submission history