DEV Community

Cogweald
Cogweald

Posted on

A plot thread is really a state machine

“Let the AI advance the story” sounds exciting, but without a state model, every chapter quickly starts inventing the same problems again.

Cogweald models long-running plot lines as story threads. Each thread has a title, description, status, and timestamps. Its status can be active, resolved, or abandoned.

When a chapter is generated, the model does not only return prose. It also returns thread updates: which thread advanced, which one was resolved, and whether a new one should be opened. The application applies those decisions to the database and provides the updated state to the model next time.

This turns continuity from a hope into an observable and verifiable state transition.

The same pattern works for any agent that needs long-term planning:

  • An unfinished refactor for a coding agent
  • An unverified hypothesis for a research agent
  • A customer risk for a success agent
  • A quest line for a game agent

If an agent needs to remember what is still unfinished across multiple runs, it probably deserves a state machine.

Top comments (0)