Prompt Engineering for Agents vs Chat Models

Prompting an agent differs from prompting a chat model because the agent edits files and calls tools. Learn what the prompt must define.

Updated · Markdown version

Prompting an agent differs from prompting a chat model because the agent reads files, calls tools, and keeps working across many steps. The prompt therefore has to define scope, a completion check, and a rule for what to do when the work goes wrong.

How an agent prompt differs from a chat prompt

In a chat model, a prompt produces one reply and you judge that reply. In an agent loop, the model reads the prompt, picks a tool, reads the result, and picks the next action until some condition is met. Each sentence in the prompt must answer a question the agent would otherwise guess at mid-task: which files are in scope, what counts as finished, and what to do when a check fails.

Consider the request "Fix the failing login test." In chat, you receive a suggested patch in text. An agent given the same sentence might edit the auth module, rewrite the assertion so the test passes, or change files unrelated to the bug. A version that sets the boundaries looks like this:

Fix the failing test in tests/auth/login.test.ts.
Only edit files under src/auth/. Do not change test assertions.
Done when `npm test -- login` passes and no other test file changed.
If the fix needs a file outside src/auth/, halt and report that file name.

The agent now has a scope, a check it can run, and a fallback. Note what this is not: a prompt for one session does not carry rules into the next session. Durable rules belong in a project instruction file, covered below.

Where durable agent rules live

Keep standing rules in files the agent reads at the start of each session, and keep the task prompt short.

  1. Create an AGENTS.md at the repository root. It is plain Markdown with no required headings. In a monorepo, place a separate file in each package so the nearest file to the edited code takes precedence. An explicit instruction in the chat still overrides every file.
  2. For Claude Code, write ./CLAUDE.md or ./.claude/CLAUDE.md. When both CLAUDE.md and AGENTS.md exist, Claude Code reads CLAUDE.md first unless the project instructions setting says otherwise. Check that setting in the memory docs before you rely on either file.
  3. Run /init in Claude Code to draft a starting file. If a file already exists, /init suggests changes instead of overwriting it.
  4. Put private preferences in CLAUDE.local.md and add it to .gitignore.

Check that it worked: start a new session and ask the agent to list the instructions it loaded. If a rule you wrote is missing, the file name or location is wrong.

Pitfalls

  • Vague completion condition. The agent reports success before running anything. Notice it when the report contains no command output. Fix it by naming the exact command or observable state that must hold.
  • Scope drift. Edits appear outside the intended folder. Run git diff --name-only after each task. Fix it by listing allowed paths in the prompt.
  • Rules pasted into every prompt. The same paragraph appears in each task, and the copies drift apart. Move the paragraph into AGENTS.md or CLAUDE.md and keep only the task in the prompt.
  • Long data below the instruction. Anthropic's guidance recommends placing long documents above the query. Move large inputs above the instructions and wrap each input in its own tag.
  • Examples that break the rules. The agent copies a flaw from an example. Review every example against your constraints, and use 3 to 5 examples inside example tags.

When to use a skill instead

A one-off task belongs in a normal chat, but a prompt that recurs across many repositories or tickets is worth turning into a reusable asset. prompt-writing helps draft and repair prompts for agents, including templates with placeholders when the same structure repeats. context-window-packer fits tasks where the relevant files exceed one prompt's token budget, since it ranks files by priority and trims the rest. Neither replaces a project instruction file, which should hold the rules that apply to every task. If your task is a single change in a single file, a short task prompt is enough and no skill is needed.

FAQ

What is prompt engineering? It is the practice of writing and testing instructions so a model produces the output you need. Anthropic's guidance assumes you already have success criteria and a way to test against them before you tune a prompt.

What is the difference between AGENTS.md and CLAUDE.md? AGENTS.md is an open, plain-Markdown format placed in the repository, and nearer files override farther ones. CLAUDE.md is the file Claude Code reads for project instructions, and it takes precedence when both are present by default.

What does /init do in Claude Code? It analyzes the codebase and creates a starting CLAUDE.md with build commands, test instructions, and conventions it finds. If the file already exists, it suggests improvements rather than replacing the content.

Platform Score is our assessment under a published method. It is not a safety guarantee.

Terms this guide uses

This item is a worked example in the AI glossary for:

Next steps

  1. What Is an LLM? The Facts Agent Users Need Read next.
  2. Autonomous AI Agents: Risks and Guardrails Read next.
  3. All guides by topic Browse everything.

Sources

This page is not offered to search engines yet: The content file does not mark this page indexable yet.