TL;DR
This paper introduces ChatFSM, an LLM-based agent designed to help robotics developers modify Finite State Machines (FSMs) using natural language instructions. By evaluating the tool on real-world robotics code, the authors demonstrate that LLMs can accurately execute complex structural modifications to FSMs in a fraction of the time it takes a human developer.
What Problem Does This Paper Address?
Finite State Machines (FSMs) are a cornerstone of robotics software engineering. They provide a clear, deterministic structure for managing complex robot behaviors—such as sequencing the steps to navigate a room, open a door, or pick up an object.
However, as robotic systems grow more sophisticated, their FSMs become massive and intricate. Manually updating these state machines—whether adding a new fail-safe state, deleting obsolete transitions, or rewiring control flows—is a tedious, time-consuming, and error-prone process. Developers must carefully trace logic across multiple files to avoid breaking system behavior. This paper investigates a practical question: Can Large Language Models (LLMs) automate these structural FSM modifications directly from natural language prompts?
Methods
The authors developed ChatFSM, an interactive tool that pairs an LLM with an automated visualization and evaluation pipeline. When a developer inputs FSM code alongside a natural language request (e.g., "Add a state called..."), ChatFSM generates the modified code.
To rigorously evaluate ChatFSM's accuracy without tedious manual code reviews, the authors built a sophisticated multi-agent evaluation framework:
- filter_fsm Agent: Extracts only the core FSM structure (states, transitions, and conditions) from raw Python code, stripping away irrelevant implementation details.
- extract_fsm Agent: Converts the isolated FSM code into a standardized JSON format.
- summarize_changes Agent: Translates historical code changes into detailed natural language instructions to simulate realistic developer requests.
- summarize_diff Agent: Compares the JSON of the LLM's modified FSM against the human-authored ground truth to pinpoint discrepancies.
- get_context Agent: Utilizes Retrieval-Augmented Generation (RAG) to pull relevant code context from the broader repository, testing whether extra codebase visibility boosts LLM accuracy.
The framework was tested using two prominent models: GPT-4o and LLaMA-3.1-70b.
Datasets
To ensure the evaluation reflected real-world engineering challenges, the authors bypassed synthetic benchmarks. Instead, they curated a dataset from the 9-year version control history of the Eindhoven University of Technology’s RoboCup@Home team repository.
Out of more than 13,000 Python commits, they isolated 87 parent-child code pairs containing FSMs. They filtered these down to 6 distinct pairs featuring significant structural modifications (e.g., replacing states, rewiring multiple transitions, and altering logic conditions) across tasks like human detection, navigation, and object manipulation.
Key Insights and Ideas
- LLMs are Highly Capable FSM Architects: Both GPT-4o and LLaMA-3.1-70b demonstrated a remarkable ability to parse state machine logic and correctly execute complex structural edits, such as removing five states and simultaneously adding ten transitions.
- The RAG Context Trap: Interestingly, simply turning on standard RAG did not improve performance. The automated RAG agent retrieved internal state implementation details rather than high-level transition logic. This reveals an important nuance: for code modification tasks, the granularity and relevance of retrieved context matter far more than the sheer volume of information.
- Hallucinations are Context-Driven: When the models did make an error (hallucinating a transition condition name), it wasn't due to a lack of reasoning capability, but rather a lack of information. Manually supplying the missing class definition to the prompt completely eliminated the error.
Key Results
The performance of ChatFSM was evaluated based on structural correctness and processing speed:
- Correctness: Across the 6 real-world test cases, both models achieved perfect structural alignment (No Diff) on 5 out of 6 pairs. On the remaining pair, both models initially introduced a minor condition name error (Small Diff). Once the missing context was provided, both models achieved 100% perfect replication of the human developer's code.
- Speedup: ChatFSM delivered massive efficiency gains. While a human developer took an average of 164 seconds to implement these changes manually, LLaMA-3.1-70b completed the tasks in a stunning 3.7 seconds, and GPT-4o finished in 59.4 seconds.
Limitations and Future Work
While the results are highly promising, the authors note several limitations:
- Structure vs. Implementation: ChatFSM successfully modifies the high-level FSM architecture (the "skeleton"), but it does not yet generate the underlying functional code that executes inside each individual state.
- Evaluation Scale: The dataset was limited to 6 structural modification pairs from a single FSM library (
smach). Testing across more diverse FSM frameworks and larger datasets is required to prove generalizability. - Dependency on Clear Context: Real-world code repositories often suffer from terse commit messages and sparse documentation, which can hinder an LLM's ability to accurately infer developer intent. Future work will focus on improving contextual retrieval mechanisms to handle messy, real-world codebases more effectively.
Summary updated