feat(energy): analyst context — JODI oil/gas + IEA oil stocks per-country data#2741
feat(energy): analyst context — JODI oil/gas + IEA oil stocks per-country data#2741
Conversation
…ocks per-country data
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Greptile SummaryThis PR wires three new per-country energy data sources (JODI oil, JODI gas, IEA oil stocks) into Confidence Score: 4/5Hold for one fix: data is fetched and reported as active but silently dropped before the LLM sees it. A P1 defect exists on the primary feature path — all three new fields are populated and tracked in activeSources, but chat-analyst-prompt.ts has no code to emit them into the prompt. The Redis calls incur real cost and activeSources misleads callers into thinking the analyst has this context when it does not. chat-analyst-prompt.ts needs DOMAIN_SECTIONS entries and emit blocks for productSupply, gasFlows, and oilStocksCover before merging. Important Files Changed
Sequence DiagramsequenceDiagram
participant C as Caller
participant AC as assembleAnalystContext
participant R as Redis
participant PB as buildAnalystSystemPrompt
participant LLM as LLM
C->>AC: assembleAnalystContext(iso2, domain)
par Concurrent fetches
AC->>R: energy:jodi-oil:v1:{iso2}
R-->>AC: productSupply data
AC->>R: energy:jodi-gas:v1:{iso2}
R-->>AC: gasFlows data
AC->>R: energy:iea-oil-stocks:v1:{iso2}
R-->>AC: oilStocksCover data
end
AC-->>C: AnalystContext (productSupply/gasFlows/oilStocksCover set, activeSources includes JODIOil/JODIGas/IEAStocks)
C->>PB: buildAnalystSystemPrompt(ctx)
Note over PB: ⚠ productSupply / gasFlows / oilStocksCover
Note over PB: never read — not in DOMAIN_SECTIONS
Note over PB: and no emit blocks added
PB-->>C: system prompt (missing JODI/IEA sections)
C->>LLM: prompt (LLM never sees energy data)
Reviews (1): Last reviewed commit: "feat(energy): extend analyst context wit..." | Re-trigger Greptile |
| productSupply?: string; | ||
| gasFlows?: string; | ||
| oilStocksCover?: string; |
There was a problem hiding this comment.
New fields fetched but never injected into the analyst prompt
productSupply, gasFlows, and oilStocksCover are populated in AnalystContext and tracked in activeSources (surfacing as "JODIOil", "JODIGas", "IEAStocks"), but chat-analyst-prompt.ts never reads or emits them. DOMAIN_SECTIONS for geo and economic — and the catch-all null path — all omit these three fields, so the LLM analyst receives no JODI/IEA data despite the Redis lookups. The feature is a no-op end-to-end until the prompt builder is wired up.
Add emit blocks and register the fields in DOMAIN_SECTIONS in chat-analyst-prompt.ts:
// After the refineryUtil block:
if (ctx.productSupply && include('productSupply'))
contextSections.push(`## Oil Product Supply\n${ctx.productSupply}`);
if (ctx.gasFlows && include('gasFlows'))
contextSections.push(`## Gas Flows\n${ctx.gasFlows}`);
if (ctx.oilStocksCover && include('oilStocksCover'))
contextSections.push(`## IEA Oil Stocks\n${ctx.oilStocksCover}`);And add 'productSupply', 'gasFlows' to DOMAIN_SECTIONS['geo'] and DOMAIN_SECTIONS['economic'], and 'oilStocksCover' to DOMAIN_SECTIONS['economic'].
| const lngShare = typeof d.lngShareOfImports === 'number' ? Math.round((d.lngShareOfImports as number) * 100) : null; | ||
| const split = lngShare != null ? ` (LNG ${lngShare}%, pipeline ${100 - lngShare}%)` : ''; |
There was a problem hiding this comment.
lngShareOfImports scale assumption not yet verified
lngShareOfImports is multiplied by 100, assuming it is a fraction (0–1). If PR #2736 seeds it as a percentage (0–100), the output would be LNG 5000%, pipeline -4900%. Since the JODI-gas seed script hasn't merged yet, the contract should be confirmed before this code goes live.
| const data = await getCachedJson(`energy:jodi-oil:v1:${iso2}`, true); | ||
| if (!data || typeof data !== 'object') return undefined; |
There was a problem hiding this comment.
Cache key strings should be exported constants in
cache-keys.ts
The three new key templates (energy:jodi-oil:v1:, energy:jodi-gas:v1:, energy:iea-oil-stocks:v1:) are inline string literals. Existing per-country prefixes like GAS_STORAGE_KEY_PREFIX live in cache-keys.ts; keeping the new ones there too makes global search-and-rename safe and keeps the key registry complete.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Summary
productSupply,gasFlows,oilStocksCoveroptional fields toAnalystContextenergy:jodi-oil:v1:{ISO2}), JODI gas (energy:jodi-gas:v1:{ISO2}), and IEA oil stocks (energy:iea-oil-stocks:v1:{ISO2}) data when a country ISO2 is in contextproductSupply+gasFlowsactive foreconomic,geo,alldomains;oilStocksCoverforeconomic,allPromise.allSettled, fail-safe — missing Redis data returnsundefinedsilentlyNote
Depends on merged PRs: #2732 (JODI oil), #2733 (IEA stocks), #2735 (chokepoint baselines). PR #2736 (JODI gas) pending —
gasFlowswill be a no-op until that merges.