Skip navigation
don't use loops, design state machines
0:00 / 1:35

don't use loops, design state machines

David

@dzhng15K followers

Visit on X
1,350 likesDownloadOriginal post

222,122 views

don't use loops, design state machines

60 Comments

Comments from the original post on X (Twitter)

  • David's profile picture

    @dzhng

    do this today at

    21 likes

  • David K 🎹's profile picture

    @DavidKPiano

    What does the state machine for this example look like?

    18 likes

  • David's profile picture

    @dzhng

    My version actually don't use a full deterministic state machine, I want to keep the flexibility of AI with minimal guardrails:

    3 likes

  • Ilko Kacharov's profile picture

    @kachar136

    Hot take: it's not loops vs state machines, it's both. The state machine defines what "done" looks like; the loop is the engine that grinds until it gets there. No loop = agent stalls mid-task. No state machine = it loops forever toward nothing. Winners design both.

    17 likes

  • David's profile picture

    @dzhng

    Agreed, but that's not catchy and doesn't go viral 😂

    8 likes

  • Brian Via's profile picture

    @BrianVia

    We’re inventing computer science from first principles

    16 likes

  • David's profile picture

    @dzhng

    😂 just slowly moving up the ladder of abstraction

    5 likes

  • David's profile picture

    @dzhng

    A loop is just a state machine with 2 states 😅

    19 likes

  • David's profile picture

    @dzhng

    😂

  • patark's profile picture

    @orbofweed

    sir this is a kanban board /s

    2 likes

  • duet's profile picture

    @duetchat

    🪩🪩🪩

    2 likes

  • Daniel's profile picture

    @dcolinmorgan

    🤯🤯🤯this looks insanely powerful! 2026 -- what a year 🚀🚀 reworking stack for 3rd time in 10 days 😵‍💫

    2 likes

  • David's profile picture

    @dzhng

    Give it a try at and tell me how it goes! Happy to give you some free credits :)

    1 like

  • Jason Szesze's profile picture

    @JasonSzesze

    Sweet @duetchat

    2 likes

  • David's profile picture

    @dzhng

    @duetchat Niceeeee

  • Mustafa Kirac's profile picture

    @muskirac

    It's n8n all over again 🤔

    2 likes

  • David's profile picture

    @dzhng

    Na, it's not a workflow engine actually, it's just the bare minimum guardrails. All workflow logic is done by agent / codegen

    1 like

  • Sense Noped Out's profile picture

    @SenseNopedOut

    this is what he meant. same same

    1 like

  • David's profile picture

    @dzhng

    yup agreed. just adding a tangible example

    1 like

  • Rob Schaper's profile picture

    @robschaper

    State machines can be designed to run in a loop, they can also act like a DAG with an outcome certain. For example, you can have four state machines in a loop, made of four DAGs, each run updates an S3 bucket, which has a trigger to run the next state machine, etc... Cheers.

    1 like