Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ These figures come from runs on 30 November 2026 at the default settings.

**The study reports.** PJM groups applications into queue windows, with names such as AC2, AF1 and AG1. `make fetch` only looks for reports for projects that applied before 1 October 2020, when the AG2 window opened. I tried 21 projects from the AG2, AH1 and AH2 windows, and none has a report at either address `make fetch` uses. By default it takes the 25 active or withdrawn projects that applied most recently before that date. All 25 applied on 30 September 2020. So did 192 other active or withdrawn projects, which it leaves out because it takes the first 25 by queue ID. Of the 25, 14 are 5 MW or smaller. Their reports are 13 feasibility studies, PJM's first, rough estimate of what a connection needs; 6 system impact studies, the more detailed study that follows; and 6 that combine the two.

**Costs.** The panel has no extracted costs yet. They need the reports embedded and then read by the extraction model, which has been shut down (see [Limitations](#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.
**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](#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.

## Quickstart

Expand All @@ -72,7 +72,7 @@ make data
make panel
make fetch
make embed DRY_RUN=false # an estimated $0.03 for the 25 default reports
# make extract DRY_RUN=false # skip for now: its model has been shut down (see Limitations)
make extract DRY_RUN=false
```

Then ask questions, in the browser or the terminal:
Expand All @@ -99,24 +99,24 @@ make embed DRY_RUN=false
Nothing calls OpenAI until you set `DRY_RUN` to false. In a dry run, `make embed` and `make extract` say how much they would send and estimate its cost, and 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.0272: 1,357,677 tokens at $0.02 per million. The dry run, which reads all 25 PDFs, took 11 minutes on my laptop.
- **Extraction and questions.** I'll measure these after the move to current models. Extraction sends the model up to seven passages per report, never a whole PDF.
- **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 embed` and `make extract` handle 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.

## Tests and evaluation

`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. Some checks compare answers with the extracted costs. With no extracted costs, two of them are skipped, and two others pass whatever the answer says, because there is nothing to compare with. One question is about AF1-236, whose report isn't in the default sample; the Quickstart shows how to add it. The evaluation needs extracted costs, so I'll run it after the move to current models.
`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. Some checks compare answers with the extracted costs. With no extracted costs, two of them are skipped, and two others pass whatever the answer says, because there is nothing to compare with. One question is about AF1-236, whose report isn't in the default sample; the Quickstart shows how to add it. I haven't run the evaluation yet, because it needs the paid steps first.

## Limitations

- **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 fetch` only looks for reports of projects that applied before October 2020, and the default sample is narrow.** See [What the data holds now](#what-the-data-holds-now).
- **Extraction can't run at the default settings.** OpenAI shut down `gpt-4.1-nano`, the extraction model, on 23 October 2026, and shuts down `gpt-4.1-mini`, the agent's model, on 14 January 2027 ([OpenAI](https://developers.openai.com/api/docs/deprecations)). Moving to current models is the next change ([future work](docs/future_work.md)).
- **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](docs/decisions.md#the-models-gpt-6-luna-with-reasoning-off)), and no request has gone to it yet. So I haven't confirmed that OpenAI accepts the settings the code sends, 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.
- **Two background findings in the agent's instructions don't match Berkeley Lab's PJM study.** One says cost is "the dominant driver" of withdrawal, where the study says high costs are "likely a key driver". The other says network upgrades are about 70% of recently withdrawn projects' costs, where the study's figure is 94%. Fixing them needs a fresh paid evaluation, so the fix comes with the model change.
- **Two background findings in the agent's instructions don't match Berkeley Lab's PJM study.** One says cost is "the dominant driver" of withdrawal, where the study says high costs are "likely a key driver". The other says network upgrades are about 70% of recently withdrawn projects' costs, where the study's figure is 94%.
- **Withdrawal risk is reasoning, not prediction.** The agent weighs a project's costs against research findings 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.
- **Queue age, the days since a project applied, counts to the day you build the panel,** even for projects that withdrew or started operating years ago.

Expand Down Expand Up @@ -144,7 +144,7 @@ Downloads and built data go in `data/raw/`, `data/processed/` and `data/vectors/

## Built with

Python 3.11 to 3.14, LangChain and LangGraph for the agent, and OpenAI's models: `gpt-4.1-mini` for answers, `gpt-4.1-nano` for 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 the exact versions.
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 the exact versions.

## Sources and credits

Expand All @@ -160,7 +160,7 @@ Research and other sources:
- Berkeley Lab (2023), "Interconnection Cost Analysis in the PJM Territory", [summary](https://emp.lbl.gov/publications/interconnection-cost-analysis-pjm) and [brief](https://eta-publications.lbl.gov/sites/default/files/berkeley_lab_2023.1.12-_pjm_interconnection_costs.pdf): the costs of withdrawn PJM projects, 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](https://www.govinfo.gov/content/pkg/FR-2023-09-06/html/2023-16628.htm): how a withdrawal affects the projects behind it (paragraph 47).
- [PJM's home page](https://www.pjm.com/): it serves 13 states and the District of Columbia.
- OpenAI's [pricing](https://developers.openai.com/api/docs/pricing) and [deprecations](https://developers.openai.com/api/docs/deprecations) pages: the model prices in `src/config.py` and the shutdown dates. The pricing page doesn't list `gpt-4.1-nano`, which has been shut down, so its price in `src/config.py` is an assumption, used only for the extraction's cost estimates.
- OpenAI's [pricing](https://developers.openai.com/api/docs/pricing), [deprecations](https://developers.openai.com/api/docs/deprecations) and [prompt caching](https://developers.openai.com/api/docs/guides/prompt-caching) pages: the model prices and cache rates in `src/config.py`, and the models OpenAI is retiring.

## Licence

Expand Down
36 changes: 35 additions & 1 deletion docs/decisions.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,46 @@ This file records the main choices behind the agent: what I decided, what I cons
- **SQL only.** The agent could give numbers but not explain them.
- **Whole reports in the model's input.** A report can run to hundreds of pages (AF1-236's system impact study has 206), so every question would cost far more.

**Evidence.** The evaluation checks this split. Its first question must use `query_queue` and not `search_studies`. Once costs have been extracted, two more checks fail an answer that presents one line of a report as the project's total. The evaluation needs extracted costs, so I'll run it after the move to current models (see the README's limitations).
**Evidence.** The evaluation checks this split. Its first question must use `query_queue` and not `search_studies`. Once costs have been extracted, two more checks fail an answer that presents one line of a report as the project's total. I haven't run the evaluation yet, because it needs the paid steps first (see the README's limitations).

**Trade-offs.**
- The panel's costs are only as good as the extraction, which reads passages too.
- Only the instructions and the evaluation stop the agent quoting a passage's figure as a total. The code doesn't.

## The models: gpt-6-luna with reasoning off

**Decision.** The agent and the cost extraction both use OpenAI's `gpt-6-luna`, and the study reports are embedded with `text-embedding-3-small`. Every request to `gpt-6-luna`:
- switches its reasoning off (`reasoning_effort` set to `none`);
- sets the temperature, which controls how much randomness the model adds when it picks its words, to 0;
- goes through Chat Completions, the older of OpenAI's two interfaces for sending a conversation to a model;
- asks for OpenAI's standard service tier (OpenAI sells several processing speeds, each at its own price), the one whose prices `src/config.py` lists. A request that names no tier gets whichever tier the OpenAI account's project settings choose, and other tiers have other prices.

The model names and prices live in `src/config.py`.

**Why.**
- **The jobs suit a small model.** In the extraction, the model copies figures from a few passages into a fixed set of fields. As the agent, it picks a tool, writes a database query or a search, and writes an answer that cites its evidence.
- **It replaces the retiring models, and it is the cheapest.** OpenAI shut down `gpt-4.1-nano`, the old extraction model, on 23 October 2026, and shuts down `gpt-4.1-mini`, the old agent model, on 14 January 2027. It lists `gpt-6-luna` as the replacement for `gpt-4.1` and `gpt-4.1-mini`. OpenAI charges by the token, a chunk of text a few characters long. At $0.10 per million input tokens and $0.50 per million output tokens, `gpt-6-luna` is the cheapest chat model on OpenAI's price list that isn't due to retire.
- **Reasoning off suits these jobs.** `gpt-6-luna` is a reasoning model: unless told otherwise, it works through hidden steps before it answers, and they are billed as output tokens. Copying figures and querying a table need little of that. OpenAI's deployment checklist advises keeping a model's current reasoning effort when moving work to GPT-6, which for a model that doesn't reason, such as `gpt-4.1-mini`, means none.
- **It is the only setting the agent can use on Chat Completions.** OpenAI's model page and GPT-6 guide say that with reasoning on, `gpt-6-luna` doesn't support tool calls there, which the agent needs, or any temperature setting.

**Alternatives.**
- **`gpt-5.6-luna`,** OpenAI's listed replacement for `gpt-4.1-nano`. It costs $0.20 and $1.20 per million, two to two and a half times as much, and is an older generation.
- **A larger model,** such as `gpt-6-sol` ($2 and $10 per million) or `gpt-6.1-terra` ($1 and $5). These cost 10 to 20 times as much, for jobs a small model should manage. OpenAI's GPT-6 guide says `gpt-6-sol` accepts the same settings, so it would need only its prices added to `src/config.py`. The newer `gpt-6.1-sol` and `gpt-6.2-sol` can't switch reasoning off, and `gpt-6.1-terra` can only call tools through the Responses API. I'd switch only if the evaluation shows the small model failing.
- **Reasoning on, at `low`.** OpenAI's [deployment checklist](https://developers.openai.com/api/docs/guides/deployment-checklist) suggests it for jobs that are mostly extraction. It adds output tokens, rules out temperature 0, and blocks the agent's tool calls on Chat Completions. I'd test it for the extraction if the extracted figures come out wrong.
- **The Responses API,** OpenAI's newer interface, which it recommends for new work and requires for reasoning with tools. It changes how requests and replies are sent, so it would need its own tests, and it brings nothing while reasoning is off.
- **`text-embedding-3-large`** for the embeddings, at 6.5 times the price ($0.13 per million). I'd consider it only if search keeps missing the passages that hold the costs.
- **Turning off prompt caching for the extraction.** OpenAI keeps the start of any prompt of 1,024 tokens or more in a short-term cache, and bills writing it at $0.125 per million tokens, a quarter more than plain input. Each extraction prompt is used once, so the writes only add cost. I left them on, because a prompt holds at most seven passages of up to 1,000 characters plus the instructions, so for 25 reports the writes cost less than a cent more than plain input would.

**Evidence.**
- I read OpenAI's [deprecations page](https://developers.openai.com/api/docs/deprecations), [pricing page](https://developers.openai.com/api/docs/pricing), [gpt-6-luna model page](https://platform.openai.com/docs/models/gpt-6-luna), [GPT-6 guide](https://developers.openai.com/api/docs/guides/latest-model/gpt-6-astra), [prompt caching guide](https://developers.openai.com/api/docs/guides/prompt-caching), [deployment checklist](https://developers.openai.com/api/docs/guides/deployment-checklist) and [Chat Completions reference](https://platform.openai.com/docs/api-reference/chat/create) on 28 November 2026, and the pricing page, GPT-6 guide and deployment checklist again on 30 November.
- Offline tests check that every request carries the settings above, and that the agent's requests include both tools.

**Uncertain.**
- **Whether OpenAI accepts the requests.** I haven't sent any request to `gpt-6-luna`. The settings above come from OpenAI's documentation, and the offline tests only check, against a stand-in for OpenAI, that the code sends them. I also haven't compared the costs the code reports, including its pricing of cached tokens, with a real OpenAI bill.
- **How well it works.** I haven't run the paid steps yet. I'll check the extraction by adding the reports of three projects outside the default sample (AC2-093, AF1-236 and AF2-353), and comparing the costs it extracts with the figures I read from them by hand. The evaluation questions (`make eval`) check whether the agent picks the right tool, writes a correct query and grounds its answer in the evidence.
- **Repeatability.** Temperature 0 makes answers less random, but not identical from run to run.
- **The cost estimates.** The estimate before an extraction run counts the tokens in the first project's prompt and assumes every prompt is that long. It adds the description of the reply's fields that goes with each request, and allows a fixed amount for each reply. The `tiktoken` library, which counts tokens offline, doesn't know `gpt-6-luna`, so the count uses `o200k_base`, the encoding `tiktoken` uses for `gpt-4o`, `gpt-4.1` and `gpt-5`. The estimate prices every prompt token at the cache-write rate, since each prompt is new. Paid runs report the tokens OpenAI measured, and price cached tokens at their own rates.

## A pinned copy of Berkeley Lab's data

**Decision.** The panel is built from one release of Berkeley Lab's queue spreadsheet: the Queued Up 2026 file, with queues to the end of 2025. `src/config.py` holds its address and its SHA-256 checksum, a fingerprint of the exact file. `make data` downloads it and checks the fingerprint. `make panel` refuses a spreadsheet that doesn't match. To build from another copy, name it with `python -m src.ingest_queue --file <path>`.
Expand Down
2 changes: 1 addition & 1 deletion docs/future_work.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Changes I plan or propose, starting with the most urgent.

## Next

- **Move to current OpenAI models.** OpenAI shut down `gpt-4.1-nano`, the extraction model, on 23 October 2026, and shuts down `gpt-4.1-mini`, the agent's model, on 14 January 2027. After the change, I'll check the extracted costs of three reports (AC2-093, AF1-236 and AF2-353) against the figures I read from them by hand, and run the evaluation.
- **Run the paid steps.** Embed the reports, extract their costs and run the evaluation. Then add the reports of AC2-093, AF1-236 and AF2-353, which aren't in the default sample, and check their extracted costs against the figures I read from them by hand. This needs OpenAI credits.
- **Correct the agent's instructions.** Two of its background findings don't match Berkeley Lab's PJM study (see the README's limitations), so I'll correct them and give each finding its source. I'll also remove the instruction to treat a quoted cost as an upper bound, which no cited source supports.
- **Make the evaluation skip checks it can't make.** With no extracted costs, two checks have nothing to compare with, so they pass whatever the answer says.

Expand Down
Loading