最新资讯
dev.to 如何在专用 GPU 服务器上用 OpenAI 兼容 API 部署 LLM dev.to 审计 153 份 Claude Code 与 Codex 会话记录:User-Agent 与 URL 中的邮箱泄露 dev.to 你的 Agent Harness 应具备的 17 项能力 dev.to 离线 AI 记忆中 0.8 余弦阈值为何失效 dev.to Kimi K3.1 Pro 开放权重:自托管 2.8T 模型前的开发者清单 dev.to 如何通过工具调用引导模型以提升 Harness 质量 dev.to AI Agent 审计轨迹不等于对话记录 dev.to 精简 MCP server 工具数量:更少工具、更小影响面,双重收益 dev.to 为什么 git checkout 无法撤销 AI 编码 agent 的改动? wechat AI短剧门槛降降降!实测即梦短剧工作室:剧本分镜预演一条龙,伙伴计划长期护航 dev.to 让模型改写文档前,先量化事实保真度 dev.to 回放 153 个 Claude Code 与 Codex 会话,审计 Agent 的生产影响范围
多元动态
登录 注册
大模型 dev.to · @Valipireddy Kowshik

为什么我放弃“全交给 LLM”,改用状态机

原文 我的收藏

作者在构建 AI 技术面试官时,最初用一个大系统提示词让 LLM 扮演面试官,约 80% 情况可用,但模型会提前结束面试、在提示中泄露答案、重复提问或提前打分。作者认为问题不在提示词技巧,而在结构:LLM 生成下一句话时并不真正记得当前处于哪个阶段,因此改用状态机来管理流程。

AI推荐理由 以 AI 技术面试官为例,说明纯提示词驱动流程约 80% 可靠,剩余失败源于模型缺乏阶段记忆,改用状态机控制流程;属具体工程经验,有明确失败模式描述,但无量化对比数据。

64

正文

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. The problem with trusting an LLM to run your whole flow Here's what kept happening. Mid-interview, the model would: Randomly decide the interview was "done" after one question Give away the answer while trying to give a "gentle hint" Forget it already asked a question and ask it again Jump straight to scoring before the candidate even submitted code 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. What I did instead 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 Enter fullscreen mode Exit fullscreen mode 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 can't hallucinate a phase transition because it doesn't control phase transitions Hints only trigger off a real signal — 35+ seconds of no keystroke activity — not the model deciding "the candidate seems stuck" Scoring only fires after code is actually submitted and executed in the sandbox, not whenever the model feels like wrapping up 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. A simplified look at the transition logic 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): # The FSM owns "what happens next" — # the LLM only fills in content within a state if current_state == InterviewState.CANDIDATE_CODING: if event == "idle_35s": return InterviewState.HINT_CHECK if event == "code_submitted": return InterviewState.EVALUATING # ...deterministic, testable, no hallucinated jumps Enter fullscreen mode Exit fullscreen mode 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. The part that surprised me 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. The takeaway 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.

来源报道 · 1 篇 · 以下链接均前往原始媒体

Valipireddy Kowshik 为什么我放弃“全交给 LLM”,改用状态机 09-15 · 原文发布
← 返回精选动态 原文

更多内容