Skip to main content

Overview

State machines map structured inputs to predefined outcomes instead of generating open-ended text. MTP supports both single-state and multi-state instructions, and CSV training can create either form. See the CSV Overview section for CSV training documentation.

What Is a State Machine?​

In MTP, a state machine selects from a fixed set of allowed outcomes. This is useful when your model should classify, route, or trigger behavior using known state values such as intent labels.

State machine protocols:

  • Use structured input TokenSets and predefined output states
  • Do not use final tokens for generated text; the final is always <NON>
  • Do not allow numeric outputs
  • Can use one output state per sample or one state per output key

Single-State and Multi-State​

A single-state instruction selects one state for each input. This is represented by StateMachineInstruction.

A multi-state instruction selects one state for each declared output key. This supports independent classifiers such as Intent and Sentiment in the same sample and is represented by MultiClassifierInstruction.

All CSV protocols are state machines. The exact Input,Output,Reference shape creates a single-state instruction, while additional output columns create a multi-state instruction.

Enabling State Machines​

State machines are disabled by default for general MTP protocols. Enable them when creating your protocol:

protocol = mtp.Protocol(
name="my_state_machine",
inputs=1,
encrypt=True,
state_machine=True
)

Where States Are Stored​

When state_machine=True, the template includes state-machine metadata:

  • state_machine: set to true
  • Single-state instructions use a list of allowed state strings
  • Multi-state instructions use a state map keyed by output column or classifier name

See Template for the fields in the template and how they are structured.

Next Steps​

  • Use the Single-State section for StateMachineInstruction and StateMachineInput.
  • Use the Multi-State section for MultiClassifierInstruction and independent output state maps.
  • Review the CSV Overview for CSV column shapes and inheritance rules.