Skip navigation
One underrated benefit of declarative, event-based state management:
0:00 / 0:27

One underrated benefit of declarative, event-based state management:

David K 🎹

@DavidKPiano90K followers

Visit on X
178 likesDownloadOriginal post

20,747 views

One underrated benefit of declarative, event-based state management: It turns your app logic into something LLMs can use *directly*. Transitions + schemas become tool calls automatically. The agent doesn’t mutate state; it sends events the app already understands.

24 Comments

Comments from the original post on X (Twitter)

  • Alem Tuzlak 🇧🇦's profile picture

    @AlemTuzlak

    TanStack AI agrees with you!

    7 likes

  • Devin Jameson's profile picture

    @devinjameson

    David we should talk.

    7 likes

  • David K 🎹's profile picture

    @DavidKPiano

    Very cool. Some notes (love what Foldkit is doing btw): - If schemas are part of the contract, you should be able to do something like this without having to set up MCP; just feed it directly to the agent: - Event/message schema is only part of the story; context schema + emitted events/effect schema (what can the app emit? what effects will the app execute?) are also important - Something like store.can is huge: you want the agent to check if sending a message will have any effect, or is even allowed - State machines also bring this to a new level: "here's all the possible messages" can become "here's all the possible messages *in this state*" - Eventually, sending the entire app logic to an agent will enable lots of cool things; messages only are not enough (I'm sure you've thought of this too)

    5 likes

  • Devin Jameson's profile picture

    @devinjameson

    Many thanks for the feedback!

    2 likes

  • Rohan's profile picture

    @proxy_vector

    This is the bridge a lot of agent demos miss. If the app already exposes valid events and transitions, the model stops inventing side effects and starts operating inside guardrails the system understands.

    4 likes

  • David K 🎹's profile picture

    @DavidKPiano

    You get it!

    2 likes

  • Hassan Hayat 🔥's profile picture

    @TheSeaMouse

    in python, I push my agents to specify everything as explicit state machines with states, transitions, and effects all spelled out. it's easier for the model to mine the logs after the fact to figure out where the bugs are and what it modeled incorrectly. it can also reason about it visually when you graph it

    3 likes

  • Werner Kasselman's profile picture

    @wernerk_au

    given the right tools, and taking away the complicated need for interacting with a UI makes the llm agent much more effective in my experience

    1 like

  • David K 🎹's profile picture

    @DavidKPiano

    Yep that's exactly what that demo shows; it sends events to the store directly

  • Swizec Teller's profile picture

    @Swizec

    joke's on you our business process needs a pushdown automata at least pretty sure it might be turing complete

    1 like

  • ismael celis's profile picture

    @ismasan

    Commands (FSM “events”) are the only entry point into state changes. Then you get APIs, permissions, docs, and LLM tools almost for free.

    1 like

  • Mihai Popescu's profile picture

    @Test123457tets

    What is the extensionyou are using to prompt the ai?

    1 like

  • Ruben Casas 🦊's profile picture

    @Infoxicador

    State machines 🤝 WebMCp

    1 like

  • David K 🎹's profile picture

    @DavidKPiano

    Need to try this out!

    1 like

  • Robert Youssef's profile picture

    @rryssf

    event schemas give llm deterministic payloads, but you still need runtime guard to reject malformed events

  • David K 🎹's profile picture

    @DavidKPiano

    Yes; xstate/store (the library used here) has a validation extension just for this:

    1 like

  • Robert Youssef's profile picture

    @rryssf

    validation extension covers compile‑time checks, but runtime guard remains necessary for untrusted event sources

  • Dan's profile picture

    @Dan65709645

    Explicit state makes agents safer and easier to inspect. If the app exposes transitions and schemas, the agent can operate through known events instead of inventing the workflow, and humans can see what changed and why.

  • *daymare*'s profile picture

    @todaymare

    declarative state management is the fancy way to say an imgui?

  • David K 🎹's profile picture

    @DavidKPiano

    It's a fancy way to say a state machine

    2 likes