State Module Overview
The State Module implements a YAML-configurable state machine that manages conversation flow and agent behavior in ARKOS.Core Concepts
The State Module provides a declarative way to define conversation flows using YAML configuration files, with automatic transition handling based on context.
What is a State?
A state represents a distinct phase in the conversation or agent processing pipeline. Each state:- Has a unique name
- Defines specific behavior when active
- Specifies possible transitions to other states
- Can be marked as terminal (ending the flow)
Architecture
State Class
The baseState class that all states extend:
AgentState Enum
Predefined states available in the system:StateHandler
Manages the state machine lifecycle and transitions:YAML Configuration
Basic State Graph
Transition Format
Transitions use a list of names corresponding to the next stateState Execution Flow
Integration with Agent
The Agent uses StateHandler for flow control:Transition Selection
When multiple transitions are possible, the LLM chooses:Custom State Types
Creating a Custom State
(NOTE: all states must be registered with @register_state and follow state_[name].py convention)
Tool State Example
State Types Reference
Best Practices
State Design Guidelines
- Single Responsibility: Each state should have one clear purpose
- Clear Transitions: Define unambiguous transition conditions
- Terminal States: Ensure all paths eventually reach a terminal
- Descriptive Names: Use clear, action-oriented state names
YAML Configuration Tips
Debugging States
Logging State Transitions
Common Issues
State not transitioning
State not transitioning
Check that
check_transition_ready() returns True:Wrong state selected
Wrong state selected
Improve transition descriptions for better LLM selection:
Infinite loop
Infinite loop
Ensure there’s always a path to a terminal state and MAX_ITER limit is respected.
Example: Complete State Graph
Next Steps
Implementation Details
Deep dive into state implementation
Agent Module
Learn about agent orchestration
Memory Module
Explore memory integration
Model Module
Understand LLM integration