# Stateful

> Carries information forward. Sessions are stateful across turns; agents can be made stateful across sessions via a memory system.

Carries information forward. A [session](https://ai9k.vercel.app/en/session) is stateful across [turns](https://ai9k.vercel.app/en/turn) — [context](https://ai9k.vercel.app/en/context) accumulates as the session runs, which is why long sessions drift into the [dumb zone](https://ai9k.vercel.app/en/smart-zone). An [agent](https://ai9k.vercel.app/en/agent) can be made stateful across **sessions** by adding a [memory system](https://ai9k.vercel.app/en/memory-system) that persists information into the [environment](https://ai9k.vercel.app/en/environment) and reloads it at the start of future sessions. The [model](https://ai9k.vercel.app/en/model) is never stateful; any apparent continuity is the [harness](https://ai9k.vercel.app/en/harness) re-feeding context. Counterpart to [stateless](https://ai9k.vercel.app/en/stateless).

Where state lives at each layer:

| Layer       | Stateful?       | How                                                                                                                    |
| ----------- | --------------- | ---------------------------------------------------------------------------------------------------------------------- |
| Model       | Never           | [Parameters](https://ai9k.vercel.app/en/parameters) are frozen; it sees only what's in each request                                          |
| Session     | Across turns    | The harness appends every message and [tool result](https://ai9k.vercel.app/en/tool-result) to the context                                 |
| Harness     | Across sessions | Memory files, [AGENTS.md](https://ai9k.vercel.app/en/agentsmd), [handoff artifacts](https://ai9k.vercel.app/en/handoff-artifact) — written down, reloaded later |
| Environment | Always          | Files persist whether or not any session is running                                                                    |

Each layer's statefulness is built by re-reading something stored a layer below: the session feels continuous because the harness re-sends the message history to the stateless model, and the agent remembers across sessions because the harness re-loads files from the environment. No state is ever stored in the model itself.

State isn't always wanted. Everything carried forward influences what comes next, so a wrong assumption made early in a session is carried forward too. [Clearing](https://ai9k.vercel.app/en/clearing) is the deliberate act of throwing session state away and starting from what's written down.

**Usage**

"It remembered my preferences from yesterday — does that mean the model learned them?"

"No, the agent's stateful because the harness wrote them to a memory file and reloaded them at session start. The model itself saw nothing of yesterday."

---

- Section 2 — Sessions, Context Windows & Turns · Term 20 of 72
- Page: https://ai9k.vercel.app/en/stateful
- Learn step by step: https://ai9k.vercel.app/en/learn#/stateful
- On the map: https://ai9k.vercel.app/en?term=stateful
- JSON: https://ai9k.vercel.app/data/terms/stateful.json
- Mentioned in: [Stateless](https://ai9k.vercel.app/en/stateless.md), [Environment](https://ai9k.vercel.app/en/environment.md), [Memory system](https://ai9k.vercel.app/en/memory-system.md), [DX](https://ai9k.vercel.app/en/dx.md)
- Previous: [Context window](https://ai9k.vercel.app/en/context-window.md)
- Next: [Agent](https://ai9k.vercel.app/en/agent.md)

Every term page has a markdown copy: add .md to its address.
