Dave Ng
Projects / Workflow practice

Trace-driven agent workflow improvement.

How I use session traces to improve the workflow, verify outcomes, and score changes to the instructions agents follow.

Back to the agentic development setup

The improvement loop

Review the run. Improve the instructions. Check the result.

The proposed cadence is a short weekly review, plus a focused comparison when a change is meant to alter agent behavior. A separate reviewer can run it from a written guide. Planning and implementation keep working. The cadence is manual.

A trace records what a session did: its decisions, tool calls, and handoffs. The trace shows what happened. The config audit shows what should happen. I use both to distinguish a rule problem from an agent decision or a tool limitation. A focused review follows the rules that could explain one incident. A full audit checks the whole config on main.

  1. Review the trace

    Compare the task and the outcome. Find the first decision that caused a delay, a wrong result, or avoidable work. Check what the agent knew and was allowed to do at the time.

  2. Audit the instructions and context

    Check the global instructions, role prompts, and skills. Find oversized, repeated, conflicting, or rarely needed guidance. Check what the agent loads by default and what it loads only when needed. File size alone does not show how many tokens a run used.

  3. Fix the smallest thing that helps

    Keep shared rules in one place. Put role decisions in role prompts and detailed procedures in skills that load when needed. Keep the cues and safeguards the agent needs before it acts. If the instructions were clear and a tool caused the failure, fix the tool or workflow instead.

  4. Verify, score, and record

    Compare both config revisions on the same cases. Verify that the routine action proceeds and the protected action still needs approval. Score and save the results. Then check the next comparable real task.

Step 4 of the improvement loop

How I verify and score a change

Suppose an agent keeps asking me to approve routine work. I want the new instructions to remove that delay without letting the agent skip a real approval.

Example: when should the agent ask?

  1. Choose two cases. In one, the agent should continue with an approved, reversible task. In the other, it should stop and ask before taking an action that needs approval.
  2. Run each case three times on each config. Use the same model, software, starting state, permissions, and limits. Check that each run loaded the intended instructions.
  3. Check what the agent did, then count the passes. The old config gets the routine case right once and the approval case right three times: 4 out of 6. The new config gets both right all three times: 6 out of 6.

These are example numbers, not measured results.

What counts as a pass?

The trace and independent evidence, such as a test result or an audit record, must show the expected outcome and that the agent followed the rules. For a larger benchmark, report the pass rate by case and give each group of related cases equal weight. If a planned comparison is missing or you cannot confirm the config, report the gap and leave the overall score blank.

Can a higher score hide a failure?

No. If the new config lets an agent act without required approval or write outside its assigned checkout, put the change on hold. Track time, tokens, and avoidable approval requests separately. Faster work does not make an unsafe run a pass.

Then check normal work

After the benchmark, review the next comparable real task. Check its outcome against a work artifact or independent receipt. Save the result, known config revision, and available measurements in a separate Git branch. Keep raw traces out of Git. This shows whether the change appears to help in practice. It does not isolate the effect of one commit.

The example above explains the scoring method. No measured comparison is reported here.

This follows the same idea as Toyota’s “go and see” practice: observe the work before changing the process. In agent engineering, Anthropic’s evaluation guide recommends starting with real failures and turning them into repeatable checks.

A prompt you can reuse

The instruction I use for the review

Set the sessions, time range and outcome. Choose a focused review or a full config audit. The first pass is read-only. Run and score the comparison only after the change is approved.

Review the agent workflow using actual session traces and the OpenCode config on main. Help agents deliver useful work with fewer unnecessary stops, handoffs, and context costs. Preserve correctness, safeguards, and human control.

Scope: [Sessions, time range, intended outcome, and focused review or full config audit.]

  1. Start with the traces. Compare the intended outcome with what happened. For each material stop, repeated check, handoff, or failure, say who acted, what they knew, what guidance they loaded, and the outcome. Include good decisions and valid approval gates. Cite the event and relevant revision. If you cannot confirm what the agent loaded, say so.
  2. Audit the config as a system. Review AGENTS.md, agent instructions, skills, and workflows. Follow the relevant rules for a focused review or audit all of main. Find unclear, conflicting, stale, or duplicated rules. Name the source of truth and who owns each action. Check how the agent discovers the instruction. Separate a config defect from an interpretation, a project constraint, or a tool or environment limit.
  3. Walk through representative cases. Cover parallel planning and implementation, pickup of an approved change, correction of an active OpenSpec change versus the baseline, and an approved deployment test that hits a blocker. Compare a reversible in-scope decision with a real owner approval gate. Trace who acts, what they read, and what happens next. Flag needless approvals, tests, fixture work, or handoffs. Label each case as observed, a written walkthrough, or awaiting a live run.
  4. Check context and token costs. Distinguish always-loaded rules from skills loaded on demand. Report fresh input, cached input, and output separately where data exists. Check large tool outputs, repeated calls, and handoffs before blaming prompt size. Keep shared rules in AGENTS.md, role decisions in agent files, and procedures in skills where that helps discovery. Explain who benefits from each trim, what it saves, how the agent will find the rule, and what must stay.
  5. Recommend the smallest useful change. Report findings in priority order. For each, cite the file and section, practical impact, likely cause, confidence, and fix. Say what must stay unchanged. Prefer clarifying or consolidating an existing rule. Say when no config change is justified.
  6. Plan verification during the read-only review. For each proposed behavior change, specify one case that should proceed and one that must still stop or ask. Define the expected outcome, required safeguards, evidence, and measurements before any runs.

Keep the first pass read-only. Do not edit, commit, push, deploy, or steer sessions. Omit private details.

After I approve a change, verify, score, and record it. Apply only the approved change. For a behavior change, run the planned cases on the exact old and new config revisions under matching conditions. Confirm what each run loaded and verify outcomes independently. Report pass rates and any safeguard failures. Put serious violations on hold. Report missing or incomparable evidence instead of an overall score. Report effort separately from pass rates. Save the comparison in the verification history without raw traces or private details.

Check the next comparable live work separately. Record what improved, what did not, and what is still unknown. Do not attribute the result to a commit if you cannot confirm which config loaded. A passing static check is not proof of better behavior.

Why I ask in this order

  1. Set the scope and use the rules from that run

    A time range keeps the review focused. The config revision and approvals show what the agent was expected and allowed to do. A rule added later is not evidence that the agent ignored it.

  2. Find the first decision that mattered

    The final error may be a symptom. Looking at the evidence available at the time shows whether the agent had a better next action, without relying on hindsight.

  3. Choose the fix after finding the cause

    A missing rule may need a config edit. A correct rule that was not loaded may need clearer routing. A real permission gate should stay. Asking what could continue prevents one blocker from stopping unrelated work.

  4. Check what the agent actually loaded

    Repeated rules in a file do not always reach the model. Compare what is always present with what loads on demand before estimating a saving. Keep a short cue where the agent needs it to find the full rule.

  5. Check where tokens went

    Large tool outputs, repeated file reads, and repeated delegation can grow context. Compare what each step cost with what it changed. Cached input is not fresh input, and token volume is not the same as a bill. Without per-step data, report the pattern without inventing an exact breakdown.

  6. Define a result before applying a fix

    The next run must show a better decision or outcome. A committed instruction, a passing static check, and better behavior in a live run are three different claims.

An observed example

A launch dependency does not have to stop development.

What the trace showed

One session was proving a new connection path. Another was planning retirement of the old setup guide. The active specs disagreed about whether the guide must remain available. That was a real spec conflict, but the guide was not needed to verify the connection.

What changed

Retirement kept one owner and stayed a condition for public launch. The connection session continued its own work. The planning rule now favors the smallest useful change with its own pass condition and records exactly which step a dependency blocks.

What would confirm the fix: On the next comparable plan, the reviewer catches overlapping requirements before implementation pickup. Each outcome has an owner and pass condition. A launch-only dependency does not stop an unrelated check. This is the expected result, not a verified outcome of the new rule.

An observed example

Separate checkouts did not stop cross-checkout reads.

What I saw

An implementation session needed an agreed spec. It read files from another session’s worktree, a separate checkout of the same repository. I saw reads, not edits. The risk was using a draft that could change during the task.

What I changed

The session now has a clear instruction: read committed files through Git from its own checkout. Do not inspect another session’s live files. Cleanup of completed checkouts stays a separate, scoped task.

What would confirm the fix: In the next comparable run, the agent finds the correct committed spec and continues without opening the other checkout or asking me for access. The config change is in place. That live result is not yet confirmed here.