Module 4: Agents / Harnesses

AI-Powered Coding and Data Analysis

Exercise: the project you set up in Module 3 (Download ZIP)

GitHub repository

Agents and harnesses

In Module 2 you copied and pasted code, results, and context back and forth between your project and the chat window. The chatbot never saw the data, the codebook, or the output, and it couldn’t run code. An agent reads the project files and runs code itself.

Agents

An agent is a harness around a model. The model can:

  • read files in the project,
  • search the project for context,
  • edit files directly, and
  • run code and read the errors.

A typical agent task runs like this:

  1. You give a task, such as “Create a summary table for this dataset.”
  2. The agent explores the project folder.
  3. It writes and saves the code.
  4. It runs the code, reads the errors, and fixes them.
  5. It reports the result.

Three harnesses/model providers on one project

Tool Location Access
Posit Assistant RStudio pane R session and project files
Claude Code Terminal in the project folder Project files and shell
Codex Terminal in the project folder Project files and shell

Posit AI and Claude Code use Anthropic models. Codex uses OpenAI models.

Exercise

I am going to do this live. You can follow along in the tool you set up.

I run each prompt in Posit Assistant (inside RStudio), Claude Code, and Codex (both from a terminal in the project folder), and we compare the three results as a class.

Prompt 1a: describe the data

We're analyzing the data in inputs/raw/. Read inputs/raw/subgroup_estimates.csv and inputs/raw/codebook.md.

Tell me:
- what one row represents
- what needs cleaning before we can summarize or plot it
- what checks you would run

Don't write any code yet; wait for my answer.

Read the description and reply. Correct anything that’s wrong before you send prompt 1b.

Prompt 1b: clean

Write R code in notebooks/01_cleaning.qmd that cleans the data and saves it to inputs/final/. Ask me before making any judgment call, such as relabeling, deciding what counts as missing, or dropping rows.

Prompt 2: summarize

Using the cleaned data in inputs/final/, fill in notebooks/02_summary.qmd with:
- counts by measure and by subgroup category
- mean, minimum, and maximum estimate by measure
- a short interpretation of what these summaries show

Save summary tables to outputs/tables/.

Prompt 3: analyze and plot

Using the cleaned data in inputs/final/, fill in notebooks/03_analysis.qmd with one simple comparison of estimates across subgroups and one figure that's easy to read in a short report. Pick a comparison that includes at least one missing or suppressed subgroup, and show it on the figure. Keep the figure to one panel. Include a brief interpretation and its limitations. Save the figure to outputs/figures/.
TipCheck the work

Agents rarely fail outright. They make mistakes that propagate, and syntactically valid code can still be statistically wrong.

  • Read the code before running it.
  • Confirm that the row count matches the raw file.
  • Check how the agent handled --, Suppressed, NA, and not available.
  • Check whether “Unknown” was kept as a subgroup.
  • Read the label lookup and decide whether you agree with each rename.
  • Look for hard-coded numbers such as == 22. They break when the data change.
  • Check whether the agent changed files you didn’t ask about.
  • Recompute one summary number by hand.

Points to notice

  • Each subgroup category comes from one state and one measure. A comparison across categories is confounded by state and measure. Did the agent say so?
  • Compare the three tools as a class: the questions each one asked before a judgment call, how each relabeled the categories, the row counts in each clean file in inputs/final/, and the figure each one made.