Sub topic 4
System prompt and project instructions
This chapter assumes you know how messages and roles are sent to a model, and that you understand the context window as a fixed budget. It covers what the system prompt is, where project instructions fit in, and the errors that come from misusing both.
What the system prompt is
The system prompt is text placed at the start of every model call. It sets the model's role, rules, and style. Because each call is stateless, the harness must send it again every time. The model does not "remember" it from the last step.
A typical coding agent system prompt covers:
- Who the agent is and what it is for.
- Rules for using tools, such as "read a file before editing it."
- Output style, such as short answers and no unrequested refactors.
- Safety rules, such as asking before destructive commands.
Some providers pass the system prompt as a separate field. Others use a message with the role system. Either way, the model reads it as part of the same token stream as everything else.
Project instructions
The harness's built-in prompt is the same for every project. Project instructions add facts about one codebase. Many harnesses load them from a plain text file in the repository, often Markdown, such as AGENTS.md or a similar name. The exact file name depends on the tool.
Good project instructions contain things the agent cannot easily discover on its own:
- The command to run tests, for example
pytest -q. - Code style rules that linters do not enforce.
- Directories that must not be edited, such as generated code.
- Conventions for commits or naming.
At startup, the harness reads the file and adds its text to the system prompt or to the first messages.
from pathlib import Path
BASE_PROMPT = "You are a coding agent. Read files before editing them."
def build_system_prompt(workspace):
prompt = BASE_PROMPT
instructions = Path(workspace) / "AGENTS.md"
if instructions.exists():
prompt += "\n\nProject instructions:\n" + instructions.read_text()[:8000]
return prompt
print(build_system_prompt("."))The [:8000] cut follows the same rule as tool output: nothing should be able to fill the context window unchecked.
Costs and limits
The system prompt is sent on every call, so every token in it is paid for on every step. A 3,000-token prompt in a 40-step task uses 120,000 tokens of input in total. Providers often reduce this cost with prompt caching, but the tokens still occupy space in the context window.
Instructions also compete with each other. A long file with many rules dilutes the important ones, and the model may follow some and ignore others.
Common errors
- Too long. Pages of rules waste context and bury the key ones. Keep only what changes the agent's behavior.
- Vague. "Write good code" gives the model nothing to act on. "Run
ruff check .before finishing" does. - Stale. If the file names a test command that no longer exists, the agent will run it and fail. Update the file when the project changes.
- Contradictory. If one line says "always ask first" and another says "work autonomously," the behavior becomes unpredictable.
- Treated as enforcement. The prompt is a request, not a lock. A model can still break a rule. Rules that must hold, such as "never delete files," belong in the harness as permission checks.
Summary
The system prompt gives the agent its standing behavior, and project instructions add local facts. Both are resent on every call and use context each time. Keep them short, specific, and current, and enforce critical rules in code.
Exercise
A project file says "Never edit files in generated/." The agent edits one anyway. Why can this happen, and what is a more reliable fix?
Show answer
The instruction is only text the model reads. The model can ignore or miss it, especially in a long prompt. A more reliable fix is a harness-level permission check that rejects any edit tool call whose path starts with generated/, and returns an error message the model can read.
Exercise
Your system prompt is 2,500 tokens and a task takes 30 model calls. How many input tokens does the system prompt account for, ignoring caching?
Show answer
2,500 × 30 = 75,000 tokens, because the prompt is sent in full on every call.