FiniteStateMachineTask
Model concepts using finite state machine analysis to identify states, map transitions, and validate system logic.
Category: Reasoning
Model: GPT-4 Preferred
Output: Mermaid + Markdown
⚙️ TaskConfig.json
{
"concept_to_model": "User Authentication",
"domain_context": "Web Security",
"identify_edge_cases": true,
"validate_properties": true,
"input_files": ["src/auth/*.kt"],
"generate_test_scenarios": true
}
→
👁️ Generated State Diagram
stateDiagram-v2
[*] --> Unauthenticated
Unauthenticated --> Authenticating : login_attempt
Authenticating --> Authenticated : success
Authenticating --> Locked : max_retries_exceeded
Authenticated --> [*] : logout
Locked --> Unauthenticated : reset_timeout
Authenticated --> Authenticating : session_expired
✔ 5 States Identified
✔ 6 Transitions Mapped
✔ Properties Validated (Deterministic)
✔ 6 Transitions Mapped
✔ Properties Validated (Deterministic)
Live Results Showcase
Explore actual artifacts generated by this task, including the full Markdown analysis and Mermaid source files.
Configuration Parameters
| Field | Type | Description |
|---|---|---|
concept_to_model* |
String |
The concept, system, or process to model as a finite state machine. |
domain_context |
String |
Domain or context for the FSM (e.g., 'authentication system'). |
initial_states |
List<String> |
Initial state(s) to consider for the state discovery. |
known_events |
List<String> |
Known events or triggers that cause state transitions. |
identify_edge_cases |
Boolean |
Whether to identify edge cases and error states. Default: true. |
validate_properties |
Boolean |
Whether to validate state machine properties (determinism, completeness, reachability). Default: true. |
generate_test_scenarios |
Boolean |
Whether to generate test scenarios for state transitions. Default: true. |
input_files |
List<String> |
Glob patterns for source code to be used as input for the task. |
Task Process Lifecycle
- 1. State Identification: Analyzes the concept and reference files to define states, invariants, and entry/exit conditions.
- 2. Transition Mapping: Identifies events, guard conditions, and actions that move the system between states.
-
3. Diagram Generation:
Produces a
stateDiagram-v2Mermaid block for visual documentation. - 4. Edge Case Analysis: (Optional) Detects invalid transitions, missing paths, and race conditions.
- 5. Formal Validation: (Optional) Evaluates the FSM for determinism, completeness, reachability, and liveness.
- 6. Test Scenario Generation: (Optional) Creates "Happy Path" and "Error Path" sequences for QA validation.
Direct Orchestration
Use this when adding the task to a custom agentic workflow.
Kotlin
val task = FiniteStateMachineTask(
orchestrationConfig = config,
planTask = FiniteStateMachineTaskExecutionConfigData(
concept_to_model = "Payment Gateway",
domain_context = "E-commerce",
input_files = listOf("src/payments/**/*.kt"),
validate_properties = true
)
)
Embedded Execution (Headless)
Invoke as a standalone tool using the UnifiedHarness for CI/CD or CLI tools.
Embedded Example
import com.simiacryptus.cognotik.plan.TaskType
import com.simiacryptus.cognotik.plan.tools.reasoning.FiniteStateMachineTask.Companion.FiniteStateMachine
import com.simiacryptus.cognotik.plan.tools.reasoning.FiniteStateMachineTask.FiniteStateMachineTaskExecutionConfigData
harness.runTask(
taskType = FiniteStateMachine,
typeConfig = TaskTypeConfig(name = "FsmAnalyzer"),
executionConfig = FiniteStateMachineTaskExecutionConfigData(
concept_to_model = "Order Lifecycle",
domain_context = "Logistics",
generate_test_scenarios = true
),
workspace = File("./project-dir"),
autoFix = true
)
Prompt Segment
The following logic is injected into the LLM context:
FiniteStateMachine - Model concepts using finite state machine analysis
** Specify the concept, system, or process to model
** Optionally provide initial states and known events
** Identify all possible states and transitions
** Detect edge cases and error states
** Validate FSM properties (determinism, completeness, reachability)
** Generate test scenarios for state transitions
** Produces state diagram and transition table
** Useful for:
- System design and validation
- Understanding complex workflows
- Identifying missing requirements
- Test case generation
- Protocol analysis