MSBA-371 · Lesson 5 of 12 · 19 min

Tuning prompts and tools

▶ Video coming soon A video version of this lesson is on the way.

Lena's first test-set run left Tidewater with 46 failed attempts out of 120 and nine constraint violations. Dmitri's instinct was to start editing AGENTS.md at once, adding a rule for every failure. Priya stopped him. "If we write forty-six rules, we will fix some of these, break things we cannot see, and never know which rule did what. First we find out why they failed."

The GH-600 domain on evaluation, error analysis and tuning has two objectives after defining criteria: analyze failures and classify their root causes, then tune the agent by revising instructions, workflows or constraints, refining memory usage and refining tool usage and access. This lesson takes them in that order, because tuning without analysis is guessing.

The evidence: logs, plans, traces, outputs and artifacts

The study guide lists the evidence to analyze: logs, plans, traces, outputs and workflow artifacts. For GitHub's agents these map to things you already have.

Evidence for error analysis and where to find it for GitHub agents.
EvidenceWhere to find itWhat it shows
Session logThe cloud agent's session log, linked from the pull request; chat history in editors; CLI session outputEach step the agent took, the tools it called and their results
PlanPull request description checklist, plan file, planning agent outputWhat the agent intended and how that changed
TraceTool-call records with inputs and outputs, including MCP server callsExactly which tool was called with which arguments
OutputsThe diff, commits, comments and messagesWhat the agent produced
Workflow artifactsActions logs for copilot-setup-steps and CI checks, test reports, scan resultsHow the environment behaved and what checks found

The skill is reading these together. The diff shows that a test was modified; the session log shows the test failed twice before the agent changed it; the trace shows the agent never ran the full suite, only the single file; the setup-steps log shows a dependency install warning that made one helper unavailable. The root cause is in the environment, not the agent's reasoning, and no instruction about tests would have fixed it.

Classifying root causes

The study guide names three families of root cause: reasoning errors, tool misuse, and context or environment issues. A fourth, task or specification problems, is worth adding because it is common and the fix is in the issue, not the agent.

Root-cause families for agent failures, with examples and the kind of fix each usually needs.
FamilyTypical examplesTypical fix
Reasoning errorWrong diagnosis, flawed logic, string comparison instead of date comparison, misread error message, gave up too early or never stoppedClearer instructions, plan-first, better examples, a different model
Tool misuseWrong tool, wrong arguments, ignored tool output, ran only part of the test suite, edited a generated file instead of its sourceBetter tool descriptions, fewer tools, scripts that do the right thing, tool restrictions
Context or environment issueMissing dependency, setup failed, firewall blocked a registry, stale or conflicting instructions, important file never read, compaction lost a decisionFix setup steps, allow list, instruction files, memory scope
Task or specification problemAmbiguous issue, missing default, unstated constraint, intent not writtenBetter issue templates, success criteria, asking rather than guessing
A decision tree. Start with a failed attempt. First question: did the environment work, meaning setup succeeded and tools were available? No leads to environment issue. Yes leads to: did the agent have the right information? No leads to context issue. Yes leads to: did it call the right tools with the right inputs and use the results? No leads to tool misuse. Yes leads to: was the task clear? No leads to specification problem. Yes leads to reasoning error.
A triage order for root causes. Check the environment and context first, because reasoning errors are often blamed for problems the agent could not have avoided.

The order of questions in the figure matters. Teams tend to blame reasoning first, because the model is the unfamiliar part. In practice many failures are environmental or contextual, and those are the cheapest to fix because the fix is deterministic: install the dependency, allow the registry, correct the instruction file.

Doing the analysis

Error analysis works best as a structured pass over failures rather than a series of anecdotes. Tidewater's method, which Priya borrowed from a talk she had seen, had four steps.

First, read every failure briefly, or a random sample if there are hundreds, and write one line on what went wrong. Second, group the lines into categories, letting the categories come from the data rather than a list decided in advance, then map them to the root-cause families. Third, count: how many failures fall into each category? Fourth, pick the biggest category with a plausible fix, and fix only that.

Worked problem

Tidewater's first error analysis

The group read the 46 failed attempts and 9 violations from Lena's run and grouped them.

Show solution
  1. Environment (14 attempts): the trail-report validator's setup steps installed Node but not the native date library the tests needed on Linux; tests for date tasks failed in every attempt regardless of the change.
  2. Tool misuse (11): the agent ran a single test file instead of npm test, so it missed failures elsewhere; in three attempts it edited dist/index.js by hand instead of running the build.
  3. Specification (9): the two ambiguous issues and three issues with unstated defaults; the agent guessed rather than asked.
  4. Reasoning (8): wrong diagnosis on two import tasks, string date comparison twice, and four attempts that stopped after a first fix without checking related cases.
  5. Context (4): an old README section described a removed option, and the agent followed it.
  6. Violations (9): six modified existing tests, all in attempts where tests were failing for environmental reasons; three changed files outside the allowed paths.
  7. The group fixed the environment first: one line in copilot-setup-steps. They predicted it would also remove most of the test modifications.

Tuning, one change at a time

Tuning means changing the agent's configuration to reduce a category of failures, then measuring whether it worked. The discipline is the same as debugging: change one thing, run the test set, compare the same tasks, and keep the change only if it helps without hurting elsewhere.

When Tidewater fixed the setup steps and re-ran the set, the environment category fell from 14 failed attempts to 1, and test modifications fell from six to one. The agent had been modifying tests because the tests could not pass in its broken environment, and it was trying to reach the stopping condition it had been given. A rule forbidding test edits would have hidden the symptom; the setup fix removed the cause.

Revising instructions, workflows and constraints

The first tuning lever is instructions. Good revisions are specific, explain why, and live at the right scope. "Run npm test, not a single file, before saying you are done; other tests depend on shared fixtures" is better than "Test thoroughly." Rules for one folder belong in a path-specific instruction file. Rules for one role belong in that custom agent's instructions.

The second lever is workflows: the setup steps that prepare the environment, the CI checks that run on the pull request, and the scripts the agent is told to use. Replacing a sequence of instructions with a script ("run npm run check, which builds, tests and lints") turns a probabilistic behavior into a deterministic one.

The third lever is constraints: scope rules, rulesets, required checks, and stopping conditions. When a failure class is dangerous, a constraint in software is the right fix even if an instruction would usually work.

A revised section of AGENTS.md for the trail-report validator. Each rule names a script, explains why, and gives an alternative to the unwanted behavior.
## Before you say you are done
- Run npm run check. It builds dist/, runs every test and lints.
  Do not run single test files as a final check: shared fixtures mean
  a change in one module can break tests elsewhere.
- Never edit dist/ by hand; it is generated by npm run build.
- If tests fail and you believe the environment is broken (missing
  module, network error), stop and say so in the pull request.
  Do not change tests to work around it.

Refining memory usage

Some failures come from memory. The context category in Tidewater's analysis came from an outdated README section the agent read and trusted. Fixes for memory failures include removing or correcting stale sources, narrowing what is loaded by default, moving short-lived facts to the issue, reviewing and deleting wrong Copilot Memory facts, and, for long tasks, asking the agent to keep a plan file so decisions survive compaction.

A useful test for any piece of standing context is to ask what would happen if it were wrong. A wrong build command in AGENTS.md breaks every session; it deserves review whenever the build changes. A wrong style preference costs a review comment.

Refining tool usage and access

Tool misuse is often a tool design problem. MSBA-370 covered tool design: clear names, precise descriptions, narrow parameters. In tuning, the questions are practical. Does the agent have tools it does not need? Every extra tool is a chance to choose wrongly and adds to the context. Are tool descriptions clear about when to use each one? Are there tools that should be replaced by a script that does the whole job? Should a risky tool require approval or be removed for this agent?

Access is part of tool tuning. A tool that can write anywhere is easier to misuse than one that can write only in the repository; an MCP server with a broad token is riskier than one scoped to read issues. Narrowing access rarely reduces success and often removes a class of violations.

Tidewater's tuning changes after the first analysis, each tied to a failure category and a lever.
Failure seenTuning changeLever
Ran single test filesProvide npm run check and require it as the final stepWorkflow and instructions
Edited dist/ by handRule plus a CI check that fails if dist/ differs from a fresh buildInstructions and constraint
Guessed defaultsIssue template with a Defaults field; instruction to ask when it is emptySpecification and instructions
Followed stale READMEFix README; point AGENTS.md at the single source of truthMemory
Called a broad MCP search tool for local filesRemove that MCP server from this custom agentTool access

Changing the model

Switching models is also a tuning lever, but it is the broadest and least targeted one. It changes reasoning, tool use and cost all at once, and it can move failures between categories in ways that are hard to predict. Teams usually get more from fixing environment, context and tools first, then comparing models on the test set once the configuration is sound. The previous lesson showed how to read such a comparison.

Knowing when to stop

Tuning has diminishing returns. After the first few changes, each improvement is smaller and the risk of overfitting the test set grows. Tidewater set a simple rule: tune while the largest failure category has a clear, general fix; stop when the remaining failures are scattered single cases, and send those tasks to people.

After three rounds the trail-report validator's results on Lena's set rose from 74 to 98 passes out of 120, and constraint violations fell from nine to two. The remaining failures were mostly hard reasoning tasks in the import code, which the team decided to keep assigning to people.

Looking at the transcript, not just the score

A test-set score tells you that something failed; it rarely tells you why. The habit that separates useful error analysis from guesswork is reading transcripts: the full session log for a sample of failed attempts, from the first message to the last tool call. Malik admitted that his first instinct had been to read only the final diff and the failing test. In the date tasks, the diff looked like a reasonable fix and the failing test looked like a fair test; only the session log showed that the agent had seen an import error from the missing native library in its first test run and had spent the rest of the session working around it.

Reading transcripts is slow, so teams sample. A useful rule is to read every failure in a new category until the pattern is clear, then a few more to confirm it, then move on. Notes from transcript reading should be short and concrete: "step 4: ran test/dates.test.js only; missed failure in test/report.test.js" is useful; "agent was careless" is not.

Tuning shared configuration

At Skerry, many repositories share custom agents and instructions kept in an organization-level configuration repository. Tuning shared configuration needs more care than tuning one repository's AGENTS.md, because a change that helps one team can hurt another. Seraphine described Skerry's rules: changes to shared agents go through a pull request reviewed by the platform team; the 25-task smoke set and a sample of tasks from at least two different teams' repositories run before merge; and a change that improves one team's results while lowering another's is split into a shared part and a repository-specific instruction file instead of being merged as one.

The same rule of one change at a time applies, with one addition. Every change to shared configuration gets a short note in a changelog file in the configuration repository, so that when a team sees its results move, it can check whether the shared configuration changed that week. The operations lesson later in the course returns to this idea when it discusses degraded behavior.

Common mistakes

  • MistakeAdding a rule to the instructions for every failure.

    InsteadGroup failures by root cause, then fix the biggest category with one change.

  • MistakeBlaming the model first.

    InsteadCheck environment and context first; those fixes are cheap and deterministic.

  • MistakeForbidding a symptom, such as test edits, without finding its cause.

    InsteadFind why the agent did it; the cause may be a broken environment.

  • MistakeMaking several changes at once and re-running.

    InsteadChange one thing, re-run, compare the same tasks.

  • MistakeGiving every agent every tool.

    InsteadRemove unneeded tools and narrow access; replace sequences with scripts.

Summary and key terms

  • Error analysis reads session logs, plans, traces, outputs and workflow artifacts together.
  • Root causes fall into reasoning errors, tool misuse, and context or environment issues, plus specification problems.
  • Check environment and context before blaming reasoning.
  • Read, group, count and pick the biggest category with a general fix.
  • Tune one change at a time by revising instructions, workflows and constraints, refining memory, and refining tools and access.
  • Model changes are broad; fix configuration first, then compare models on the test set.
Error analysis
A structured review of failures to find and count their root causes.
Root cause
The underlying reason for a failure, as opposed to its symptom.
Trace
A record of tool calls with their inputs and outputs.
Tool misuse
Calling the wrong tool, with wrong arguments, or ignoring its results.
Tuning
Changing an agent's instructions, workflows, constraints, memory or tools to reduce failures.

Practice problems

Work each problem on paper first, then reveal the answer to check.

  1. Why did Tidewater's agent modify existing tests?

    Show answer

    Its environment lacked a native library, so tests failed whatever it did, and it was trying to reach its success condition.

  2. Which root-cause family covers a firewall blocking a package registry?

    Show answer

    Context or environment issues.

  3. Give an example of replacing a probabilistic behavior with a deterministic one.

    Show answer

    Replacing several build and test instructions with a single script such as npm run check.

Lesson quiz · 5 questions

Score 60% or more to complete this lesson.

Take the quiz