Examples / Standard Library / State Management

State Management

Has Specs

Demonstrates state operations in Tactus workflows. This example shows: - Initializing state with metatable syntax (`state.key = value`) - Using `State.increment()` for atomic counter operations - Reading state values for output and validation - Tracking workflow progress with state variables - State assertions in specifications

Source Code

-- State Management Example
-- Demonstrates setting, getting, and incrementing state values

-- No agents are needed for this example.

-- Procedure with outputs defined inline

Procedure {
    output = {
            success = field.boolean{required = true, description = "Whether the workflow completed successfully"},
            message = field.string{required = true, description = "Status message"},
            count = field.number{required = true, description = "Final count of processed items"},
    },
    function(input)

    Log.info("Starting state management example")

        -- Initialize state (metatable syntax)
        state.items_processed = 0

        -- Process items and track count
        for i = 1, 5 do
          State.increment("items_processed")
          Log.info("Processing item", {number = i})
        end

        -- Retrieve final state (metatable syntax)
        local final_count = state.items_processed
        Log.info("Completed processing", {total = final_count})

        return {
          success = true,
          message = "State management example completed successfully",
          count = final_count
        }

    -- BDD Specifications
    end
}

Specification([[
Feature: State Management
  Demonstrate state operations in Tactus workflows

  Scenario: State operations work correctly
    Given the procedure has started
    When the procedure runs
    Then the procedure should complete successfully
    And the state items_processed should be 5
    And the output success should be True
    And the output count should be 5
]])

Quick Start

Run the example:

$tactus run 03-standard-library/01-state-management.tac

Test with mocks:

$tactus test 03-standard-library/01-state-management.tac --mock

View source on GitHub →

Explore more examples

Learn Tactus through practical, runnable examples organized by topic.

Part of the Anthus Platform
Tactus icon

Tactus

Tactus is a programming language and runtime for durable AI agent procedures with checkpointing, sandboxing, and built-in human-in-the-loop controls.

PART OF

The Anthus Platform

Solve complex business problems with AI and ML using a proven, reusable technology stack. These interoperable building blocks give our solutions a stronger operational foundation: durable procedures, MLOps control loops, workload orchestration, knowledge systems, observability, and programmable media workflows.

Plexus

MLOps platform for agent evaluation and iteration.

Tactus

Durable runtime for agent procedures.

Korporus

Agent operating system and federated shell.

Biblicus

Corpus analysis for extraction and retrieval.

Babulus

Marketing automation built around VideoML.

Kanbus

Durable multi-agent task management.

Caducus

Monitoring, alerts, and operator support.

Free and open-source softwareDesigned cybernetically by Ryan Porter
Contact us

How can we help?

GitHub

Browse the code.

LinkedIn

Company updates.

Discord

Join the chat.