Working memory keeps an agent’s conversation context available during a single session. If a traveler asks for flights and then adds “make sure it’s a window seat,” the agent can apply that constraint without asking for the destination and date again. Unlike persistent memory, this information is temporary and can be discarded when the session ends. section 6.2.1
Order-tracking chat
A customer supplies an order ID. The agent retains it for the session, uses it to query the order database, and can answer follow-up questions without requesting the ID again. A support agent can likewise retain a device type, operating system, and reported error while troubleshooting. section 6.2.1
A plain buffer is often enough: store messages or key details in a list or dictionary, then read them when handling the next turn. It is lightweight and needs no persistent store. Keeping the full conversation preserves recall, but long sessions can exceed a model’s context window. For those sessions, periodically summarizing the history reduces what must be carried forward; it is a trade-off when exact recall matters. section 6.2.1 section 6.2.2
class ShortTermMemory:
def __init__(self):
self.memory = []
def add_message(self, message):
self.memory.append(message)
def get_memory(self):
return self.memory
This minimal Python class appends messages to a list and returns the accumulated session history; it shows storage, not session lifecycle management. section 6.2.1
Start with a buffer for short conversations, where it is simpler and cheaper. Add summarization when sessions regularly exceed the context window. For production agents needing checkpointing, human approval steps, or state across sessions, consider LangGraph state management rather than relying on standalone memory classes intended for simpler applications and prototypes. section 6.2.2






