Using AI Agents Effectively

SENG 365 — Software Engineering

Neil Ernst

University of Victoria

Neil Ernst

2026-11-05

Learning Objectives

Learning Objectives

After this lecture you can:

  • Follow a careful process for working with an agent: understand, plan, implement
  • Steer an agent with context: a context file, a spec, a plan
  • Check its output with tests and evals, not trust

Caveats

  • I am learning as I go, as you are.
  • Things have moved fast, and there are many tools to choose from.
  • More effective models tend to cost more.
  • I don’t believe AI will replace thinking.

Contrarian Perspective

@hardin.bsky.social

How I Use It

  1. To answer questions about background I forgot or didn’t know
  2. To write scripts to manage notes and marks, format slides
  3. To code up answers to the exercises, to test my questions

I do not use it to mark your assignments.

How to Use AI as a Student/Developer

Simple Is Not Easy

Emphasize craftsmanship. There is a difference between what is “simple” and what is “easy”.

Simple is hard work. Vibe coding is easy.

AI rewards having a structured, careful development process.

A Careful Development Approach

via https://www.arthropod.software

A Rational AI Design Process and How To Fake It

  1. Think hard and chat about the problem and the changes you need before doing anything
  2. Keep components encapsulated with carefully designed interfaces
  3. Control the scope of your changes; current AIs work best at the function or class level

A Rational AI Process (2)

  1. Testing and validation: how do you know your program works?
  2. Good manual debugging skills (students found AI debugging unreliable)
  3. General system knowledge: networking, OS, data formats, databases

One Approach

Phase 1: Research and Problem Understanding

Use the AI to map the codebase, identify dependencies, and help you understand the problem.

Your insights keep the AI on track.

Phase 2: Planning as Design Thinking

Get the AI to create a detailed implementation plan, perhaps as a Markdown checklist.

This separates the what from the how.

Phase 2: Review the Plan

Humans now conduct a thorough design review of the plan.

Look for overly coupled components, poor modifiability, obvious design smells.

Phase 3: Implementation as Execution

The AI translates the plan into code.

Kent Beck suggests this only works with a rigorous test suite (TDD). The tools will optimize, which includes lying to you!

Design Cycle

via arthropod.software

Practical Advice

Steps

  1. Manage context with a global or project context file
  2. Prompt the AI with design questions and get a spec for the task
  3. Revise the spec, ideally with two humans, and update it
  4. Think about tests for the AI’s suggestions: how will you validate them?
  5. Generate code in small chunks, one per task in the spec
  6. Test the code; repeat 4 to 6

Prompt Files and Context

Create a project-wide context file in your repo root:

  • CLAUDE.md for Claude Code
  • .github/copilot-instructions.md for Copilot
  • GEMINI.md for Gemini CLI
  • AGENTS.md: a generic file read by many agents (Codex, Copilot, OpenHands and others), so one file can serve a mixed team

What Goes in the Context File

  • coding conventions
  • rules around the scope of suggested changes
  • tech stack restrictions
  • context on your team as learners (do you know a LOT of JavaScript?)

Example Context Files

Generating a Spec

Use the AI to brainstorm the steps in the building process. Give it your project context AND your team’s context (skills, gaps). Work one step at a time.

The Spec Prompt

Now that we’ve wrapped up the brainstorming process, can you compile our findings into a comprehensive, developer-ready specification? Include all relevant requirements, architecture choices, data handling details, error handling strategies, and a testing plan so a developer can immediately begin implementation. Write this to the file spec.md.

Moving to Implementation

Get your teammates to check the proposed spec. You can also ask other LLMs to revise it.

Then ask the AI for a detailed set of implementation steps. Save it as something like prompt-plan.md.

Add a todo.md so the AI can check steps off as it finishes them.

Implement and Test

Run the steps in an agent: Claude Code, Copilot CLI, Gemini CLI, Aider.

Aside: the model is not the tool. The same model behaves differently in different tools.

Verifying Outputs

You need a way to confirm the code does what you want.

Get the AI, maybe a different one, to create some integration tests for what you are looking for.

Keep the Tests Apart

Always ask for tests as part of the normal workflow.

Keep the integration tests separate: no shared context with the code writer.

Kent Beck: Warning Signs

What were the warning signs that told you the AI was going off track?

  • Loops.
  • Functionality I hadn’t asked for (even if it was a reasonable next step).
  • Any indication that the AI was cheating, for example by disabling or deleting tests.

Demo: Spec, Plan, Implement

Follow Along

Do this with me, on your own laptop.

  1. Make an empty folder
  2. Run git init in it
  3. Open it in your agent (any one you have)

Nothing else. The agent’s plan sets up the project.

The Demo

A JavaFX app that shows the local weather (A4-6 in one go)

  1. A spec: research and planning, in Bram, using GitHub
  2. A plan: reviewed in Bram and VS Code
  3. An implementation, one slice at a time, in Claude Code

Bram

Bram, from Jon Udell, is a workspace for working with an agent.

Three levels of ceremony: just do it, worklists, GH Pull Requests.

The agent proposes each change as a worklist item. I read it, then approve, ask for changes, or drop it.

I use it for the research and planning steps, and then kick off the agent for implementation. Integrates nicely with Github (not Gitlab, sadly).

Step 1: Spec

I start with an empty folder and an empty CLAUDE.md (with Bram stuff).

I tell the agent the stack: Java 25, Gradle, JavaFX.

In Bram, I ask the agent questions, one at a time, then ask it to propose a PRD as spec.md.

Watch for: what I correct, and what the agent assumed that I never said. (lots!)

Step 2: Plan

I ask for a plan (CLI: as Markdown checklist), proposed in Bram.

I review the implementation plan as a design before approving it: is anything coupled that should not be?

Small changes are easier to back out.

Step 3: Implement

One slice at a time. Tests first.

I run the tests and read the diff before I accept anything.

Watch for: the Kent Beck warning signs: loops, extras, cheating.

Adding Context

What Is Context?

context venn diagram via https://www.philschmid.de/context-engineering

Building Good Prompts

As Simon Willison writes,

The entire game when it comes to prompting LLMs is to carefully control their context—the inputs (and subsequent outputs) that make it into the current conversation with the model.

So how can we do that?

The Challenge

An LLM is trained on vast amounts of general data, like all of Wikipedia and all of GitHub.

But our problem is a particular one, and we don’t know if the LLM’s distribution matches ours.

So we need to steer it to the space of solutions that apply to us.

Another term for this is context engineering.

Context Issues

Context is not free… every token influences the model’s behavior.

  • Context Poisoning: a hallucination or other error makes it into the context, where it is repeatedly referenced.
  • Context Distraction: the context grows so long that the model over-focuses on it, neglecting what it learned in training.
  • Context Confusion: superfluous information in the context is used to generate a low-quality response.
  • Context Clash: new information and tools in the context conflict with other information in the prompt.

(derived from this article)

Tactics for Improving Context

  1. Use RAG
  2. Be deliberate in tool choice: more tools is not better.
  3. Context quarantine: use sub-agents to isolate (modularity!)
  4. Prune the context: remove unnecessary docs
  5. Summarize: give the model the summary, not everything
  6. Offload: don’t put everything in the context

Harnesses

Model, Agent, Harness

  • The model predicts the next token.
  • The agent is a loop around the model: think, act, look at the result.
  • The harness is the software around the model that makes the loop work.

Claude Code, Codex and Gemini CLI are harnesses. The model is not the tool.

What a Harness Does

Six jobs, from Sebastian Raschka:

  1. Gathers repo context (branch, layout, project docs) before work starts
  2. Keeps a stable prompt apart from content that changes each turn
  3. Offers named tools, and checks each call before it runs

What a Harness Does (2)

  1. Trims long outputs and old history so context does not bloat
  2. Keeps session memory: the full transcript and a smaller working summary
  3. Hands side questions to subagents with tighter limits

Why It Matters to You

  • Your context file is part of the harness’s first job.
  • Permission prompts are the harness’s third job. Read them.
  • The same model in a different harness behaves differently.

Agent Skills

The Problem

You keep typing the same instructions.

“Review my code against these design principles.” “Write the log entry in this format.”

A context file loads every time. Most instructions are needed only some of the time.

What Is a Skill?

A skill is a folder of instructions the agent loads only when it needs them.

.claude/skills/design-check/
  SKILL.md        # name, description, instructions
  toolbox.md      # extra files the instructions use

A SKILL.md

---
name: design-check
description: Review my code against the course
  toolbox and ask questions about my design
  choices. Use when I ask for a design check.
---

Read toolbox.md. For each tool, look for
evidence in the code. Cite file and line.
Ask the tool's question. Do not edit code.

How a Skill Loads

  1. At start, the agent sees only each skill’s name and description
  2. When your request matches a description, it reads the full SKILL.md
  3. If the instructions point at other files, it reads those too

So a skill costs a few lines of context until it is used.

Invoking a Skill

  • Ask in plain words: “do a design check”
  • Or name it: /design-check in Claude Code, $design-check in Codex

The description decides whether the agent picks it up. Write it as “use when…”.

Skill or Context File?

Context file Skill
Loaded Always When relevant
Holds Facts and rules for the project A procedure for one task
Example “Java 25, tests in test/” “How to run a design check”

Tools and Skills

Tool Skill
Is Something the agent can do Instructions on how to do a task
Examples Read a file, run a command, call an API Run a design check; write a log entry
Runs The harness runs it, after checks The agent reads it as text
Comes from The harness, or an MCP server A folder you write

A skill tells the agent which tools to use, in what order, and what to look for.

Where Skills Live

Each tool looks in its own folder:

  • Claude Code: .claude/skills/
  • Codex, Gemini CLI, OpenHands: .agents/skills/

The SKILL.md format is shared, so the same folder works in all of them.

Skills Are Not Magic

  • A skill is text. The agent can still ignore it or misread it.
  • Read what a skill tells the agent to do before you install it.
  • Test it on code you know, and check its output.

Summary

Summary

  • AI can be a powerful multiplier in software engineering.
  • It still requires care and attention when prompting and developing. It is not a substitute for design knowledge.
  • Context matters: move the AI toward the solution.
  • Use evals and tests to check that the AI’s output matches your goals.

Log It

Using AI is an interaction you report. Add an entry to docs/ai-log.md: what you asked, what you got, what you accepted or rejected, and why.

Appendix: Useful Guides

Useful Guides