Structured outputs
Modern models can emit JSON via a response_format or function-calling tool. This lets you build reliable flows:
Raw text -> {intent, entities} -> branch logic
Always validate the JSON before trusting it. A model can forget a field or add extra text. Wrap parsing in a try/catch.
Multi-turn memory
A real agent remembers what came before. Store the extracted state in a dict and update it each turn:
state = session.get("state", {})
state.update(entities) # fill in new details
session["state"] = state
Turn 1: "refund" -> {intent: refund}
Turn 2: "for $42" -> {intent: refund, amount: 42}
State accumulation turns a one-shot parser into a conversation.