arXiv(opens in a new tab)cs.AIAug 2026Cited by 5 papers on PaperVantage

Manuscript Offprint

arXiv:2608.23670

Automata from Agent Traces: Failure and Next-Step Prediction

Seonglae Cho, Franklin Cardenoso Fernandez, Umar Mohammed, Zekun Wu, Kleyton Da Costa, Ilham Wicaksono, Adriano Koshiyama

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Abstract

LLM-based agents execute multi-step tasks, but their behavioral structure remains opaque: long unstructured traces resist the safety auditing and runtime monitoring that deployment requires. Existing approaches operate per-trace or success-only, so they miss the cross-run topology that links next-step and failure prediction. To recover that shared structure, we collapse an entire trace corpus into a single, compact finite-state machine (FSM) that serves as a structural substrate for the otherwise unpredictable behavior of LLM agents. Across twelve public datasets, the FSMs are compact (7–43 states), replay held-out data at ≥\geq0.997 fitness with near-identical topology across splits, and build in milliseconds. This substrate addresses both prediction goals. For next-step prediction, FSM-state context outperforms Agent Workflow Memory on every ground-truth-matched dataset. For failure prediction, per-state behavioral features reach held-out AUROC up to 0.94, and an online monitor ranks failing runs above passing ones from a partial trace, triggering early stopping well before completion. Behavioral topology thus appears shaped more by the deployment harness than by the LLM, providing a model-agnostic structural primitive for safety auditing and runtime monitoring.

1. Introduction

As LLM-based agents (Wang et al., 2024; Sumers et al., 2024) take on longer reasoning chains and broader action spaces, the risk of undetected failures scales with their autonomy. These agents now resolve GitHub issues (Yang et al., 2024; 2025), navigate websites (Deng et al., 2023; Zhou et al., 2024; Koh et al., 2024), operate desktop environments (Xie et al., 2024; Wang et al., 2025c), manage customer service interactions (Yao et al., 2025), and orchestrate multi-agent pipelines (Wu et al., 2024a; Hong et al., 2024). Following the ReAct paradigm (Yao et al., 2023), they interleave chain-of-thought reasoning (Wei et al., 2022) with tool calls (Schick et al., 2023), generating execution traces whose behavioral structure remains implicit. A coding agent cycles through search→edit→execute; a customer service agent alternates between database queries and user communication. This structure emerges from the interaction between the system prompt, available tools, and task distribution, but nowhere is it specified.

Understanding this latent structure matters for safety auditing (Zhang et al., 2025a; Ruan et al., 2024; Chen et al., 2025), debugging bottleneck states (Zhang et al., 2025c; Cemri et al., 2025), and monitoring behavioral drift in production (Wang et al., 2025a). Yet current approaches operate at the individual trace level, requiring task descriptions, manual specification, or success filters (Zhang et al., 2025d; Wu et al., 2024b; Wang et al., 2025d).

We frame behavioral recovery as an inverse problem: given a corpus of execution traces, reconstruct a finite state machine (FSM) that explains the observed behavior. Agent traces provide only positive examples in the Gold sense (Gold, 1967; Angluin, 1980), and identifying the target language from positive examples alone is impossible in the limit. Our key observation is that agent behavior is generated by a bounded set of tools and actions, producing traces with small activity alphabets (6–42 symbols). The resulting behavioral topology appears shaped more by the system than by the LLM, across 4 chat models on tau2-bench: a single FSM achieves perfect fitness on every model. This structural constraint makes the problem tractable: a prefix tree merged by last activity produces a compact directly-follows FSM in linear time, requiring no learning hyperparameters (the only design choice is the activity extraction function, whose robustness we verify in Appendix G.2). We evaluate on twelve public datasets (Table 5) against nine baselines from automata learning (RPNI, EDSM, Alergia, k-Tails), HMMs, process mining, and workflow extraction ( §2\S2):

1^{1}Holistic AI 2^{2}PUC-Rio 3^{3}University College London. Correspondence to: Seonglae Cho seonglae.cho.24@ucl.ac.uk.

Published at the Second Workshop on Agents in the Wild: Safety, Security, and Beyond (AIWILD) at ICML 2026. Copyright 2026 by the author(s).

Figure

Figure 1. FSM evolution on SWE-agent. State count ∣Q∣|Q| (red, left) and test fitness (blue, right) over training traces, with FSM snapshots at six milestones. The state space grows incrementally as new behavioral modes appear, while fitness saturates early ( ≥\geq 0.99 at 240 traces, 15% of training); construction completes in milliseconds.

• Workflow memory. FSM-state context outperforms Agent Workflow Memory (Wang et al., 2025d) on 8/8 datasets (6 statsig at p<10−8p<10^{-8}; Table 4).

• Next-step prediction. FSM state conditioning improves cross-entropy by 0.155 bits (21%) over identical methods without state.

• Failure prediction. Per-state features reach held-out AUROC up to 0.94, lift MLP/GRU/Transformer baselines on 20 of 21 pairs, and power a prefix-based monitor that ranks failing SWE-agent runs above passing ones at the 25% checkpoint (rank-AUROC 0.66 vs. 0.5 for flag-everything) and triggers early stopping at 32% completion.

• Compression. 15–3,036× fewer states than RPNI at ≥0.997 fitness from a deterministic, hyperparameter-free construction.

One object ties these results together: bounded LLM-agent alphabets make the resulting compact deterministic finite automaton (DFA) both small and statistically informative, and the same FSM unifies workflow memory, next-step prediction, failure prediction, and runtime monitoring (Theorems and Propositions in §3.4).

References (1)

  • This loop executes 2–8 times per trace