Skip to main content

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 base State 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 state

State 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

  1. Single Responsibility: Each state should have one clear purpose
  2. Clear Transitions: Define unambiguous transition conditions
  3. Terminal States: Ensure all paths eventually reach a terminal
  4. Descriptive Names: Use clear, action-oriented state names

YAML Configuration Tips

Debugging States

Logging State Transitions

Common Issues

Check that check_transition_ready() returns True:
Improve transition descriptions for better LLM selection:
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