An agent that answers plain-English questions about power projects that have applied to connect to PJM's grid. PJM is the grid operator across 13 US states and the District of Columbia. The agent gets its numbers from exact database queries, and its explanations from PJM's study reports.
For example, you can ask which solar projects look most at risk of withdrawing, and why. The agent is built to find the projects and their estimated costs in the data, search the reports for the grid upgrades behind those costs, and say where each figure came from. I haven't yet run it with OpenAI's live models, so its answers are untested (see Limitations).
Before a new power plant can connect to the grid, it joins a waiting list called an interconnection queue. The grid operator, the organisation that runs the grid in that area, then studies what the connection would need and cost. Most projects never get built. Lawrence Berkeley National Laboratory (Berkeley Lab), a US Department of Energy laboratory, tracks these queues. Of the capacity that asked to connect between 2000 and 2020, it found that 13% was running by the end of 2025 and 75% had withdrawn (Queued Up).
Cost is one reason. A study can find that the grid needs network upgrades, such as new lines or bigger substations, before the plant can connect, and the plant may have to pay for them. Projects told they need large upgrades tend to withdraw (Gorman and others, 2025). In PJM, projects that withdrew had the highest estimated costs on average, "likely a key driver for those withdrawals". For recent withdrawn projects, network upgrades made up 94% of their average cost (Berkeley Lab, 2023). A withdrawal can also mean new studies for the projects behind it in the queue, which can delay them and raise their costs. The Federal Energy Regulatory Commission (FERC), the US regulator of interstate power transmission, says so in Order No. 2023 (paragraphs 47 and 49).
The data that explains this sits in two places. Berkeley Lab's queue data is a tidy table of each project's size, fuel, dates and status, such as active or withdrawn. The estimated costs, and the reasons for them, are in PJM's study reports: long PDFs full of tables. For its PJM cost study, Berkeley Lab read the costs out of the reports by hand, at 30 to 50 minutes per project on average. I wanted to see whether a language model, the kind of AI behind ChatGPT, could do that reading, and whether an agent could then answer questions from both sources together.
An agent is a language model that can use tools, such as a database query or a search, and read their results before it answers. This one has two tools, one for each source.
query_queueruns SQL, the standard language for asking a database questions, on what I call the panel. The panel is a table with one row per PJM project, built from Berkeley Lab's data and stored in DuckDB, a database that runs on your computer. The agent is told to take every count, total and cost per kW from here, so these come from exact queries rather than from reading text. Its queries can only read the panel, and one still running after 10 seconds is stopped (why). Cost per kW is a project's network upgrade cost divided by its size in kilowatts (a kilowatt, kW, is a thousandth of a megawatt, MW), so projects of different sizes can be compared.search_studiesfinds the passages in PJM's study reports that are closest in meaning to a question. Each report is split into overlapping passages, which the code calls chunks, of up to 1,000 characters. Each passage is stored as an embedding, a list of numbers that captures its meaning, in Chroma, a database for embeddings that also runs on your computer. Handing passages found this way to a language model is called retrieval-augmented generation (RAG). The agent uses them to explain the numbers. It can search every report, or only the report of a project it names.
One step links the two. For each report, a language model reads up to seven passages about its costs and size, and copies out the key figures, such as the totals in its cost summary. The code then works out the network upgrade cost per kW and writes it into the panel.
flowchart LR
LBNL["Berkeley Lab queue data"] -->|make data, make panel| PANEL[("Panel, in DuckDB")]
PANEL -->|make fetch picks the projects| PDF["PJM study reports"]
PDF -->|make embed| VEC[("Passages, in Chroma")]
VEC -->|make extract adds costs| PANEL
Q(["Your question"]) --> AGENT["Agent"]
AGENT -->|query_queue| PANEL
AGENT -->|search_studies| VEC
AGENT --> A(["Answer"])
| Command | What it does | Paid |
|---|---|---|
make data |
Downloads Berkeley Lab's queue spreadsheet, which the code calls the workbook, and checks it is the exact copy this project expects | No |
make panel |
Builds the panel from the spreadsheet's PJM projects | No |
make fetch |
Downloads PJM's study reports for up to 25 projects | No |
make embed |
Splits the reports into passages and embeds them | Yes |
make extract |
Reads each report's costs into the panel | Yes |
make app, or python -m src.cli ask or chat |
Answers your questions | Yes |
The paid steps only call OpenAI when DRY_RUN is false (see Cost). The design decisions explain the main choices.
These figures come from runs on 30 November 2026 at the default settings.
The panel. It holds 7,666 PJM projects from Berkeley Lab's Queued Up: 2026 Edition, which covers queues to the end of 2025. Of these, 5,226 have withdrawn, 1,192 are operating, 1,134 are active and 114 are suspended. By fuel, 3,661 are solar, 1,096 gas, 943 storage, 730 wind, 516 solar with storage, 138 coal, 89 hydro, 77 nuclear, 53 oil, 24 diesel and 339 other. "Other" covers projects Berkeley Lab itself lists as other, and hybrids (projects that combine technologies at one site) other than solar with storage.
Queue age is the number of days a project spent in the queue: from the day it applied to the day it withdrew or began operating, or, if it is still in the queue, to 31 December 2025, the date Berkeley Lab's statuses describe. It is blank for 146 projects with a missing date, or an end date before the day they applied (why).
The study reports. PJM groups applications into queue windows, with names such as AC2, AF1 and AG1. Each project has a queue ID, such as AG1-462, that starts with its window's name. make fetch only looks for reports for projects in the AG1 window or an earlier one. I tried 21 projects from the later AG2, AH1 and AH2 windows, and none has a report at either address make fetch uses. By default it works back from the active or withdrawn projects that applied most recently, skips any without a report, and stops once it has 25 (why). Berkeley Lab dates 22 of these 25 applications 30 September 2020, and the other three 1 October. In Berkeley Lab's data, 12 of the 25 are 5 MW or smaller. 195 other active or withdrawn projects also applied on 30 September. make fetch leaves them out because it takes projects that applied on the same day in order of queue ID. The 25 reports are 12 feasibility studies, PJM's first, rough estimate of what a connection needs; 7 system impact studies, the more detailed study that follows; and 6 that combine the two.
Costs. The panel has no extracted costs yet, because embedding the reports and extracting their costs are paid steps I haven't run (see Limitations). To show the calculation, here is one report read by hand. AC2-093 was a 675 MW solar project in North Carolina, now withdrawn. Its system impact study, from May 2018, estimates $280,825,093 of costs. Of that, $2,300,000 is for attachment facilities, the equipment where the plant meets the grid, and the other $278,525,093 is for network upgrades. Divided by its 675 MW, that is about $413 of network upgrades per kW.
You need Linux on a 64-bit Intel, AMD or Arm processor, with glibc, its standard system library, at version 2.28 or later (ldd --version shows yours), or a Mac with Apple silicon and macOS 14 or later (other systems), with Python 3.11 to 3.14 and make. For the paid steps, you also need an OpenAI API key: the password that lets the code use OpenAI's models and bills your OpenAI account.
make install # creates .venv and installs the pinned packages
source .venv/bin/activate
cp .env.example .env # then set OPENAI_API_KEY in .env
make check # shows what is set up so far, with no API call
DRY_RUN is true in .env.example, so nothing calls OpenAI until you set it to false, either in .env or for one command, as below. make help lists every step.
make data
make panel
make fetch
make embed DRY_RUN=false # an estimated $0.04 for the 25 default reports
make extract DRY_RUN=false
Then ask questions, in the browser or the terminal:
make app DRY_RUN=false
DRY_RUN=false python -m src.cli ask "How many withdrawn solar projects are in the panel, and what is their combined capacity in MW?"
DRY_RUN=false python -m src.cli chat
make app opens a chat page at http://127.0.0.1:8000. It listens only on your computer, and each browser tab keeps its own conversation. Press Ctrl+C in the terminal to stop it. It stops once any answer in progress has finished.
Adding a report. To add other projects' reports, download them with python -m src.fetch_pdfs --ids, giving each queue ID exactly as in the panel. Then run make embed again, and make extract to read their costs. Both skip reports they have already done. For example, for AF1-236:
python -m src.fetch_pdfs --ids AF1-236
make embed DRY_RUN=false
make extract DRY_RUN=false
You can also save a report yourself, as data/raw/pdfs/<queue ID>.pdf, with the queue ID written exactly as in the panel.
PJM's live queue. To build the panel from PJM's live queue instead of Berkeley Lab's data, put a free PJM Data Miner API key in PJM_API_KEY in .env, then run python -m src.ingest_queue --source gridstatus. I haven't tested this route.
Nothing calls OpenAI until you set DRY_RUN to false. In a dry run, make embed says how much it would send and estimates its cost. make extract does the same, but only for reports already embedded. Embedding is a paid step, so until it has run, make extract says there is nothing to extract. In a dry run, the agent gives a fixed reply. OpenAI charges by the token, a chunk of text a few characters long. The prices this project uses are in src/config.py.
- Embedding the 25 default reports is estimated at $0.0396: 1,980,104 tokens at $0.02 per million. The dry run, which reads all 25 PDFs, took about 20 minutes on my laptop.
- Extraction and questions. I haven't measured these yet. Extraction sends the model up to seven passages per report, never a whole PDF.
- Limits.
make embedandmake extracthandle at most 25 reports per run (MAX_PDFS) and skip any they have already done. The agent stops after 10 steps, at most five calls to the model, on any one question.
make test runs the offline tests. They use small sample files in data/fixtures/, and stand-ins for the model and the network, so they need no key, no network and no downloads. GitHub runs them on Python 3.11 and 3.14 for every pull request.
make eval DRY_RUN=false puts six questions to the real agent. It prints each answer, the result of each check, and the tokens and cost. The checks test, for example, that the agent used the right tool, stated the right count, and didn't present one line of a report as a project's total. Four checks compare answers with the extracted costs. Until there are costs to compare with, the evaluation skips these checks and says so, rather than passing them. One of them is about AF1-236, whose report isn't in the default sample, so it stays skipped until you add that report and extract its costs (see the Quickstart). The wind question's check follows the panel too: until a wind project's extracted cost is above $300 per kW, it expects the answer to say there is none. I haven't run the evaluation yet, because it needs the paid steps first.
python -m src.extract --validate sets each extracted cost per kW beside the one in Berkeley Lab's PJM cost data, which its researchers read by hand from PJM's studies. It calls no model. The file covers 13 of the 25 default projects, and AF1-236. For each of these with an extracted cost, it prints the two costs, the difference, the megawatts each was divided by, and the study Berkeley Lab read. The first time it has a cost to compare, it downloads Berkeley Lab's file and checks that it's the expected copy. Until the paid extraction runs, it has nothing to compare, and says so. The two costs are defined differently (see Limitations), so they can differ even when both are read correctly. For AF1-236, the cost I read from its report by hand comes to $391.35 per kW, and Berkeley Lab's to $418.46. Most of that gap is Berkeley Lab's conversion to 2022 dollars (more).
- Study costs are preliminary estimates, not final bills. They are the grid operator's estimates at the time of the study, and a later study can change them.
- PJM only. The panel holds PJM's projects, and the reports are PJM's.
make fetchonly looks for reports of projects in the AG1 window or an earlier one, and the default sample is narrow. See What the data holds now.- The paid steps haven't run yet. Embedding the reports, extracting their costs, asking the agent questions and the evaluation all call OpenAI's paid models, and I haven't run any of them. The agent and the extraction use
gpt-6-luna(why). Only a connection test of two short requests, with the same model settings, has reached it. So I haven't confirmed that OpenAI accepts the agent's tool calls or the extraction's reply format, the fixed set of fields it asks the model to fill in, or that the costs the code reports match OpenAI's bill. Nor have I measured how accurately the model extracts costs, how well the agent answers, or what either costs. The offline tests use a stand-in for OpenAI, so they check what the code sends, not what OpenAI does with it. - The model can misread a report. It can miss or misread a figure, and its output can vary between runs, so check any cost that matters against its report.
- My cost per kW is defined differently from Berkeley Lab's. Berkeley Lab counts every cost except attachment facilities as network cost, divides by the plant's nameplate capacity (its rated maximum output) and converts to 2022 dollars. I use the report's own network upgrade total, or if it gives none, its total minus the cost of the physical connection. Either can leave out connection work that Berkeley Lab counts. I divide by the megawatts the study assessed, or by the panel's capacity if it gives none, and don't adjust for inflation. Each of the 25 default reports gives two sizes on its title page: the plant's full output, and the part of that output PJM counts as capacity (PJM's own term, not the nameplate capacity above), which is smaller in 22 of them. AC2-093's report gives 675 MW and 429.4 MW, so its cost per kW is $413 or $649, depending on which one is used. I haven't yet tested which one the model copies (future work).
--validateshows both costs for each project Berkeley Lab covers, once its cost is extracted. - Withdrawal risk is reasoning, not prediction. The agent weighs a project's costs against four research findings, each with its source (what it is told), and describes the risk. It is told never to say a project will certainly withdraw. It isn't a statistical model trained on past withdrawals.
src/
config.py every setting, path, model name and price
fetch_queue.py downloads Berkeley Lab's queue spreadsheet and its PJM cost data
ingest_queue.py builds the panel, and runs the agent's SQL safely
fetch_pdfs.py downloads PJM's study reports
ingest_pdfs.py splits the reports into passages and embeds them
extract.py reads the costs out of the reports into the panel
tools.py the agent's two tools
agent.py the agent and its instructions
cli.py the terminal commands: setup-check, ask and chat
app.py the chat page's web server
static/ the chat page's HTML, CSS and JavaScript
tests/ the offline tests and the evaluation
docs/ design decisions and future work
data/fixtures/ small sample files for the tests
Downloads and built data go in data/raw/, data/processed/ and data/vectors/, which stay on your computer and out of Git.
Python 3.11 to 3.14, LangChain and LangGraph for the agent, and OpenAI's models: gpt-6-luna, with its reasoning (the hidden working-out it can do before it answers) switched off, for answers and extraction, and text-embedding-3-small for embeddings. DuckDB holds the panel, Chroma holds the passages and PyMuPDF reads the PDFs. Starlette and Uvicorn serve the chat page. requirements.txt pins every package to an exact version, and make lock rebuilds it from requirements.in, the list of packages the project uses directly (why).
| Data | What I use it for | Licence and terms |
|---|---|---|
| Berkeley Lab, Queued Up: 2026 Edition (data file) | The panel, and the national figures on completion and withdrawal | CC BY 4.0, credited to Lawrence Berkeley National Laboratory and GridTracker, as Berkeley Lab's copyright notice for the file asks. make data downloads it, and Git ignores it. |
| Berkeley Lab, PJM interconnection cost data (data file), by Seel and others, with Exeter Associates (January 2023) | The costs --validate compares with: network costs read by hand from PJM's studies of 1,127 projects |
It states no open licence. Its copyright notice only reserves a licence for the US government to publish or reproduce it. --validate downloads it for your own use, and Git ignores it. |
| PJM study reports, such as AC2-093's | The passages the agent reads, and the costs | © PJM Interconnection, all rights reserved. make fetch downloads them for your own use, and Git ignores them. |
| PJM's live queue, through gridstatus (optional) | An alternative to Berkeley Lab's data | PJM's terms apply (see its legal page). The data stays on your computer. |
Research and other sources:
- Gorman and others (2025), "Grid connection barriers to renewable energy deployment in the United States", Joule 9(2), doi:10.1016/j.joule.2024.11.008.
- Berkeley Lab (2023), "Interconnection Cost Analysis in the PJM Territory", summary and brief: the costs of PJM projects by status, how it defines each cost, and the time it took to read costs by hand.
- FERC Order No. 2023, Federal Register, 6 September 2023, official text: how a withdrawal affects the projects behind it (paragraphs 47 and 49), and how shifted costs can lead to further withdrawals (paragraphs 793, 798 and 799).
- PJM's home page: it serves 13 states and the District of Columbia.
- OpenAI's pricing, deprecations and prompt caching pages: the model prices and cache rates in
src/config.py, and the models OpenAI is retiring.
The code is under the MIT licence. Each dataset keeps its publisher's licence and terms, listed above.