Knaph

Module 5Episode 58 min

Giving an Agent Knowledge

The whole of module 5 as one video. Jump to any chapter, or read the lesson it comes from.

Transcript

Intro

On Monday, Leila tells her agent where the reports are, how to write numbers, and never to touch the archive folder. On Tuesday, in a new session, it searches the whole computer for the reports. And offers to tidy up the archive. Nothing went wrong. It simply never knew. Today, three ways to give an agent knowledge. Instruction files, memory, and skills.

Instruction files

Leila asks, I explained all of that yesterday. Why doesn't it learn my project? Omid asks, when does a model learn anything? During training. And between requests, it keeps nothing. So on Tuesday, it knows only what is in Tuesday's context. To know something every session, someone has to put it in the context every time. So let the program do it. You write the notes once, in a file. At the start of every session, the harness reads the file, and puts it in the context. Monday, Tuesday, Wednesday. Every session starts with the same notes. It doesn't learn your project. It's told about it, fresh, every morning. This is an instruction file.

CLAUDE.md and AGENTS.md

In Claude Code, the file is called CLAUDE dot M D. A plain text file. One in your home folder holds your own notes, for every project. One in the project's folder holds notes about that project. Teams share it. Many other agents, like Codex, Cursor and Gemini CLI, read a file called AGENTS dot M D. An open format for any agent. Here is Leila's file, after a week. Five lines. Where the reports are. Commas for thousands. Never change the archive. The command to check a report. The brand colours. Each line would otherwise cost her a correction. They are specific, and true every session.

What to put in, and what to leave out

Every line is sent in every request, of every session. That makes it powerful, and expensive. It costs tokens. A two thousand line file rides along, whether the task needs it or not. It competes for attention. Ten sharp lines are followed better than three hundred loose ones. Claude Code suggests under about two hundred lines. And it's guidance, not a lock. If something must happen every time, there's another tool for that, in the next episode. So, put in the commands, where things are, the house rules, and the mistakes it keeps making. Leave out long documents. Point to them instead. Leave out things that change every week, and advice it already follows, like, write clean code.

Writing instruction files well

Four habits. One. Add a line the second time you correct the agent. Two. Write lines you could check. Use this template, not, make it look professional. Three. Keep it short. Read it once a month, and delete what's no longer true. Four. Point to long documents, rather than pasting them in.

Agent memory

Last week, Leila mentioned that her manager likes charts with the newest month on the left. This week, in a brand new session, the agent does exactly that. She never wrote it in her instruction file. The model is stateless. So who remembered? Something written down. While they worked, the agent wrote a short note into a file. This week, the harness loaded that file. Agent memory is notes an agent writes during one session, and reads back in later ones. Writing. When it learns something worth keeping, it saves a note with an ordinary file tool. Reading. At the start of the next session, the harness puts the memory into the context. The model still remembers nothing. The files do.

The memory index

But a year of notes would fill the window. So memory is kept in two layers. A short index, one line per note, loaded into every session. And the notes themselves, each in its own file, opened only when the index suggests one is relevant. Claude Code's auto memory works this way. And chat assistants with a memory feature do much the same.

Memory or instruction file?

Both are loaded every session. The difference is who writes them. You write your instruction file, on purpose. The agent writes its memory, from what it understood at the time. It can misunderstand. Leila always wants blue charts, when she meant it just once. And it can go stale. A wrong note isn't a one time mistake. It's repeated, confidently, every session. But it's plain text. You can read it, and fix it.

Using memory well

Four habits. One. Read the memory now and then. Two. Move notes that matter every time into your instruction file. Three. Say, remember this, when it matters. Four. Say, forget that, when it's wrong. Correcting it in the session isn't enough. The old note comes back tomorrow.

Skills

Leila's company has a thirty page brand guide, a proposal checklist, a procedure for the monthly report, and four more. Why not paste all seven into her instruction file? That's about thirty thousand tokens. She needs the proposal checklist once a month. So most days, those tokens sit in every request, costing money, and crowding the context. Omid asks, do you read a big reference book cover to cover before every task? No. She looks at the contents page, finds the chapter she needs, and reads only that. So give the agent just the contents page. A line about each procedure. And it opens the full one only when a task matches.

What a skill is

That's a skill. A folder that teaches an agent one procedure. At its heart is a file called SKILL dot M D. A short name and description at the top. Then the full instructions, as clear steps. The folder can also hold extra files. A reference sheet, a template, or a small script.

Load only what you need

The trick is when each part reaches the context. This is called progressive disclosure. Always, only each skill's name and description. Twenty skills might cost a couple of thousand tokens. When a task matches, the agent reads the whole SKILL dot M D, and follows it. Only if needed, it opens the extra files. And a script can just be run, without reading its code. When the agent chooses a skill, the description is all it has seen. Brand stuff. That's weak. The skill will never be used, or used at the wrong time. Checks a document against the brand guide. Use when asked to check branding, or before anything is sent to a client. That's strong. What it does, and when. So, instruction file or skill? An instruction file is short facts every session needs. A skill is a procedure needed sometimes, too long to carry everywhere. If most sessions would never use it, it's a skill.

Writing skills well

Four habits. One. Write the description for the moment of choosing. What it does, and the words a request would use. Two. Keep SKILL dot M D focused. Move long details into their own files. Three. Explained the same procedure three times? Make it a skill. Four. For the exact parts, use a small script. It's safer than words.

Recap

Let's put it together. An instruction file is notes you write, loaded every session. Memory is notes the agent writes, which you should read. A skill is a procedure, loaded only when it's needed. Next time, keeping an agent in check. Permissions, hooks, and planning before acting. The lessons and quizzes for this course are free on knaph dot com. See you in the next episode.