Automata from Agent Traces

One automaton, built from traces, serves as a memory, prediction, and monitoring prior

Authors

Published

Jun. 30, 2026

Table of Contents

The Opacity Problem

LLM-based agents execute multi-step tasks, but their behavioral structure remains opaque. Existing approaches operate per-trace or success-only, so they miss the cross-run topology (what one run shares with the next) that links next-step and failure prediction. Watch one agent work and you get a wall of text; watch a thousand and you get a machine, a search, edit, execute loop the agent never declares and the system prompt never specifies.

Yang and colleagues put LLM-based agents to work resolving GitHub issues (Yang et al., 2024, 2025). Others have them navigating websites (Zhou et al., 2024), operating desktops (Xie et al., 2024), driving mobile interfaces (Lu et al., 2025), managing customer service interactions (Yao et al., 2024), orchestrating multi-agent pipelines (Hong et al., 2024; Wu et al., 2023), and attributing the blame when one of those pipelines breaks down (Zhang et al., 2025). Following the ReAct pattern (Yao et al., 2023), they interleave chain-of-thought reasoning (Wei et al., 2022) with tool calls — and every run produces an execution trace of tool calls, natural language, and environment feedback.

This article recovers that machine. From nothing but the agent’s own execution traces — no labels, no task descriptions — we extract a compact finite-state machine, or FSM, of 7 to 43 states. That machine does the two things an operator actually needs: predict what the agent will do next, and catch a failing run before it wastes the compute.

The whole article follows one thread: heterogeneous agent traces pass through one deterministic abstraction ϕ\phi, pile up into a prefix tree, and collapse in a single classical merge into one automaton. That one object — not four bespoke pipelines — is then read four different ways: as workflow memory, a next-step predictor, a failure detector, and a runtime monitor.

How the machine is built, and how it is used
build trie merge states Agent traces messages · tool calls coding web GUI telecom φ message → symbol deterministic Prefix tree PTA one branch per trace ONE PER AGENT Automaton states + transition probabilities Workflow memory state → likely next actions, injected into the agent's prompt Next-step prediction reads P(next action | current state) off the machine Failure prediction replay a run → per-state features → classifier Runtime monitor online conformance check, flags drift mid-run CONSTRUCTION · built once, offline USED AT RUNTIME · per execution
Data and execution flow. On the left, construction (offline, once per agent): each trace message is mapped to a symbol by φ, the symbol sequences accumulate into a prefix tree, and one state-merge collapses it into a single automaton. On the right, the four runtime consumers and what each reads from that same machine. Hover a consumer to trace it back to the automaton.

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, the available tools, and the task distribution — yet it’s nowhere written down.

Understanding this latent structure matters the moment you deploy: safety auditing has to verify that an agent visits the right states and avoids the attack chains that agent security benchmarks enumerate (H. Zhang et al., 2025), debugging means locating the bottleneck states where agents get stuck, and production monitoring flags behavioral drift before it costs anything.

Yet current agent analysis works at the level of a single trace (Z. Wu et al., 2025). Benchmarks such as AgentBench and AgentBoard score whether a run succeeded (Liu et al., 2024; Ma et al., 2024), and sandboxes such as ToolEmu probe what a run risks (Ruan et al., 2024). Neither offers a structural model of the behavior that links one run to the next.

A trace, read symbol by symbol, drives a finite-state machine
Pick a dataset, then scrub the tape (drag or scroll) or let it play. The read-head advances through the agent's activity tape (left) and lights up the current FSM state and the transition it takes (right). A successful run threads to submit; a stuck run loops and never reaches it. These are representative traces; the full set of twelve datasets with their real extracted FSMs is in the live dashboard.

The Inverse Problem

We frame behavioral recovery as an inverse problem: given a corpus of execution traces, reconstruct a finite-state machine that explains the observed behavior. Gold posed this as grammatical inference (Gold, 1967), Oncina and García later gave it a working algorithm (Oncina & Garcı́a, 1992), and de la Higuera surveys what the field settled on (de la Higuera, 2010). The classical setting assumes both positive and negative examples. Angluin’s alternative replaces the negatives with an oracle that answers membership queries (Angluin, 1987), and an execution log answers nothing. Agent traces give us positive examples only (the runs that happened) with no labeled counter-examples. Gold also proved that identifying the target language from positive examples alone is impossible in the limit (Gold, 1967).

A property specific to agents rescues the problem: unlike arbitrary regular languages, agent behavior is generated by a bounded set of tools and actions, so traces draw from a small activity alphabet, 6 to 42 symbols across our twelve datasets.

A small alphabet is the whole reason this works. It makes the compact automaton both small and, as later chapters show, statistically dense enough to predict from. The only modeling choice in the entire pipeline is how a message becomes a symbol.

Twelve Datasets, Eight Domains

We evaluate on twelve public datasets spanning coding, web navigation, desktop GUI, desktop OS, mobile GUI, customer service, safety, and multi-agent coordination. The trace counts below are the trajectories we use in our experiments (from 184 to 8,337 each), not the size of each source corpus: for three of the sources we draw a fixed slice rather than the whole set.

DatasetDomainTraces usedActionsStatesFitness
SWE-smith (Yang et al., 2025)Coding5009101.000
SWE-agent (Yang et al., 2024)Coding2,00024250.999
Mind2Web (Deng et al., 2023)Web500781.000
WebArena (Zhou et al., 2024)Web8,33724251.000
AgentNet (Wang et al., 2025)Desktop GUI5,00024251.000
GUI-Odyssey (Lu et al., 2025)Mobile GUI7,735671.000
Who & When (S. Zhang et al., 2025)Multi-agent184891.000
tau2-bench airline (Barres et al., 2025)Customer service80017181.000
tau2-bench retail (Barres et al., 2025)Customer service1,82418191.000
tau2-bench telecom (Barres et al., 2025)Customer service1,82442431.000
ATBench (Li et al., 2026)Safety1,00014151.000
OSWorld (Xie et al., 2024)Desktop OS2,16626270.997

Every dataset replays held-out traces at fitness of at least 0.997.

Three source datasets are subsampled to a fixed slice: SWE-agent uses 2,000 of the 80,036 available trajectories, Mind2Web (Deng et al., 2023) 500 of 2,350, and AgentNet 5,000 from the OpenCUA Ubuntu subset (Wang et al., 2025) — the other nine datasets are used in full.

Every case is in the live dashboard

Every figure in this article is a fixed snapshot. The interactive dashboard renders all twelve datasets straight from the experiment outputs — the FSMs, the failure predictor, the runtime monitor, and more.

  1. Angluin, D. (1987). Learning Regular Sets from Queries and Counterexamples. Information and Computation, 75(2), 87–106.
  2. Barres, V., Dong, H., Ray, S., Si, X., & Narasimhan, K. (2025). τ2-Bench: Evaluating Conversational Agents in a Dual-Control Environment. arXiv Preprint arXiv:2506.07982. back: 1, 2, 3
  3. de la Higuera, C. (2010). Grammatical Inference: Learning Automata and Grammars.
  4. Deng, X., Gu, Y., Zheng, B., Chen, S., Stevens, S., Wang, B., Sun, H., & Su, Y. (2023). Mind2Web: Towards a Generalist Agent for the Web. Advances in Neural Information Processing Systems (NeurIPS). back: 1, 2
  5. Gold, E. M. (1967). Language Identification in the Limit. Information and Control, 10(5), 447–474. back: 1, 2
  6. Hong, S., Zhuge, M., Chen, J., Zheng, X., Cheng, Y., Zhang, C., Wang, J., Wang, Z., Yau, S. K. S., Lin, Z., & others. (2024). MetaGPT: Meta Programming for A Multi-Agent Collaborative Framework. Proceedings of the International Conference on Learning Representations (ICLR).
  7. Li, Y., Luo, H., Xie, Y., Fu, Y., Yang, Z., Shao, S., Ren, Q., Qu, W., Fu, Y., Yang, Y., Shao, J., Hu, X., & Liu, D. (2026). ATBench: A Diverse and Realistic Agent Trajectory Benchmark for Safety Evaluation and Diagnosis. arXiv Preprint arXiv:2604.02022.
  8. Liu, X., Yu, H., Zhang, H., Xu, Y., Lei, X., Lai, H., Gu, Y., Ding, H., Men, K., Yang, K., & others. (2024). AgentBench: Evaluating LLMs as Agents. Proceedings of the International Conference on Learning Representations (ICLR).
  9. Lu, Q., Zhao, W., Jia, J., Ren, K., Lu, K., Han, J., Chen, Y., Zheng, J., Zhang, Z., & Ding, L. (2025). GUI-Odyssey: A Comprehensive Dataset for Cross-App GUI Navigation on Mobile Devices. Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition. back: 1, 2
  10. Ma, C., Zhang, J., Zhu, Z., Yang, C., Yang, Y., Jin, Y., Lan, Z., Kong, L., & He, J. (2024). AgentBoard: An Analytical Evaluation Board of Multi-turn LLM Agents. arXiv Preprint arXiv:2401.13178.
  11. Oncina, J., & Garcı́a, P. (1992). Inferring Regular Languages in Polynomial Updated Time. Pattern Recognition and Image Analysis, 49–61.
  12. Ruan, Y., Dong, H., Wang, A., Pitis, S., Zhou, Y., Ba, J., Dubois, Y., Maddison, C. J., & Hashimoto, T. (2024). Identifying the Risks of LM Agents with an LM-Emulated Sandbox. Proceedings of the International Conference on Learning Representations (ICLR).
  13. Wang, X., Wang, B., Lu, D., Yang, J., Xie, T., Wang, J., Deng, J., Guo, X., Xu, Y., Wu, C. H., Shen, Z., Li, Z., Li, R., Li, X., Chen, J., Boyuan, Z., Li, P., Lei, F., Cao, R., … Yu, T. (2025). OpenCUA: Open Foundations for Computer-Use Agents. arXiv Preprint arXiv:2508.09123. back: 1, 2
  14. Wei, J., Wang, X., Schuurmans, D., Bosma, M., Ichter, B., Xia, F., Chi, E., Le, Q., & Zhou, D. (2022). Chain-of-Thought Prompting Elicits Reasoning in Large Language Models. Advances in Neural Information Processing Systems (NeurIPS).
  15. Wu, Q., Bansal, G., Zhang, J., Wu, Y., Li, B., Zhu, E., Jiang, L., Zhang, X., Zhang, S., Liu, J., Awadallah, A. H., White, R. W., Burger, D., & Wang, C. (2023). AutoGen: Enabling Next-Gen LLM Applications via Multi-Agent Conversation. arXiv Preprint arXiv:2308.08155.
  16. Wu, Z., Cho, S., Munoz, C., King, T., Mohammed, U., Kazim, E., Perez-Ortiz, M., Bulathwela, S., & Koshiyama, A. (2025). AgentGraph: Trace-to-Graph Platform for Interactive Analysis and Robustness Testing in Agentic AI Systems. Proceedings of the AAAI Conference on Artificial Intelligence.
  17. Xie, T., Zhang, D., Chen, J., Li, X., Zhao, S., Cao, R., Hua, T. J., Cheng, Z., Shin, D., Lei, F., Liu, Y., Xu, Y., Zhou, S., Savarese, S., Xiong, C., Zhong, V., & Yu, T. (2024). OSWorld: Benchmarking Multimodal Agents for Open-Ended Tasks in Real Computer Environments. The Thirty-Eight Conference on Neural Information Processing Systems Datasets and Benchmarks Track. https://openreview.net/forum?id=tN61DTr4Ed back: 1, 2
  18. Yang, J., Jimenez, C. E., Wettig, A., Lieret, K., Yao, S., Narasimhan, K., & Press, O. (2024). SWE-agent: Agent-Computer Interfaces Enable Automated Software Engineering. Advances in Neural Information Processing Systems (NeurIPS). back: 1, 2
  19. Yang, J., Lieret, K., Jimenez, C. E., Wettig, A., Khandpur, K., Zhang, Y., Hui, B., Press, O., Schmidt, L., & Yang, D. (2025). SWE-smith: Scaling Data for Software Engineering Agents. Proceedings of the Annual Conference on Neural Information Processing Systems (NeurIPS), Datasets & Benchmarks Track. back: 1, 2
  20. Yao, S., Shinn, N., Razavi, P., & Narasimhan, K. R. (2024). τ-bench: A Benchmark for Tool-Agent-User Interaction in Real-World Domains. arXiv Preprint arXiv:2406.12045.
  21. Yao, S., Zhao, J., Yu, D., Du, N., Shafran, I., Narasimhan, K., & Cao, Y. (2023). ReAct: Synergizing Reasoning and Acting in Language Models. International Conference on Learning Representations (ICLR).
  22. Zhang, H., Huang, J., Mei, K., Yao, Y., Wang, Z., Zhan, C., Wang, H., & Zhang, Y. (2025). Agent Security Bench (ASB): Formalizing and Benchmarking Attacks and Defenses in LLM-based Agents. Proceedings of the International Conference on Learning Representations (ICLR).
  23. Zhang, S., Yin, M., Zhang, J., Liu, J., Han, Z., Zhang, J., Li, B., Wang, C., Wang, H., Chen, Y., & Wu, Q. (2025). Which Agent Causes Task Failures and When? arXiv Preprint arXiv:2505.00212. back: 1, 2
  24. Zhou, S., Xu, F. F., Zhu, H., Zhou, X., Lo, R., Sridhar, A., Cheng, X., Bisk, Y., Fried, D., Alon, U., & Neubig, G. (2024). WebArena: A Realistic Web Environment for Building Autonomous Agents. Proceedings of the International Conference on Learning Representations (ICLR). back: 1, 2

From Traces to Symbols

An agent execution trace is a sequence of messages τ=(m1,m2,…,mT)\tau = (m_1, m_2, \ldots, m_T), where each message has a role (system, user, assistant, tool) and content. Step one maps each message to a symbolic activity from a finite alphabet.

Activity Extraction

An activity extraction function ϕ:mt↦at∈A\phi: m_t \mapsto a_t \in \mathcal{A} maps each message to a symbol, and it applies three rules in priority order: a message carrying a tool_call field takes the function name as its activity (bash, search_flight, click); content carrying an [ACTION] description tag takes the action label; and for agents that act through code blocks we take the first command token and map it to a semantic category (edit, search, navigate, execute). If no rule matches, the activity defaults to role:content_type, and assistant:text is the common case.

The symbol layer is where other work has made different choices. ToolBench takes each API call as the unit (Qin et al., 2024), SWE-bench scores the patch an agent produces rather than the path it took (Jimenez et al., 2024), and AgentTrek reconstructs trajectories from written tutorials before an agent ever runs (Xu et al., 2025). Each fixes its unit in advance and computes it cheaply, as ϕ\phi does, but only ϕ\phi has to survive four trace formats at once.

The extraction is entirely deterministic and format-specific, with no LLM calls; the whole process completes in milliseconds.

An Example

Consider a coding agent trace from SWE-agent (Yang et al., 2024) with 47 messages. The raw trace contains system prompts, file contents, error messages, and tool invocations. After extraction, the activity sequence is:

init → user → search → user → edit → user → execute → user → edit → user → submit

From 47 messages and thousands of tokens, we get the 11 symbols the FSM will model — drawn from an alphabet of 24 possible activities.

Trace Explorer
Step through an agent trace to see how raw messages map to symbolic activities. Each message is classified by the extraction rules into one of the agent's activity symbols.

Replay any real trace symbol by symbol in the trace view.

Why This Works

These alphabets are small by construction, against the tens of thousands of symbols in natural language — that’s what keeps FSM extraction tractable.

Even a 42-activity telecom customer service agent (tau2-bench telecom (Barres et al., 2025)) needs only 43 states to capture its behavioral structure — the agent can only call the tools it was given. So its capabilities stay bounded and so does its alphabet.

How sensitive is the result to this choice?

ϕ\phi is the one design decision in the pipeline — so we stress-test it. Fitness stays at or above 0.999 across all four granularities, from role-only (two to four symbols) to full tool-level, and failure-prediction AUROC (area under the ROC curve) holds up: the default level matches or beats the coarser role-only level on ten of the twelve datasets, moving more only where role-only collapses to three symbols or fewer. The rules above are one valid setting, not the only one.

  1. Barres, V., Dong, H., Ray, S., Si, X., & Narasimhan, K. (2025). τ2-Bench: Evaluating Conversational Agents in a Dual-Control Environment. arXiv Preprint arXiv:2506.07982.
  2. Jimenez, C. E., Yang, J., Wettig, A., Yao, S., Pei, K., Press, O., & Narasimhan, K. (2024). SWE-bench: Can Language Models Resolve Real-World GitHub Issues? Proceedings of the International Conference on Learning Representations (ICLR).
  3. Qin, Y., Liang, S., Ye, Y., Zhu, K., Yan, L., Lu, Y., Lin, Y., Cong, X., Tang, X., Qian, B., & others. (2024). ToolLLM: Facilitating Large Language Models to Master 16000+ Real-world APIs. Proceedings of the International Conference on Learning Representations (ICLR).
  4. Xu, Y., Lu, D., Shen, Z., Wang, J., Wang, Z., Mao, Y., Xiong, C., & Yu, T. (2025). AgentTrek: Agent Trajectory Synthesis via Guiding Replay with Web Tutorials. Proceedings of the International Conference on Learning Representations (ICLR).
  5. Yang, J., Jimenez, C. E., Wettig, A., Lieret, K., Yao, S., Narasimhan, K., & Press, O. (2024). SWE-agent: Agent-Computer Interfaces Enable Automated Software Engineering. Advances in Neural Information Processing Systems (NeurIPS).

Building the Machine

Given a corpus of activity sequences, construction is a prefix tree, a merge on the incoming activity, then a prune of transitions seen exactly once unless they are a state’s only exit. There are no thresholds to tune, no number of clusters, no learning rate.

Step 1: Prefix Tree

Insert all activity sequences into a trie — each unique prefix becomes a distinct state. The prefix tree has perfect training fitness, replaying every training trace exactly. But it can have tens of thousands of states.

The trie gives every distinct prefix its own state, so it grows with total trace length rather than with behavior. Most of those states are visited once and memorize a suffix instead of capturing a reusable transition.

Step 2: Structural Merging

Merge every state whose incoming edge carries the same activity. Writing last(x)\mathrm{last}(x) for the activity on the edge into xx, the relation is x≡y  ⟺  last(x)=last(y)x \equiv y \iff \mathrm{last}(x) = \mathrm{last}(y), with the empty prefix as its own class. One pass, no recursion, and at most ∣A∣+1|\mathcal{A}|+1 classes, so the state count is bounded by the alphabet.

The quotient is the canonical order-1 abstraction: the finest deterministic finite automaton (DFA) in which the next state depends only on the current activity. It accepts a superset of the observed prefixes, and that over-approximation is what lets it replay traces it never saw. It is not the minimal DFA of the observed prefix language, which would be acyclic and could carry none of the loops below.

SWE-agent collapses to 25 states, one per activity plus the initial state, and still replays held-out traces at 0.999 fitness. Alergia, the strongest method that also learns from positive examples alone, needs 35 for the same corpus.

Prefix Tree to FSM Collapse
Watch a prefix tree collapse into a compact FSM. States reached by the same activity merge into one, in a single pass.

The Resulting FSM

The FSM M=(Q,A,δ,q0)\mathcal{M} = (Q, \mathcal{A}, \delta, q_0) encodes the agent’s behavioral topology. Recurring patterns become loops. And the state count tracks the number of distinct activities.

In the tau2-bench airline customer service agent at role level, a tool-call loop (assistant:tool_call to tool:text) dominates execution, with the conversational path through assistant:text as a separate branch. In a coding agent the search, edit, execute cycle accounts for most of the trace.

Explorable FSM Graphs
Select a dataset to explore its extracted FSM. Node size reflects visit frequency; edge thickness reflects transition frequency. Drag nodes to rearrange, scroll to zoom, drag the background to pan, and double-click to reset the view.

Open the FSM explorer for any of the twelve datasets in the live dashboard.

Theoretical Properties

The construction guarantees three properties.

Fitness preservation. Structural merging preserves training fitness: if a trace is accepted by the prefix tree, it’s accepted by the merged FSM, because merging only adds out-edges — each state carries the union of its merged transitions.

Compactness. The merged FSM is a compact directly-follows automaton: one state per activity, deterministic. Pruning the single-observation transitions is the one step that can cost fitness, and the replay numbers measure that cost directly. We recover this, not the generating automaton, which is impossible to identify from positive examples alone (Gold, 1967). But it’s enough for faithful replay and prediction.

Linear runtime. Prefix tree construction is O(∑iTi)O(\sum_i T_i), and structural merging is a partition refinement (Hopcroft et al., 2006) in O(∣QP∣⋅∣A∣)O(|Q_\mathcal{P}| \cdot |\mathcal{A}|). In practice all twelve datasets complete in under one second on a single CPU core.

The construction itself is classical (Daciuk et al., 2000). Bounded agent alphabets are new: they make the resulting compact automaton small enough — and dense enough per state — to be useful for the prediction and monitoring tasks that follow.

  1. Daciuk, J., Mihov, S., Watson, B. W., & Watson, R. E. (2000). Incremental Construction of Minimal Acyclic Finite-State Automata. Computational Linguistics, 26(1), 3–16.
  2. Gold, E. M. (1967). Language Identification in the Limit. Information and Control, 10(5), 447–474.
  3. Hopcroft, J. E., Motwani, R., & Ullman, J. D. (2006). Introduction to Automata Theory, Languages, and Computation (3rd ed.). Pearson.

Why the Machine Stays Small

A small alphabet alone doesn’t make a machine useful; an automaton can still be huge if the language is complex. And a huge automaton spreads its observations thinly (leaving every per-state statistic noisy). The FSM works as a substrate because it’s small, stable, and converges fast, so each state pools enough traces to estimate from. The prediction and monitoring chapters depend on that property, not the exact count.

It converges on a few percent of the data

Across random train/test splits the extracted state count stays within a few states of the full-data value, so the topology is a property of the agent, not of which traces you happened to sample. Replay fitness plateaus just as fast: within the first 1 to 10% of the training traces every dataset with a convergence run clears 0.95 fitness, and SWE-smith holds 0.9996 from the first 1%.

Two other methods back the count

The compactness isn’t an artifact of our particular merge rule: Alergia (Carrasco & Oncina, 1994), a statistical merge, lands within 1.0 to 6.0×\times of our own state count on every dataset, and a hidden Markov model (HMM) (Rabiner, 1989) given the same number of states achieves comparable fitness, though its states aren’t interpretable.

  1. Carrasco, R. C., & Oncina, J. (1994). Learning Stochastic Regular Grammars by Means of a State Merging Method. International Colloquium on Grammatical Inference, 139–152.
  2. Motwani, R., & Raghavan, P. (1995). Randomized Algorithms. Cambridge University Press.
  3. Rabiner, L. R. (1989). A Tutorial on Hidden Markov Models and Selected Applications in Speech Recognition. Proceedings of the IEEE, 77(2), 257–286.

Compression and Comparison

We compare against nine baselines: RPNI (Oncina & Garcı́a, 1992), EDSM (Lang et al., 1998), Alergia (Carrasco & Oncina, 1994) and k-Tails (Biermann & Feldman, 1972) from automata learning, run through AALpy (Muškardin et al., 2022); the HMM (Rabiner, 1989); the Alpha, Inductive and Heuristic miners from process mining (van der Aalst, 2016), run through PM4Py (Berti et al., 2019); and AWM, agent workflow extraction (Wang et al., 2024). All but AWM receive only the same positive training sequences, with no failure labels; AWM needs success labels, so it runs on the labeled datasets only.

How Much Smaller

Our FSMs achieve 15 to 3,036×\times compression over RPNI while replaying held-out traces at fitness of at least 0.997. The ratio grows with trace length and branching: 15×\times on WebArena (short web traces, where RPNI succeeds) up to 3,036×\times on GUI-Odyssey (Lu et al., 2025) (long, repetitive mobile-GUI traces, where RPNI’s prefix tree explodes to 21,255 states against our 7).

Compression Ratios
Each dataset's state count on a log scale: ours (dark slate) versus RPNI (light slate). The distance between the two dots is the compression, from 15x on WebArena to 3,036x on GUI-Odyssey, all at replay fitness of at least 0.997.

Compare all eight methods interactively in the baselines view, or watch structure stabilize in the convergence view.

Convergence and Stability

Replay fitness reaches its plateau well before the training set is exhausted: on SWE-agent it’s already at 0.985 within 1% of the training traces and settles at 0.996 by 10%, and the state count keeps inching up as rare command patterns appear. Structured tool-call domains converge fastest: SWE-smith holds 0.9996 from the first 1% of data. Open web and multi-agent traces take longer, with Mind2Web (Deng et al., 2023) needing 5% and Who&When (Zhang et al., 2025) 10% of their traces to clear 0.95 fitness.

Convergence Curves
Replay fitness as training traces accumulate, for the four datasets with incremental-convergence runs. The dashed marker shows where each first reaches 0.95 fitness.

Baselines at a Glance

Method Comparison
State count and fitness across five methods and twelve datasets. Our FSM holds the smallest state count among non-degenerate methods, at fitness within 0.003 of the best.

Precision

The FSM is more than a vocabulary: it rejects every random trace, and at least 99.9% of permuted traces that keep the activity set but scramble the order. Even single-symbol mutations — a substitution or an insertion or an adjacent swap — are blocked 77 to 100% of the time. RPNI — with its 382 states — accepts 75% of those same permuted traces on WebArena.

  1. Berti, A., van Zelst, S. J., & van der Aalst, W. (2019). Process Mining for Python (PM4Py): Bridging the Gap Between Process- and Data Science. https://arxiv.org/abs/1905.06169
  2. Biermann, A. W., & Feldman, J. A. (1972). On the Synthesis of Finite-State Machines from Samples of Their Behavior. IEEE Transactions on Computers, C–21(6), 592–597.
  3. Carrasco, R. C., & Oncina, J. (1994). Learning Stochastic Regular Grammars by Means of a State Merging Method. International Colloquium on Grammatical Inference, 139–152. back: 1, 2
  4. Deng, X., Gu, Y., Zheng, B., Chen, S., Stevens, S., Wang, B., Sun, H., & Su, Y. (2023). Mind2Web: Towards a Generalist Agent for the Web. Advances in Neural Information Processing Systems (NeurIPS).
  5. Lang, K. J., Pearlmutter, B. A., & Price, R. A. (1998). Results of the Abbadingo One DFA Learning Competition and a New Evidence-Driven State Merging Algorithm. International Colloquium on Grammatical Inference (ICGI), 1–12. back: 1, 2
  6. Lu, Q., Zhao, W., Jia, J., Ren, K., Lu, K., Han, J., Chen, Y., Zheng, J., Zhang, Z., & Ding, L. (2025). GUI-Odyssey: A Comprehensive Dataset for Cross-App GUI Navigation on Mobile Devices. Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition.
  7. Muškardin, E., Aichernig, B. K., Pill, I., Pferscher, A., & Tappler, M. (2022). AALpy: An Active Automata Learning Library. Innovations in Systems and Software Engineering, 18, 417–426.
  8. Oncina, J., & Garcı́a, P. (1992). Inferring Regular Languages in Polynomial Updated Time. Pattern Recognition and Image Analysis, 49–61. back: 1, 2
  9. Rabiner, L. R. (1989). A Tutorial on Hidden Markov Models and Selected Applications in Speech Recognition. Proceedings of the IEEE, 77(2), 257–286. back: 1, 2
  10. van der Aalst, W. M. P. (2016). Process Mining: Data Science in Action (2nd ed.). Springer. back: 1, 2
  11. Wang, Z. Z., Mao, J., Fried, D., & Neubig, G. (2024). Agent Workflow Memory. arXiv Preprint arXiv:2409.07429.
  12. Zhang, S., Yin, M., Zhang, J., Liu, J., Han, Z., Zhang, J., Li, B., Wang, C., Wang, H., Chen, Y., & Wu, Q. (2025). Which Agent Causes Task Failures and When? arXiv Preprint arXiv:2505.00212.

Prediction: Next Step and Failure

The same FSM state answers both questions an operator asks: what the agent will do next, and whether this run is heading for failure. Both read off the per-state transition distribution, which compactness makes reliable.

Next-Step Prediction

At each step the predictor estimates P(at∣context)P(a_t \mid \text{context}), scored by cross-entropy in bits via 5×\times5-fold cross-validation (CV). Conditioning on FSM state alone, with no learning beyond an order-1 Markov model, accounts for 83 to 99% of the total cross-entropy improvement on each dataset. The average drops to 0.93 bits, a 62% cut from the unigram baseline at 2.44 bits.

The cleanest test holds the predictor fixed and adds FSM state as a feature: under absolute discounting, FSM state conditioning adds +0.155 bits on average (0.580 vs 0.735) and helps on every one of six datasets, from +0.016 on SWE-agent to +0.364 on Mind2Web, whose branching web-action vocabulary gains most from knowing where in the workflow it is. Combining FSM state with a small learned model gives the best predictor in the study, at 0.73 bits.

Workflow Memory

The gain generalizes to the agent’s own LLM: feeding the current FSM state as context for choosing the next action beats Agent Workflow Memory (AWM) (Wang et al., 2024) on all eight ground-truth datasets, with six gaps significant at p<10−8p < 10^{-8}.

DatasetNAWMOursΔ
WebArena (Zhou et al., 2024)4,80065.581.2+15.7
SWE-smith (Yang et al., 2025)30074.7100.0+25.3
SWE-agent (Yang et al., 2024)1,20067.770.5+2.8
tau2-bench telecom (Barres et al., 2025)1,09528.545.6+17.1
tau2-bench retail (Barres et al., 2025)1,09552.965.1+12.2
tau2-bench airline (Barres et al., 2025)48056.557.3+0.8
ATBench60047.862.5+14.7
OSWorld (Xie et al., 2024)1,28655.070.7+15.7

The margin runs from +0.8 points on tau2-bench airline to +25.3 on SWE-smith, and four of the eight gaps clear 15 points. The retail row is the set the FSM context format was selected on; the other seven are held out, and the margin averaged over them is the larger of the two.

AWM extracts linear workflows from successful traces only, and it cannot represent cycles or branching.

The win is not automatic

Handing the LLM the full FSM, every state and transition, loses to AWM: 52.2% against 52.9% on tau2-bench retail. What wins, at 65.1%, is a minimal format: next-action probabilities plus a few top continuations from the current state. Finding that minimal context is itself part of the contribution, as AWM’s linear-workflow format was for AWM.

Context given to the LLM (tau2-bench retail)Top-1 %
No memory, just the trace so far27.6
Linear workflows from successful runs (AWM)52.9
Full machine: current state, every transition, the whole graph52.2
Full machine, plus multi-step continuations49.2
Full machine, from successful traces only50.3
Minimal: next-action probabilities and a few likely continuations65.1

Step through the workflow-memory comparison per dataset in the memory view.

Predicting Failure

Failure has mostly been studied after the fact: Who&When asks which agent and which step were to blame once a multi-agent run has already gone wrong (Zhang et al., 2025), and Trace treats the whole workflow as a differentiable graph to be optimised offline (Cheng et al., 2024). Ours is the earlier and cheaper question: with the run still going, does the machine already know?

Replay a trace through the FSM and read off per-state behavioral features (visit frequency, message-length statistics, error rate, early/late entropy drift) plus five cross-entropy anomaly features. A single gradient-boosted classifier on a fixed 80/20 split reaches held-out AUROC up to 0.94.

Raw fitness is useless here (AUROC near 0.50): successful and failed traces both replay perfectly. But the signal is in the per-state decomposition and in surprise: failing traces take low-probability transitions under the FSM.

The largest machine predicts best and the smallest predicts worst: the 43-state telecom agent tops out at 0.941, and the 10-state SWE-smith sits lowest. In between, size stops explaining the order. WebArena (Zhou et al., 2024) (0.903), AgentNet (X. Wang et al., 2025) (0.890) and SWE-agent (Yang et al., 2024) (0.799) all have 25 states and span a tenth of AUROC, and ATBench, the only safety-labeled benchmark, reaches 0.894 on 15 (0.864 ± 0.024 under repeated CV). Across all eight real-trace datasets the CV standard deviation stays in 0.012 to 0.031 — so these aren’t single-split artifacts.

Failure Prediction
Held-out AUROC across the nine labeled datasets, with the top predictive feature for each. The extremes track machine size; the middle does not.

Inspect per-state feature importances and failure modes in the failure view.

And the predictors are interpretable. On SWE-agent the single strongest feature is whether the trace reaches the submit state: 94.8% of successes get there, only 55.7% of failures do. And this isn’t a length proxy — structural features score 0.790 against 0.659 for trace length alone. Successful runs touch only 9 of 25 states along a focused search, edit, submit path — and failures spread across all 25 (Jaccard overlap 0.206).

Runtime Monitor

Deployed online (H. Wang et al., 2026), a two-rule monitor fires when the cycle-rate exceeds 0.778 and the unique-state count clears a warm-up floor. On all four evaluated datasets it reaches rank-AUROC 0.66 at the 25% trace checkpoint, against 0.5 for a flag-everything baseline by construction. On SWE-agent it fires at 32% of trace completion, stopping the run with about two-thirds of its compute unspent, at precision 85.9% and recall 95.5%. By the halfway checkpoint, FSM features alone already recover 92% of the full-trace signal.

Why rank-AUROC, not F1

When 84% of runs fail, flagging everything scores a high F1 by default (0.914, versus the monitor’s 0.904). The point of a monitor isn’t whether to flag but when. Rank-AUROC measures exactly that early-warning utility. The pipeline is FSM replay only, 0.006 ms per step, with no ML model in the loop.

Watch the monitor flag a failing run in real time in the monitor view.

  1. Barres, V., Dong, H., Ray, S., Si, X., & Narasimhan, K. (2025). τ2-Bench: Evaluating Conversational Agents in a Dual-Control Environment. arXiv Preprint arXiv:2506.07982. back: 1, 2, 3
  2. Cheng, C.-A., Nie, A., & Swaminathan, A. (2024). Trace is the New AutoDiff: Unlocking Efficient Optimization of Computational Workflows. arXiv Preprint arXiv:2406.16218.
  3. Wang, H., Poskitt, C. M., & Sun, J. (2026). AgentSpec: Customizable Runtime Enforcement for Safe and Reliable LLM Agents. Proceedings of the International Conference on Software Engineering (ICSE).
  4. Wang, X., Wang, B., Lu, D., Yang, J., Xie, T., Wang, J., Deng, J., Guo, X., Xu, Y., Wu, C. H., Shen, Z., Li, Z., Li, R., Li, X., Chen, J., Boyuan, Z., Li, P., Lei, F., Cao, R., … Yu, T. (2025). OpenCUA: Open Foundations for Computer-Use Agents. arXiv Preprint arXiv:2508.09123.
  5. Wang, Z. Z., Mao, J., Fried, D., & Neubig, G. (2024). Agent Workflow Memory. arXiv Preprint arXiv:2409.07429.
  6. Xie, T., Zhang, D., Chen, J., Li, X., Zhao, S., Cao, R., Hua, T. J., Cheng, Z., Shin, D., Lei, F., Liu, Y., Xu, Y., Zhou, S., Savarese, S., Xiong, C., Zhong, V., & Yu, T. (2024). OSWorld: Benchmarking Multimodal Agents for Open-Ended Tasks in Real Computer Environments. The Thirty-Eight Conference on Neural Information Processing Systems Datasets and Benchmarks Track. https://openreview.net/forum?id=tN61DTr4Ed
  7. Yang, J., Jimenez, C. E., Wettig, A., Lieret, K., Yao, S., Narasimhan, K., & Press, O. (2024). SWE-agent: Agent-Computer Interfaces Enable Automated Software Engineering. Advances in Neural Information Processing Systems (NeurIPS). back: 1, 2
  8. Yang, J., Lieret, K., Jimenez, C. E., Wettig, A., Khandpur, K., Zhang, Y., Hui, B., Press, O., Schmidt, L., & Yang, D. (2025). SWE-smith: Scaling Data for Software Engineering Agents. Proceedings of the Annual Conference on Neural Information Processing Systems (NeurIPS), Datasets & Benchmarks Track.
  9. Zhang, S., Yin, M., Zhang, J., Liu, J., Han, Z., Zhang, J., Li, B., Wang, C., Wang, H., Chen, Y., & Wu, Q. (2025). Which Agent Causes Task Failures and When? arXiv Preprint arXiv:2505.00212.
  10. Zhou, S., Xu, F. F., Zhu, H., Zhou, X., Lo, R., Sridhar, A., Cheng, X., Bisk, Y., Fried, D., Alon, U., & Neubig, G. (2024). WebArena: A Realistic Web Environment for Building Autonomous Agents. Proceedings of the International Conference on Learning Representations (ICLR). back: 1, 2

Discussion

When Does It Work?

A system’s action vocabulary is bounded, so its behavioral topology is bounded too, and a compact, stable automaton is the natural summary; beating four bespoke pipelines with it is a consequence, not a design goal.

The topology is also model-invariant: a single FSM achieves perfect fitness across four large language models on the same task, so what shapes it is the system, the tools and prompts and task distribution, more than the model driving it. It survives a coarser ϕ\phi too: the default level matches or beats role-only on ten of the twelve datasets, moving more only where role-only collapses to three symbols or fewer.

A 25-state machine can be read and checked by a person; the trie it came from cannot. That auditability is a dividend of the bound on the state count, which is the alphabet size plus one.

Three lines of work touch this one.

State machines placed around agents. StateFlow runs an agent through a state machine somebody wrote by hand (Wu et al., 2024), a definite finite automaton can be bolted onto a chatbot pipeline the same way (Sun et al., 2024), FlowMind builds a workflow from an API surface (Zeng et al., 2024), and AFlow and ADAS search over agentic workflow designs (Hu et al., 2024; Zhang et al., 2025), while MetaAgent assembles a whole multi-agent system out of one (Chen et al., 2025). In every one of them the machine is an input — here it is an output, recovered from traces the agent had already produced.

Experience kept as memory. Agent Workflow Memory induces reusable routines from past trajectories (Wang et al., 2024), Experience-to-Strategy trains a graph of them (Xia et al., 2025), ExpeL distils insights out of them (Zhao et al., 2024), and Voyager accumulates a skill library (G. Wang et al., 2023). Each of those keeps fragments of behavior. The automaton keeps the topology instead.

Automata learned from observation. Model learning turns a black-box system into a state machine (Vaandrager, 2017), Weiss and colleagues pull one out of a recurrent network with membership and equivalence queries (Weiss et al., 2018), DeepDFA learns one by gradient (Umili & Capobianco, 2024), prompt chaining extracts one from a flow description (Wael et al., 2025), and AALpy packages the classical algorithms (Muškardin et al., 2022). Process mining, which discovers process models from event logs, is the closest classical neighbour: van der Aalst’s textbook treatment (van der Aalst, 2016), its re-thinking for the agent era (Berti et al., 2024), an evaluation of large language models at the task (Berti, Kourani, et al., 2024), and skill learning from mined processes (Redis et al., 2024). This one works from a different input: positive traces only, no oracle to query, and an alphabet small enough that one merge suffices.

Limitations

The FSM accepts the directly-follows closure of the observed traces, not the agent’s generating language: like any trace-replay method, it cannot tell an adversarial trace that preserves the observed transition statistics from a legitimate one. The extraction function ϕ\phi needs a small amount of per-domain knowledge, and fully automatic discovery of it is future work. Only the extremes of machine size track prediction quality: the 10-state SWE-smith is lowest and the 43-state telecom highest, while three datasets at 25 states span a tenth of AUROC, so size does not order the middle. Extending the workflow-memory comparison beyond AWM to other memory-injection methods is future work.

For agents with much larger action spaces or weaker sequential structure, the construction still applies but stops being compact — and the per-state observation density that drives every result above would degrade with it.

Broader Impact

Compact FSM representations make agent behavioral structure inspectable — and that supports safety auditing. The same analysis could be misused to find exploitable behavioral patterns, so deployment should restrict FSM analysis to authorized auditing.

Conclusion

A finite-state machine — built in milliseconds from positive examples with one classical merge — does the work of four bespoke learned pipelines. The same 7-to-43-state object serves all four.

  1. Berti, A., Kourani, H., Hafke, H., Li, C.-Y., & Schuster, D. (2024). Evaluating Large Language Models in Process Mining: Capabilities, Benchmarks, Evaluation Strategies, and Future Challenges. arXiv Preprint arXiv:2403.06749.
  2. Berti, A., Maatallah, M., Jessen, U., Sroka, M., & Ghannouchi, S. A. (2024). Re-Thinking Process Mining in the AI-Based Agents Era. arXiv Preprint arXiv:2408.07720.
  3. Chen, Z., Wu, Y., Li, Z., & Ji, H. (2025). MetaAgent: Automatically Constructing Multi-Agent Systems Based on Finite State Machines. Proceedings of the International Conference on Machine Learning (ICML).
  4. Hu, S., Lu, C., & Clune, J. (2024). ADAS: Automated Design of Agentic Systems. arXiv Preprint arXiv:2408.08435.
  5. Muškardin, E., Aichernig, B. K., Pill, I., Pferscher, A., & Tappler, M. (2022). AALpy: An Active Automata Learning Library. Innovations in Systems and Software Engineering, 18, 417–426.
  6. Redis, A. C., Fani Sani, M., Zarrin, B., & Burattin, A. (2024). Skill Learning Using Process Mining for Large Language Model Plan Generation. International Conference on Process Mining (ICPM).
  7. Sun, Y., Hu, J., Cheng, W., & Chen, H. (2024). Chatbot Meets Pipeline: Augment Large Language Model with Definite Finite Automaton. arXiv Preprint arXiv:2402.04411.
  8. Umili, E., & Capobianco, R. (2024). DeepDFA: Automata Learning through Neural Probabilistic Relaxations. Proceedings of the European Conference on Artificial Intelligence (ECAI).
  9. Vaandrager, F. (2017). Model Learning. Communications of the ACM, 60(2), 86–95.
  10. van der Aalst, W. M. P. (2016). Process Mining: Data Science in Action (2nd ed.). Springer.
  11. Wael, F., Maklad, Y., Hamdi, A., & Elsersy, W. (2025). An Agentic Flow for Finite State Machine Extraction using Prompt Chaining. arXiv Preprint arXiv:2507.11222.
  12. Wang, G., Xie, Y., Jiang, Y., Mandlekar, A., Xiao, C., Zhu, Y., Fan, L., & Anandkumar, A. (2023). Voyager: An Open-Ended Embodied Agent with Large Language Models. arXiv Preprint arXiv:2305.16291.
  13. Wang, Z. Z., Mao, J., Fried, D., & Neubig, G. (2024). Agent Workflow Memory. arXiv Preprint arXiv:2409.07429.
  14. Weiss, G., Goldberg, Y., & Yahav, E. (2018). Extracting Automata from Recurrent Neural Networks Using Queries and Counterexamples. Proceedings of the International Conference on Machine Learning (ICML).
  15. Wu, Y., Yue, T., Zhang, S., Wang, C., & Wu, Q. (2024). StateFlow: Enhancing LLM Task-Solving through State-Driven Workflows. arXiv Preprint arXiv:2403.11322.
  16. Xia, S., Xu, Z., Chai, J., Fan, W., Song, Y., Wang, X., Yin, G., Lin, W., Zhang, H., & Wang, J. (2025). From Experience to Strategy: Empowering LLM Agents with Trainable Graph Memory. arXiv Preprint arXiv:2511.07800.
  17. Zeng, Z., Watson, W., Cho, N., Rahimi, S., Reynolds, S., Balch, T., & Veloso, M. (2024). FlowMind: Automatic Workflow Generation with LLMs. arXiv Preprint.
  18. Zhang, J., Xiang, J., Yu, Z., Teng, F., Chen, X., Lu, J., Zhong, M., Zhang, M., Wang, Y., Li, Q., & Hong, H. (2025). AFlow: Automating Agentic Workflow Generation. Proceedings of the International Conference on Learning Representations (ICLR).
  19. Zhao, A., Huang, D., Xu, Q., Lin, M., Liu, Y.-J., & Huang, G. (2024). ExpeL: LLM Agents Are Experiential Learners. Proceedings of the AAAI Conference on Artificial Intelligence.