# State Machine Approach

### What is a State Machine?

A State Machine is a workflow layout consisting of a finite number of pre-defined states and transitions between these states.

At any point throughout the execution, based on the external inputs and verified conditions, the workflow can be in only one of the states.

Don't think about State Machine like a workflow layout used only in automation. Some examples from your daily life were designed also with State Machine principles in mind: air-condition, elevator, traffic light, or vending machines.

### What are the advantages?

* Transitions between states are well defined and offer flexibility to the workflow;
* While simple use cases having academic or demo purpose can be resolved with if statements, switch, or loops (for, for each, while, do-while), the state machine can accommodate real-life processes that are more complex and / or continuous.
* State Machine eases the coverage of all the possible cases/transitions.

### Rules for a successful State Machine

* Must contain a start state and an end state
* Every state must be linked at least to another state
* If a state is linked to 2 or more states, they must have a condition based on which the robot can know what is the nest state.

### Types of Transitions

1\. Normal Transition- the standard transition between 2 states

2\. Exception State - can be used to implement a business or application exception; you can think about it like a Try Catch from programming.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.tailent.com/getting-started/state-machine-approach.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
