Automata from Agent Traces: Failure and Next-Step Prediction
Abstract
LLM-based agents execute multi-step tasks, but their behavioral structure remains opaque: their long, unstructured traces resist the safety auditing and runtime monitoring that deployment requires. Existing approaches look at one trace at a time or at successful runs only, missing the structure shared across runs that links next-step and failure prediction. We extract finite-state machines (FSMs) as the compact directly-follows automaton of the observed traces via prefix-tree construction and last-activity merging, providing a structural substrate for the unpredictable nature of LLM agent behavior. Across twelve public datasets, the FSMs are compact (7–43 states), achieve high replay fitness on held-out data with zero structural variance across splits, and build in milliseconds. This substrate addresses both prediction goals. Provided as context, the FSM beats Agent Workflow Memory at next-step prediction on all eight ground-truth-matched datasets, six of them significantly. Per-state behavioral features predict task failure at held-out AUROC up to 0.94, and an online monitor ranks failing SWE-agent runs above passing ones from a partial trace, beating the trivial flag-everything baseline on rank-AUROC and triggering early stopping well before completion. On tau2-bench, one FSM built from the traces of four LLMs replays each of them at 1.000 fitness, evidence that within these task suites behavioral topology is shaped more by the deployment harness than by the LLM, giving a structural primitive for safety auditing and runtime monitoring at deployment.