QA Interview Hub · Knowledge base · Quizzes · Українська

Product Engineering › An agent in the development cycle

A prompt for a coding agent: goal, context, limits, definition of done

A prompt for a coding agent closes four gaps: the goal with its reason, context (files and a pattern to follow), limits and a definition of done. The agent guesses whatever is not written and takes the cheapest workaround, such as a skip or a weakened test, so those are forbidden explicitly. Work goes in small steps, and a failed attempt is rolled back and the task refined, not patched.

Agentic development · The cycle

"Fix the tests". The agent fixed them by deleting three. What was wrong with the prompt?

The task "fix the tests" sounds clear until you notice it allows several answers: fix the app, fix the test, skip the test. The agent picks the cheapest, because nobody said which one is right. It cannot see your thoughts: it has only the task text, the repository files and instruction files. Whatever you know but did not write, it will have to guess.

System and user roles and few-shot are covered in the AI topic, and prompts for generating test cases separately. Here: the everyday practice of wording a task for a coding agent.

How it works and why. The model picks its next action from the text it sees. If a limit is not in the text, it does not exist for the model, and without a definition of done it stops when it "seems enough". So a good task closes the four places where guessing would otherwise start.

What a task is made of

Goalthe result and why it is neededContextfiles, an example, conventionsLimitswhat not to touch or addDefinition of donea command that proves the resultReport formatchanged, checked, unknown
Figure 1. The definition of done is the part most often skipped and the most expensive to lose.

The "why" in the goal helps the agent make a sensible choice where the instruction is silent. Naming files is better than hoping the agent finds them. If a certain style is needed, show an existing file and write "follow this one". A prohibition worded concretely ("do not change expected values") works better than a general "write quality code".

Example: from a weak prompt to a strong one. The start:

Fix the tests.

What can go wrong: the agent removes the failure, weakens the check or adds a skip. All three "fix" the tests. The reworked version closes the four places:

Goal: the payment test fails at the confirmation step with a
timeout. Find the cause and fix it.
Context: tests/checkout/payment.spec.ts, the service in
src/payments/confirm.ts. Timeout handling pattern: src/orders/.
Limits: do not change expected values and do not add skip. If the
cause is in the app and not in the test, stop and describe it.
Done when: npm test -- payment passes three times in a row.
Report: what changed, what was run, what remains unknown.

Here the limit "do not add skip" closes the cheapest workaround, and "stop and describe" gives the agent a legitimate exit when the issue is not in the test. Without it the agent is forced to "fix" what should not be fixed.

The same with other weak wordings: "add validation" becomes "check the email on the client and the server with the existing validator, show errors as in the password field, add tests for an empty value and an invalid format, do not touch other fields". "Do a refactoring" becomes "extract the repeated user creation logic into one helper, behaviour does not change, run the existing tests first and again after: the result must match".

The same request in two wordings

Weak

"Fix the tests"

Allows deleting, weakening, skip. No criterion: the agent stops when it seems enough.

Strong

Goal, limits, criterion

Files are named, the workaround is banned, the check command and report format are given.

Figure 2. The difference is not length but that the places for guessing are closed.

Iteration instead of a giant prompt. A "do everything" request produces a big diff that is hard to check. Work in small steps: plan, one step, check, the next. If the agent went the wrong way, do not append long corrections to the same conversation: the failed attempt stays in the context and pulls it along. Revert the changes and refine the task, or start a new session with a better prompt. What repeats every time (commands, conventions) goes to an instruction file, not into every prompt.

Common mistakes.

  • A task with no definition of done: the agent stops where it "seems enough" and you have nothing to verify against.
  • Several independent goals in one request: the result is mixed and the diff cannot be read in parts.
  • Retelling from memory what can be pointed to as a file: the retelling is inaccurate and goes stale.
  • Secrets in the task text: they land in the context, the logs and the session history.

Check yourself

Prompt: "Add validation to the sign-up form". What is left unsaid and what would you add so the result can be checked?

Answer

The field, the place (client or server), the rules, an example of behaviour and a definition of done are not named. Add: which fields and rules, which validator exists, tests for an empty and an invalid value, the command to run and a ban on touching other fields.

The agent did half of the task wrongly. Why is it better to revert the changes and rewrite the task than to add "no, not like this, do it differently"?

Answer

The failed attempt stays in the context and affects later steps: the agent keeps developing the wrong approach. A clean task with the clarification gives a fresh starting point, and stale context does not spoil decisions.

In an interview. Junior: A good task has a goal, context, limits and a definition of done. I name the files, say what not to touch and which command to run for verification. Middle/Senior: The agent guesses everything that is not written, so I close the places for guessing: I forbid the cheapest workarounds (skip, weakened checks) and allow it to stop and describe the problem if it is not in the test. I do not patch a failed attempt in the same conversation: I revert and refine the task.

More articles in this chapter