cd /news/ai-agents/why-i-ditched-just-let-the-llm-handl… Β· home β€Ί topics β€Ί ai-agents β€Ί article
[ARTICLE Β· art-129761] src=dev.to β†— pub= topic=ai-agents verified=true sentiment=↑ positive

Why I Ditched "Just Let the LLM Handle It" for a State Machine (And Slept Better at Night)

A developer building an AI technical interviewer replaced LLM-driven conversation flow with a finite state machine after the model repeatedly skipped stages, ended interviews early, and mishandled transitions roughly 20% of the time. The state machine now controls which phase the interview is in and what happens next, while the LLM is only called within a state to generate questions, hints, or scorecards. The developer reports that the added structure eliminated the erratic transition bugs and allowed the model to be more creative within each step.

by read3 min views1 publishedSep 15, 2026

When I started building my AI technical interviewer, I did what most people do: I threw a big system prompt at the LLM and told it to "act like an interviewer, ask coding questions, give hints when the candidate is stuck, and score them at the end."

It worked... about 80% of the time.

The other 20% is what this post is about.

Here's what kept happening. Mid-interview, the model would:

None of this was a prompting skill issue. I rewrote that system prompt probably fifteen times. The real issue is structural: an LLM generating the next thing to say has no actual memory of "what phase are we in," unless you spoon-feed it that context perfectly, every single turn, forever. And even then, it can just... decide to do something else. It's a language model, not a state tracker. Treating it like one is where things fall apart.

For a casual chatbot, that's fine β€” mild chaos is charming. For a product where someone's actual hiring decision depends on the interview going through every stage correctly, "mild chaos" is a support ticket and an angry candidate.

I pulled the structure of the interview out of the LLM entirely and put it into a plain old finite state machine.

Something like:

SETUP β†’ GREETING β†’ QUESTION_ASKED β†’ CANDIDATE_CODING β†’
HINT_CHECK β†’ EVALUATING β†’ SCORING β†’ DONE

The state machine β€” not the model β€” decides what phase we're in and what's allowed to happen next. The LLM only gets called inside a state, to do the one thing that state needs: generate a question, generate a hint, or generate a scorecard. It never gets to decide "we're done now" or "let's skip to scoring." That's not its job anymore.

Practically, this meant:

The LLM still does all the hard, "actually intelligent" work β€” writing a good question, phrasing a helpful hint, writing a fair evaluation. It's just not allowed to drive the car anymore. It's a really good passenger with really good opinions.

class InterviewState(Enum):
    GREETING = "greeting"
    QUESTION_ASKED = "question_asked"
    CANDIDATE_CODING = "candidate_coding"
    HINT_CHECK = "hint_check"
    EVALUATING = "evaluating"
    SCORING = "scoring"
    DONE = "done"

def transition(current_state, event):
    if current_state == InterviewState.CANDIDATE_CODING:
        if event == "idle_35s":
            return InterviewState.HINT_CHECK
        if event == "code_submitted":
            return InterviewState.EVALUATING

Compare that to letting the model implicitly track state through conversation history alone β€” there's no guarantee, no test coverage, and no way to catch a bad transition before it reaches the user.

I expected this to make the product feel more robotic. It did the opposite.

Because the structure is now guaranteed, I could actually let the LLM be more creative and natural within each state, without worrying about it going off the rails. Constraining the skeleton let me loosen up the muscle. Counterintuitive, but it checks out β€” a lot of "unpredictable AI" complaints aren't really about the model being too creative, they're about the model having too much control over things it was never designed to control.

If you're building something where an LLM is orchestrating a multi-step process β€” not just answering one-off questions β€” ask yourself: does the model actually need to decide what happens next, or does it just need to generate good content within a step someone else decides?

Most of the time, in my experience, it's the second one. And the moment I stopped asking the LLM to be both the actor and the director, my "why did the interview just end after one question" bugs basically disappeared overnight.

I write about the messier, more practical side of building AI products β€” the stuff that doesn't make it into the demo. If you're curious, I built this exact system as a live product: AI Technical Interviewer. Happy to talk through the architecture more in the comments.

── more in #ai-agents 4 stories Β· sorted by recency
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain β€” perfect for shipping the agent you just read about.

$git push zahid main
β†’ Live at https://your-agent.zahid.host βœ“
Get free account β†’ Pricing
from €0/mo Β· no card required
LIVE [news/why-i-ditched-just-l…] indexed:0 read:3min 2026-09-15 Β· β€”