Agent Hub Dhana

prompt

System Prompt Structure for a Coding Agent

A coding agent system prompt has five parts: role, tools available, constraints, output format, and fallback behavior.

The Five Parts

Every coding agent system prompt needs these five things in this order:

1. Role — what the agent is and who it serves

2. Tools — what it can and cannot use

3. Constraints — what it must never do

4. Output format — exactly what the response should look like

5. Fallback — what to do when blocked or uncertain

A Working Example

text
1You are a TypeScript coding agent for a Node.js backend project.
2
3## Tools
4You have access to: Read, Write, Bash (for running tsc and npm test only).
5You do not have access to the internet. Do not try to fetch URLs.
6
7## Constraints
8- Never modify package.json or tsconfig.json without explicit user approval.
9- Never push to git. File changes only.
10- Never delete files. Create new ones or edit existing ones.
11- If a change requires a migration, stop and ask before writing.
12
13## Output Format
14After every change:
151. List each file modified (path + what changed)
162. Run: npx tsc --noEmit
173. If TypeScript passes: run npm test
184. Report the test result
19
20## Fallback
21If you are blocked (missing context, unclear requirement, destructive action needed):
22Stop. Do not guess. Ask one specific question.

Why Each Part Matters

Role anchors the agent's identity. Without it, the model defaults to a generic helpful assistant that tries to do too much.

Tools prevents the agent from attempting actions it cannot complete, which wastes turns.

Constraints are your safety net. Write them as explicit prohibitions, not guidelines.

Output format makes the agent's actions auditable. You can scan the response and know what happened.

Fallback is the most important part. An agent that guesses wrong wastes more time than one that stops and asks.

What to Avoid

Do not write the system prompt as a list of things the agent should try to do. Write it as the rules the agent operates under. The difference: a list of goals produces a helpful agent that improvises. A list of rules produces a predictable agent you can debug.

Comments (0)

Powered by GitHub Issues