Opening the book…
AI coding agents can write WeBWorK PG problem files for you, so you can focus on your subject expertise instead of learning Perl syntax. Think of it like directing a trained lab technician: you describe the experiment you want, and the technician carries out the procedure. You still need to know what a good result looks like, but you do not need to pipette every reagent yourself.
Since late 2025, several AI coding agents have become capable enough to produce working WeBWorK problems from a plain-language description. This chapter walks you through choosing an agent, giving it the right reference material, connecting it to a local renderer so it can test its own output, and refining your prompts to get better problems with less back-and-forth.
What is your goal today?
Use this table to jump straight to the section that matches what you want to do. If you are not sure where to start, read the "Start here" list below the table.
| What you want | Go to | What you will find |
|---|---|---|
| Understand what AI agents are and which ones work for WeBWorK | What are AI Agents? | Overview of coding agents, comparison of current options, and what to look for when choosing one |
| Set up documentation so the agent writes correct PG code | Knowledge Documents for AI Agents | How to prepare and organize reference files the agent reads before generating problems |
| Connect the agent to a PG renderer so it can test its own output | Connecting AI Agents to the PG Renderer | Step-by-step setup for giving your agent access to a running renderer and interpreting the results |
| Write better prompts and refine complex problems | Advance AI Agents Advice | Prompt-engineering techniques, iterative refinement strategies, and handling edge cases |
Section map
| Section | What it covers |
|---|---|
| What are AI Agents? | What coding agents are, how they differ from chatbots, and a comparison of agents that can produce WeBWorK problems. |
| Knowledge Documents for AI Agents | How to assemble and maintain the reference documents an agent needs to write correct, idiomatic PG code. |
| Connecting AI Agents to the PG Renderer | Giving your agent access to a local PG renderer so it can compile, render, and self-correct its output. |
| Advance AI Agents Advice | Prompt-engineering tips, iterative refinement workflows, and strategies for complex multi-part problems. |
Start here
- If you have never used an AI coding agent, start with What are AI Agents? to understand what they are and pick one that fits your setup.
- If your agent writes code that does not render correctly, read Knowledge Documents for AI Agents to give it better reference material, then Connecting AI Agents to the PG Renderer so it can test its own output before you review it.
- If your agent already produces working problems but you want better results, go to Advance AI Agents Advice for prompt-engineering techniques and refinement strategies.
Prerequisites
- A running PG renderer on your local machine (see Setting Up the PG Renderer).
- Basic understanding of WeBWorK problem structure (see Problem Generation (PG)).
- An AI coding agent installed on your computer (see What are AI Agents? for options and installation links).
Apply it today
- Use the decision table above to jump directly to the section that matches your current goal instead of reading the chapter front to back.
- If this is your first time, install an agent from the list in What are AI Agents? and try asking it to write a simple multiple-choice question about your favorite color to confirm the workflow end to end.
- 8.1: What are AI Agents?
- Focuses on experimental design and controls as concrete decision items that grade reliably. After finishing, you can write control-selection prompts that are anchored to a specific confound or threat to validity. Use it when writing biology design questions about treatments, vehicles, and confound isolation.
- 8.2: Knowledge Documents for AI Agents
- Explains why agents need WeBWorK-specific documentation to avoid PG sandbox traps and introduces the ready-to-install webwork-writer skill with its ten reference documents. After finishing, you can install the skill with one command, understand what topics the documents cover, and assemble custom documents if preferred. Use it before your first agent session to ensure the agent has reference material for correct PG code.
- 8.3: Connecting AI Agents to the PG Renderer
- Walks through connecting an AI agent to a local PG renderer so it can test and self-correct its output, with a timing table for simple and complex problems. After finishing, you can configure the agent to POST to localhost:3000, interpret error flags, and use fixed seeds during development. Use it after installing knowledge documents and before asking the agent to write its first problem.
- 8.4: Advance AI Agents Advice
- Covers prompt engineering with a detailed elements table, a three-pass iterative refinement workflow, accessibility guidance for color-blind users, a worked amino acid isoelectric point example, and a common pitfalls table. After finishing, you can write detailed prompts that produce polished problems, use high-contrast color pairs, and scale to many problems using templates and batch rendering. Use it when you have a working agent setup and want higher-quality output.
This page titled 8: Using AI Agents to Write WeBWorK was last modified on Fri, 27 Feb 2026 14:54:53 GMT and is shared under a CC BY 4.0 license and was authored, remixed, and/or curated by Neil R. Voss.
The book could not be loaded just now.