Patterns · working with agents

What a session starts with.

What does a fresh agent session know, and how did it learn it? Nothing carries over from yesterday. Every session reads the same short, ordered stack of files: rules first, then a memory index, then names of the skills and tools. Everything else it fetches when it needs it.

The flow

What an agent session starts with Three lanes. I start a session. The harness, the global and repository instruction files, the memory index and the skill and tool names are loaded in order, with a session-start hook as a gate in the middle. I then type the first message, and the agent fetches everything else on demand. new session only 1 I start a new session 2 Harness prompt + tools 3 Rules loaded global, then repo 4 Memory index an index only 5 Start hook a few nudges 6 Skills, tools names only 7 I type first message 8 On demand notes, specs, docs I DECIDE AN AGENT ACTS A GATE CHECKS
  • I decide
  • An agent acts
  • A gate checks

Numbers match the steps below.

Steps

  1. MeStart a session

    A new session in a terminal or an app, with no memory of earlier ones. Everything below is read from files, not remembered.

  2. HarnessBuilds the base prompt

    The system prompt and the built-in tool definitions. The app may add its own reminders on top.

  3. The agentLoads the rules

    The global instructions file on every session, then the instructions file for the working directory on top of it. A repository's own file loads only in sessions that touch that repository.

  4. The agentLoads the memory index

    Only the index of the shared memory folder, cut at a fixed length. The notes themselves stay on disk until one is needed.

  5. Session-start hookAdds a few nudges

    On a genuine new session only, not on resume or clear. It never blocks: it asks whether a broad scope was intended, reminds me to consolidate memory when it has gone stale, lists to-dos that are due, and names branches whose upstream is gone.

  6. The agentLists skills and tools by name

    Skill names and descriptions, and tool names. Full schemas and skill bodies stay out until something asks for them.

  7. MeType the first message

    From here the session has what it started with. Anything else is fetched.

  8. The agentFetches the rest on demand

    Individual memory notes, the body of the to-do inbox, specs, plans, decision records, skill bodies and tool schemas, each through a tool call when the task needs it.

Guardrails

What stops it

A small, fixed start

  • The start is a short, ordered list. Anything that is not in it has to be fetched, which keeps a session cheap and its context clean.
  • The memory index is capped, so growth in notes cannot silently crowd out the rules.
  • Files tracked in a repository load in the same order on every machine.

What waits for me

Rules are mine to write

  • I write and change the instructions files. An agent proposes an edit; it does not rewrite the rules it follows.
  • A lesson that should outlive a session goes into memory, and a superseded fact is dropped in the same pass.
  • Machine-local settings stay on the machine and are never copied by an agent.

What happens on failure

Missing context is visible

  • A missing file means a missing rule, so the first message of a session shows what was loaded.
  • If the hook fails, it is silent rather than blocking: the nudges are a convenience, never a gate on starting work.
  • A conflict between two sources is settled once, in the owning file, and the loser is corrected.

The idea

Treat context as an architecture, not a pile. The instruction files are layered from general to specific, memory is an index that points at notes rather than a dump of them, and a hook adds only the few reminders worth interrupting for. The layers in prose, in the order a session meets them: the global rules, then the repository's own rules, then the memory index and the inbox of open to-dos, then the specs and decision records that explain why. A fresh session is only as good as that stack, so I keep each layer short and give each fact exactly one home.

Copied