← Production Insights

#20

State Design for Production AI Agents

The hardest part of building a production AI agent isn't getting it to understand the user. It's making it remember what it was doing when the user changes the conversation flow.

The problem is often not the LLM.

It’s the state design.

Two important variables I usually add to the agent state are currentTurn and flowContext.

  • currentTurn: what does the user want right now?
  • flowContext: what workflow is currently in progress, and where did we leave off?

For example, imagine an e-commerce agent.

The user says: “I want this product.”

Then the agent starts an order flow:

flowContext = { flow: "orderFlow", currentStep: "collect_address", status: "active" }

The agent is currently waiting for the address.

Then the user asks:

“How much is delivery?”

That question belongs to the current turn, not necessarily to the order workflow itself:

currentTurn = { intent: "delivery_information", action: "get_delivery_fee" }

The system still knows:

  • which workflow is active.
  • which step it was waiting on.
  • whether that workflow is active or paused.

So the agent can answer the delivery question without losing its place in the order flow.

This gives each piece of state a clear responsibility:

  • currentTurn: what is the user asking now?
  • flowContext: What workflow is currently in progress?
  • currentStep: what exact step is that workflow waiting on?
  • status: is the workflow active, paused, completed, or cancelled?

This separation becomes increasingly important as an agent grows.

The goal is to make state explicit enough for the agent to distinguish between the current request, the workflow already in progress, and the point at which that workflow can resume.

The challenge is handling different types of interruptions while preserving workflow continuity.