Lecture 8

Agentic AI for Environmental Data Science

Byeong-Hak Choe

SUNY Geneseo

November 2, 2026

Today’s research task

Use Codex to produce one research artifact that you can verify.

By the end of class, you should be able to:

  • Explain how an AI agent uses files and tools.
  • Give it a task with a clear output and stopping point.
  • Check environmental data before accepting an analysis.
  • Explain which decisions and conclusions remain yours.

Why researchers use agents

Goldsmith-Pinkham emphasizes faster implementation and understanding the tools’ limits.

For our class, useful work includes reading unfamiliar R scripts, diagnosing a failed join, and rebuilding a figure.

The learning goal is to explain the result and how the workflow produced it.

The model and the agent system

Part Role
Language model Generates a response or requests a tool action from the context it receives
Agent application Organizes the work, invokes available tools, and returns their results to the model
Environment Supplies files, installed software, and configured access boundaries

The surrounding system determines which actions a model can carry out.

What makes an AI system agentic?

An agent uses a model to choose and carry out steps toward a task.

Ingredient In our research workspace
Goal Audit a county-day smoke file
Tools Read files, write R code, run commands, inspect outputs
Working context Your question, instructions, data dictionary, recent results
Feedback An error message, a failed check, or your correction
Boundaries Allowed files, actions, data, and resource limits

A chatbot answer and a project agent

Interaction Typical artifact What you inspect
“How do I join these tables?” An explanation or code snippet Does the idea make sense?
“Write and run this join in my project” Changed files and an output table The code, keys, row counts, and unmatched observations
“Check this result against the inputs” A reproducible check Whether the check catches a real possible error
dplyr::left_join(smoke, weather, by = c("GEOID", "date"))

A successful command can still produce an incorrect dataset.

Ways to use AI for coding

Form of assistance What it adds
Chat or autocomplete Suggestions you run and inspect
Agent in an editor Work across project files
Dedicated project agent File edits and command execution
Connected tools Access to approved external systems
Extended autonomous work Longer tasks within configured boundaries

For this class: a project agent with a small task and visible outputs.

Adapted from the tool ladder in Goldsmith-Pinkham’s post. Choose a configuration that fits the task.

What actually runs the analysis?

An agent can write a command such as:

Rscript R/01_audit.R

For our local starter:

  • R executes the script on your computer.
  • The filesystem stores the input CSVs and saved audit.
  • Codex can inspect the command’s output and respond.
  • You check whether the reported result answers the task.

The agent’s work cycle

  1. Inspect: read the project plan and a small input sample.
  2. Propose: identify the key, transformations, and expected output.
  3. Execute: write and run a script within the agreed task.
  4. Check: compare actual outputs with explicit expectations.
  5. Report: save the artifact, limitations, and next step.

You can correct the task when the output reveals a problem.

What should happen if the proposed key is not unique?

An example conversation

Illustrative dialogue using our synthetic starter:

Student: Read the data README and explain the two CSVs.
Agent:   Both describe county-days. Weather repeats a key.
Student: Run the supplied audit and show the actual result.
Output:  Audit saved. Execution stopped on duplicate keys.
Student: Show the repeated records and explain the problem.
Agent:   This exact weather record appears twice.
Student: Propose a derived-data fix and checks before joining.

Each follow-up uses evidence from the previous step.

The context window

Context is the working material available to the model for a response.

It can include:

  • Your task and the applicable instructions.
  • Relevant conversation history.
  • Selected file contents and documentation.
  • Tool results, including errors and computed summaries.

Its capacity is finite and model-dependent, measured in tokens: pieces of text or code.

Working context and project memory

Record Purpose
Current context Supplies material for the next response
project-plan.md Preserves the agreed question and definitions
lab-notebook.md Records decisions, actual checks, and open issues
Scripts and outputs Preserve the analysis and its evidence

Compaction reduces earlier context while carrying important state forward.

Saved project records let you check and reconstruct that state.

Official compaction overview. The file choices are our course workflow.

A checkpoint before the next task

Update lab-notebook.md with:
- the task and exact input files;
- decisions we made and why;
- scripts and outputs created;
- commands and checks that actually ran;
- unresolved issues and one concrete next task.
Keep failed checks visible. Do not report planned work as done.

When continuing: read the checkpoint, inspect the files, verify the state.

Illustrative wildfire projects

Project Research question Useful next artifact
Transportation Does Canadian wildfire smoke disrupt transportation in the Northeast? A checked airport-day dataset and an episode figure
Preseason moisture Can winter and spring moisture predict Canadian burned area? A checked province-year predictor table and a forecast evaluation plan

These are research questions, not established findings.

Illustrative course cases. Context: wildfire research guide.

Applications across environmental data science

Work A bounded agent task Human check
Data acquisition Download one documented public release Provider, version, licence, coverage
Data cleaning Build a county-month panel Units, keys, missingness, sample loss
Spatial analysis Join airport points to counties Coordinate system and unmatched points
Forecasting Compare a baseline with one model Timing, held-out years, leakage
Communication Rebuild a figure and check its caption Values, comparison, interpretation

Research decisions that need your judgment

Decision Why it matters here
Observation unit Airport-day and county-day measure different things
Exposure Smoke overhead differs from smoke near the ground
Comparison A smoky June day also has particular weather
Forecast date A June 1 forecast cannot use observed July weather
Claim Forecast accuracy and a causal effect answer different questions

Codex can propose options and identify consequences. You defend the choice.

Course context: wildfire research guide and data guide.

A suitable system for this class

Wildfire Research Lab: one Codex workspace per project.

  • A short project plan states the question and data definitions.
  • AGENTS.md records recurring project instructions.
  • R scripts produce derived data, checks, and figures.
  • One lab notebook records decisions and verified progress.
  • A classmate checks the artifact before the team accepts it.

Begin with one agent working on one bounded task.

The project folder

wildfire-project/
  AGENTS.md
  project-plan.md
  lab-notebook.md
  data/
    README.md
    raw/
    derived/
  R/
  output/
    checks/
    figures/
  report.qmd

Raw inputs stay as received.

Scripts explain every transformation.

Outputs are rebuildable.

Notes preserve the reason for each important choice.

Companion template: download the starter and read the instructions. Create analysis scripts and report.qmd as the project develops.

A project plan that supplies useful context

Field Transportation pilot Moisture pilot
Unit Airport × local calendar day Province × year
Outcome Cancelled / scheduled flights Annual burned area, hectares
Input County surface-smoke estimate Moisture known by June 1
First scope Selected airports, June 2023 A small province/year extract
First output Intake audit and episode plot Predictor audit and split diagram
Claim limit Descriptive episode evidence Forecast feasibility

The first Codex session

  1. Open a copy of the starter as its own project folder.
  2. Sign in using your own ChatGPT account in your Codex client.
  3. Ask Codex to summarize the project instructions and files.
  4. Start with the supplied synthetic-data audit.
Read AGENTS.md and project-plan.md. Summarize the active
instructions, available inputs, and proposed first check.
Do not change files during this inventory.

Official guidance: project instructions with AGENTS.md. Client access and settings may differ.

The student credit pilot

The two students will apply individually through the official offer.

  • Eligible verified university students in the U.S. and Canada can receive $100 in ChatGPT credits for Codex.
  • Eligibility includes enrollment and residence requirements. Approval requires verification.
  • Credits expire 12 months after the grant.
  • These are Codex usage credits, separate from API credits.

Use the same research workflow even if verification is pending.

Codex for Students: eligibility and claim link, checked November 2, 2026. Recheck before applying.

A prompt with a clear finish line

Include the input, task, output, checks, and boundaries.

Read data/raw/smoke_toy.csv and weather_toy.csv.
Write R/01_audit.R to audit county-day keys and missingness.
Save the actual checks under output/checks/.
Keep GEOID as text and preserve raw inputs.
Report duplicate keys, negative smoke, and missing weather.
If the join key is not unique, report the problem and stop
before creating an analysis panel.

“Done” means a saved artifact and the actual check results, including failures.

A real-data audit after the toy example

Use the Lecture 6 extract
wildfire_smoke_county_day_2023_06.csv.
Read the course data documentation first.
Write an R script that reports rows, county-day uniqueness,
date coverage, missing values, and smoke ranges.
Keep negative estimates. Check GEOID as five-character text.
Save the audit and one descriptive figure for June 2023.
State the source, units, and every check that actually ran.

Start with an instructor-supplied copy of this small teaching extract.

What belongs in an audit?

Check Evidence to save
Grain and key One row represents what? Is the key unique?
Coverage Dates, places, and expected versus observed rows
Values Units, ranges, missingness, and documented exceptions
Join Rows before/after, unmatched keys, duplicated matches
Sample Observations lost at each restriction
Provenance Provider, release, access date, licence, input file

“I checked the data” needs an output you can inspect.

Environmental variables measure different things

Variable What it measures Interpretation risk
FIRMS detection A satellite detection of active burning Counting detections as individual fires
HMS plume Smoke identified overhead Assuming surface exposure
CSU / Childs smoke Estimated surface smoke PM2.5 Treating products as interchangeable
Nearby Canadian fire share Canadian share of nearby fire radiative power Calling it the fraction of smoke inhaled from Canada

The nearby-fire share is a descriptive attribution proxy.

Missing, zero, and negative values

  • Missing weather: retain NA until you justify a treatment.
  • Zero cancellations: valid when scheduled flights are positive.
  • Zero scheduled flights: the cancellation rate is undefined.
  • Negative CSU smoke estimates: retain them in the continuous series, as the guide specifies.
  • No fire-share row: the share may be inapplicable. Read smoke from the full CSU series.

A plausible merge error

Synthetic example: smoke has one row for a county-day.

Weather input County Date Precipitation, mm
Row 1 06037 2023-06-07 0
Row 2 06037 2023-06-07 0

Joining on county and date gives that smoke observation two matches.

  • The command can succeed.
  • The dataset now gives this county-day extra weight.
  • An exact duplicate needs a documented resolution in the cleaning script.

A key check in R

smoke <- read.csv("data/raw/smoke_toy.csv",
                  colClasses = c(GEOID = "character"))
weather <- read.csv("data/raw/weather_toy.csv",
                    colClasses = c(GEOID = "character"))
key <- c("GEOID", "date")
stopifnot(!anyNA(smoke[key]), !anyNA(weather[key]))
stopifnot(!anyDuplicated(smoke[key]))
stopifnot(!anyDuplicated(weather[key]))

The final line should fail on the supplied weather file.

Transportation: first agent task

Pilot: one month of flight operations at selected airports.

  • Begin with JFK, LGA, EWR, and PHL in June 2023.
  • Compute cancellations divided by scheduled flights by airport-day.
  • Map each airport to a county and audit the matches.
  • Join the full county-day surface-smoke series.
  • Plot June 1–15 with clear units and source notes.

The episode figure establishes feasibility and suggests patterns to investigate.

Illustrative course pilot. Context: wildfire research guide.

A transportation pilot prompt

Read project-plan.md, the BTS dictionary, and the course
smoke guide. Inspect one June 2023 flight extract.
Build one row per origin-airport and local flight date.
Report scheduled, cancelled, and cancellation rate.
Audit airport-to-county matches and the smoke join.
Save a sample-loss table and a June 1–15 episode figure.
Keep the complete smoke series, including negatives.
Do not interpret missing smoke as zero or invent data.
If an input is unavailable, report the missing input.

Transportation design review

Issue What the student needs to defend
Weather Could weather drive both smoke transport and cancellations?
Visibility Could this be part of smoke’s mechanism?
Network effects Could smoke at other airports disrupt this airport?
Dependence Do airports share smoke shocks on the same date?
Outcome Do zero cancellations and zero scheduled flights differ?

An accurate prediction of cancellations does not by itself identify smoke’s effect.

Moisture: first agent task

Pilot: preseason moisture and province-year burned area.

  • Specify a forecast date, such as June 1.
  • Inspect a small monthly moisture extract before a large download.
  • Build features using the agreed preseason windows.
  • Audit coverage, units, geography, and historical availability.
  • Link to the documented NBAC burned-area outcome.

Keep the burned-area/eastern-smoke relationship as a separate descriptive link.

Illustrative course pilot. Context: wildfire research guide.

A moisture pilot prompt

Read project-plan.md and the predictor documentation.
List which features could be known by June 1.
Inspect the supplied moisture and NBAC extracts.
Build a province-year audit with units and coverage.
Flag features that use later-season observations.
Propose evaluation that holds out entire years.
Compare a simple model with a training-only climatology.
Fit all preprocessing within each training sample.
Save the feature definitions and unresolved decisions.

Forecast evaluation that respects time

Evaluation choice Research purpose
Hold out every province in the same year Keep a shared fire season together
Train on earlier years, evaluate on later years Approximate a future forecasting task
Fit imputation and scaling on training data Prevent information from the evaluation sample leaking in
Compare with training-only provincial averages Measure improvement over a simple baseline
Examine performance with and without 2023 Reveal dependence on one extreme season

A literature assistant needs evidence locations

Paper Useful question for the agent What you verify
Childs et al. (2022) How is surface smoke estimated? Product definition and limitations
Borgschulte et al. (2024) How are smoke and labor outcomes linked? Outcome, time unit, and design
Jain et al. (2024) Which conditions characterized Canada’s 2023 season? Evidence for each proposed mechanism

For every claim, save a page, section, figure, or table. Use “not found” when needed.

Writing and thinking with AI assistance

Write your interpretation first. Then ask:

Compare my paragraph with output/tables/ and the figure.
Identify unsupported numbers, missing units, and causal
language that the design does not justify.
Suggest edits and explain each substantive change.
Do not introduce new results or references.

Every reported number should lead back to an output and a script.

Permissions and data access

Control What it does
Sandbox Enforces configured filesystem and network boundaries
Approval policy Determines when an action requires approval
AGENTS.md Gives instructions the agent should follow
Git Records selected file changes for review and recovery

For the pilot, use public teaching data and bounded project writes.

Opening a folder or adding .gitignore does not isolate its contents.

Official sandbox and approval guidance, checked November 2, 2026.

Course data boundaries

  • Use the approved fire, smoke, air-quality, weather, population, and boundary data.
  • Add documented public transportation or moisture inputs for the approved project.
  • Keep passwords, API keys, student records, and restricted microdata out of the agent workspace.
  • Do not request, open, or share 2006–2026 mortality files. The umbrella project remains outcome-blind.

Review before accepting an artifact

  1. Read the changed code or Git diff.
  2. Run the script and inspect its checks.
  3. Verify two or three records by hand.
  4. Open the figure and explain its units and comparison.
  5. Record unresolved issues in lab-notebook.md.

A fresh Codex review can suggest problems. A classmate and source checks supply additional scrutiny.

Keeping the pilot manageable

  • Give Codex one artifact at a time.
  • Inspect a schema and a small sample before a full archive.
  • Reuse saved inputs and rerunnable scripts.
  • Save a short checkpoint before beginning a new task.
  • Check account usage and the remaining credit balance.

Track review time and useful artifacts, as well as agent usage.

Lab: the duplicated county-day

Use the supplied synthetic files in agentic-ai-starter/.

Minutes Task Artifact
0–4 Open inputs and run the audit An actual failure report
4–10 Inspect and resolve the exact duplicate in a script A documented cleaning decision
10–16 Join without changing missing or negative values A six-row derived table
16–20 Check records and explain the result to a partner A notebook entry
Rscript R/01_audit.R

Lab acceptance checks

  • GEOID remains text, including 01001.
  • The derived weather table has six unique county-day keys.
  • A left join produces six rows with no unmatched smoke keys.
  • One precipitation value remains missing.
  • The negative smoke value remains in the continuous series.
  • A partner can explain the duplicate decision and verify two rows.

The notebook distinguishes checks that passed from work still proposed.

Exit ticket

For your own project, write:

  1. One task: name the input and the artifact Codex should produce.
  2. One check: identify an error that could survive a successful run.
  3. One decision: explain what you must judge yourself.

Bring the artifact, its checks, and your explanation to the next project meeting.

Appendix: adapting the mini-series, 1–4

Paul Goldsmith-Pinkham’s installment Transfer to this class
1. Getting started A project folder, durable context, and a bounded first task
2. Empty folder to figure A script that rebuilds a documented smoke figure
3. Documents to structured data Evidence cards from supplied wildfire papers, with locations and spot checks
4. Large datasets Inspect coverage and harmonize a small sample before scaling

Appendix: adapting the mini-series, 5–8

Paul Goldsmith-Pinkham’s installment Transfer to this class
5. Writing and thinking Student interpretation first, then a check against results
6. Skills Save a repeated, tested audit workflow
7. Permissions and sandboxes Explicit access boundaries and approved public data
8. Integration and collaboration Small changes, decision records, sample-loss reports, and traceable outputs

Appendix: what belongs in AGENTS.md?

Use R and project-relative paths.
Read project-plan.md and data/README.md before analysis.
Preserve raw inputs and document derived transformations.
Check keys, units, missingness, and sample losses.
Keep claims tied to sources and generated outputs.
State what actually ran and what remains unresolved.
Use public, approved data; exclude 2006–2026 mortality.
Complete bounded local work within the authorized task.
Ask before changing the scientific scope or spending money.

Keep instructions short enough that students can understand and maintain them.

Official AGENTS.md guidance. The companion starter contains a complete teaching version.

Appendix: skills after a successful first workflow

A skill packages a reusable procedure and its instructions.

Proposed teaching skill Observable output
Data audit Keys, coverage, missingness, merge and attrition checks
Figure review Units, geography, sources, and agreement with data
Research checkpoint Verified progress, decisions, open issues, next task

Repository skills can live under .agents/skills/, each with SKILL.md.

Official skill documentation. These are proposed course skills, not preinstalled features of the starter.

Appendix: a review prompt

Review this artifact without editing files.
Read the question, data definitions, script, and output.
Check the observation unit, keys, missingness, and units.
Look for leakage or unsupported causal language.
Recompute one reported value from the supplied inputs.
Report each material issue with file/line or output location.
Distinguish verified problems from questions and suggestions.
Do not treat a successful run as proof of validity.

Give the reviewer the actual evidence, including failed checks.

Appendix: adapting the instructor’s system

Existing Co-Author practice Undergraduate version
Research strategy and project memory One project plan and one lab notebook
Data engineering and provenance Immutable inputs, documented scripts, source manifest
Claim-source map Each claim linked to a source or generated output
Creator and critic roles Student/Codex implementation plus classmate review
Quality gates Concrete checks with observable evidence

Specialized roles, hooks, dashboards, and journal submission workflows can wait.

Appendix: a two-student rollout

Stage Deliverable Instructor review
First session Synthetic audit and corrected join Can the student explain every check?
Next project task One real input audited Are data access and definitions settled?
First analysis Reproducible figure or baseline forecast Do claims match the design?
Pilot review Short account of usage, corrections, and review time What helped, and what should change?

Expand the system when the project produces a clear reason to do so.

Appendix: sources and further reading