DEV Community

professor-js
professor-js

Posted on Edited on

Restraint as Architecture: A Zero-Dependency State Machine for Agents

Most autonomous agent setups start as an unconstrained while loop around a model and tools. In practice, that tends to break down in three familiar ways:

  1. Runaway loops & idle polling: Re-running failing tool calls or busy-polling unchanged state until the budget is gone.
  2. Amnesia on restart: Crashes or timeouts wipe active subproblems and budgets—or worse, naive transcript replays risk repeating non-idempotent side effects.
  3. Unstructured concurrency: Background workers mutating shared state without coordination, producing race conditions and non-reproducible traces.

FTR.cc ("Three Problems. Three Threads. One Process.") approaches this as a single-process cooperative state machine in Python 3.10+ (standard library only, GNU GPLv3) rather than a prompt wrapper.

How It's Structured

  • Three bounded proposal generators:
    • Thread 0 (Present): Reactive event/timer handling that schedules future checks instead of busy-polling.
    • Thread X (Past): Episodic memory and consolidation that turns repeated failures into policy rules (avoid:<action>).
    • Thread hmzs26 (Future): Bayesian hypothesis tracking and bounded best-first planning aimed at high-information-gain steps.
  • Marginal-value scheduler & true idle (theta_wake): Scores candidate actions by utility, urgency, information gain, novelty, confidence, cost, and fixation penalty—and enters LIGHT_IDLE, DEEP_IDLE, or HIBERNATE when nothing clears theta_wake (checked before starvation credit so fairness doesn't invent busywork).
  • Hash-chained WAL & atomic snapshots: Logs intent before external side effects and result after, using deterministic idempotency keys and torn-tail truncation on crash recovery.

Run It Yourself (Zero Dependencies)

git clone https://github.com/hmzs26/FTR.cc.git
cd FTR.cc

# Unit & fault-injection tests
python3 -m unittest discover -s tests -v

# Synthetic benchmarks & ablations
python3 experiments/run_experiments.py
Enter fullscreen mode Exit fullscreen mode

In the synthetic benchmarks (details in paper/FTR_cc_Unified_Paper.md), the reference runtime in src/ftr.py handles delayed results (t=60) with 1 poll and 1 scheduled check instead of dozens of wasted polls, halts unfixable tool errors after 2 attempts via fixation penalty, and preserves 41/41 identical state hashes across 6 WAL crash-injection points with 0 duplicate side effects.

Honest Scope & Where Feedback Helps Most

Right now the benchmarks run in a deterministic simulated environment rather than wired to live stochastic LLM APIs, and operational restraint isn't a substitute for semantic/alignment guardrails.

I'd love honest feedback on:

  • Where the marginal-value / theta_wake sleep gate could still over-sleep or miss urgent work under tricky inputs.
  • Any WAL / crash-recovery edge cases you spot in src/ftr.py or tests/test_ftr.py.
  • Live LLM adapter trade-offs (especially content-addressed caching and token cost modeling) as a next step.

  • Repo: https://github.com/hmzs26/FTR.cc

Top comments (0)