faostat-skills 0.1.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -5,20 +5,33 @@
5
5
  [![Claude Code](https://img.shields.io/badge/Claude_Code-plugin-blueviolet)](https://claude.com/claude-code)
6
6
  [![Codex](https://img.shields.io/badge/Codex-compatible-green)](https://openai.com)
7
7
 
8
- AI-powered analysis skills for the [UN FAOSTAT](https://www.fao.org/faostat/en/#data) database the world's most comprehensive source of food and agriculture statistics. These platform-agnostic skills guide your AI assistant through multi-step analytical workflows: country food security profiles, trade dependency analysis, commodity deep dives, agrifood climate assessments, and data-driven storytelling.
8
+ AI-powered analysis skills for the [UN FAOSTAT](https://www.fao.org/faostat/en/#data) database, the world's most comprehensive source of food and agriculture statistics. These platform-agnostic skills guide your AI assistant through multi-step analytical workflows: country food security profiles, trade dependency analysis, commodity deep dives, agrifood climate assessments, and data-driven storytelling.
9
9
 
10
10
  **Works with:** Claude Code, OpenAI Codex, and any AI assistant that supports the `SKILL.md` format.
11
11
 
12
12
  ### Quick Start
13
13
 
14
+ **Claude Code**
14
15
  ```bash
15
- # Claude Code
16
- claude plugin install faostat-skills
16
+ # 1. Add this repo as a marketplace (one-time)
17
+ /plugin marketplace add berba-q/faostat-skills
17
18
 
18
- # Then ask:
19
- # "Give me a food security profile for Kenya"
20
- # "Compare wheat yields in France, USA, and India"
21
- # "How dependent is Egypt on wheat imports?"
19
+ # 2. Install
20
+ claude plugin install faostat-skills@faostat
21
+ ```
22
+
23
+ **OpenAI Codex**
24
+ ```bash
25
+ git clone https://github.com/berba-q/faostat-skills.git ~/.agents/skills/faostat-skills
26
+ ```
27
+
28
+ **Other AI assistants** — copy the `skills/` directory to wherever your tool discovers skill files. Consult your provider's documentation for the correct skills directory path.
29
+
30
+ Once installed, try asking:
31
+ ```
32
+ "Give me a food security profile for Kenya"
33
+ "Compare wheat yields in France, USA, and India"
34
+ "How dependent is Egypt on wheat imports?"
22
35
  ```
23
36
 
24
37
  ## Prerequisites
@@ -36,14 +49,19 @@ Then configure your credentials (one-time setup) by asking your AI assistant:
36
49
 
37
50
  ### Claude Code
38
51
 
52
+ Claude Code uses a marketplace model. Add this repo as a marketplace source once, then install:
53
+
39
54
  ```bash
40
- claude plugin install faostat-skills
41
- ```
55
+ # Step 1 — add marketplace (one-time setup)
56
+ /plugin marketplace add berba-q/faostat-skills
42
57
 
43
- Or install directly from GitHub:
58
+ # Step 2 — install the plugin
59
+ claude plugin install faostat-skills@faostat
60
+ ```
44
61
 
62
+ To update to a new version later:
45
63
  ```bash
46
- claude plugin install berba-q/faostat-skills
64
+ claude plugin update faostat-skills@faostat
47
65
  ```
48
66
 
49
67
  ### OpenAI Codex
@@ -71,23 +89,28 @@ Copy the `skills/` directory to wherever your AI tool discovers skill files. Eac
71
89
  | Skill | Command | Description |
72
90
  |-------|---------|-------------|
73
91
  | **Country Food Security Profile** | `/faostat-country-profile` | Comprehensive food security assessment — production, trade, nutrition, and risk indicators for any country |
74
- | **Comparative Agricultural Analysis** | `/faostat-compare` | Side-by-side comparison of agricultural metrics across countries, commodities, or regions |
92
+ | **Comparative Agricultural Analysis** | `/faostat-compare` | Side-by-side comparison of agricultural metrics for two or more specific named entities |
75
93
  | **Commodity Deep Dive** | `/faostat-commodity` | Complete global briefing for any commodity — production rankings, yield trends, trade flows |
94
+ | **Trade Dependency Analyzer** | `/faostat-trade` | Import dependence assessment with self-sufficiency ratios and supply chain risk indicators |
95
+ | **Agrifood Climate Analyzer** | `/faostat-climate` | Climate-agriculture nexus analysis — emissions profiles, temperature trends, land use, inputs-emissions links |
96
+ | **Agricultural Trend Monitor** | `/faostat-trends` | Identify biggest changes and anomalies in agricultural data over a time window |
76
97
 
77
- ### Tier 2: Specialized
98
+ ### Tier 2: Outputs
78
99
 
79
100
  | Skill | Command | Description |
80
101
  |-------|---------|-------------|
81
- | **Agrifood Climate Analyzer** | `/faostat-climate` | Climate-agriculture nexus analysis emissions profiles, temperature trends, land use, inputs-emissions links |
82
- | **Trade Dependency Analyzer** | `/faostat-trade` | Import dependence assessment with self-sufficiency ratios and supply chain risk indicators |
83
- | **Data Visualizer** | `/faostat-viz` | Generate interactive Chart.js HTML charts from FAOSTAT data |
102
+ | **Choropleth Map** | `/faostat-map` | Interactive world map of any FAOSTAT country-level metric |
103
+ | **Data Visualizer** | `/faostat-viz` | Interactive Chart.js HTML charts use when the chart itself is the deliverable |
104
+ | **Infographic** | `/faostat-infographic` | Shareable single-page visual summary for social, press, or pitch decks |
105
+ | **Data Storyteller** | `/faostat-story` | Data-driven narrative article with embedded charts for research |
106
+ | **Analytical Brief** | `/faostat-analytical-brief` | Multi-page policymaker-facing brief in FAOSTAT house style (PDF + xlsx appendix) |
107
+ | **Scientific Paper** | `/faostat-scientific-paper` | Peer-reviewable IMRaD research paper (docx + xlsx + bib) |
84
108
 
85
- ### Tier 3: Creative
109
+ ### Tier 3: Utilities
86
110
 
87
111
  | Skill | Command | Description |
88
112
  |-------|---------|-------------|
89
- | **Agricultural Trend Monitor** | `/faostat-trends` | Identify biggest changes and anomalies in agricultural data over a time window |
90
- | **Data Storyteller** | `/faostat-story` | Build data-driven narratives with embedded charts for journalism and research |
113
+ | **Data Export** | `/faostat-export-dataset` | Clean tabular data bundle (xlsx + csv + data dictionary) when data itself is the deliverable |
91
114
  | **FAOSTAT Explorer** | `/faostat-explore` | Guided discovery of FAOSTAT's data catalog with sample data and explanations |
92
115
 
93
116
  ## Examples
@@ -0,0 +1,6 @@
1
+ ---
2
+ description: Produce a FAOSTAT-style multi-page analytical brief (PDF + xlsx appendix)
3
+ argument-hint: <topic>
4
+ ---
5
+
6
+ Invoke the `faostat-analytical-brief` skill to produce a policymaker-facing analytical brief in the FAOSTAT house visual style. If no topic is provided in the argument, ask the user what the brief should cover.
@@ -0,0 +1,6 @@
1
+ ---
2
+ description: Export clean, documented FAOSTAT data as xlsx + csv + data dictionary
3
+ argument-hint: <indicator or domain>
4
+ ---
5
+
6
+ Invoke the `faostat-export-dataset` skill to deliver a clean tabular data bundle. If no indicator is provided in the argument, ask the user what data they would like to export.
@@ -0,0 +1,6 @@
1
+ ---
2
+ description: Create a shareable single-page infographic from FAOSTAT data
3
+ argument-hint: <topic or metric>
4
+ ---
5
+
6
+ Invoke the `faostat-infographic` skill to build a modern, non-expert-facing single-page infographic. If no topic is provided in the argument, ask the user what they would like to visualise.
@@ -0,0 +1,6 @@
1
+ ---
2
+ description: Generate a choropleth world map of a FAOSTAT metric by country
3
+ argument-hint: <metric> [for <commodity>] [year <year>]
4
+ ---
5
+
6
+ Invoke the `faostat-map` skill to render an interactive choropleth map of the specified FAOSTAT metric. If no metric is provided in the argument, ask the user what they would like to map.
@@ -0,0 +1,6 @@
1
+ ---
2
+ description: Generate a peer-reviewable academic paper from FAOSTAT data (docx + xlsx + bib)
3
+ argument-hint: <research question or topic>
4
+ ---
5
+
6
+ Invoke the `faostat-scientific-paper` skill to write an IMRaD-structured research paper from FAOSTAT data. If no research question is provided in the argument, ask the user what they would like to investigate.
@@ -0,0 +1,17 @@
1
+ {
2
+ "name": "faostat",
3
+ "owner": {
4
+ "name": "Griffiths Obli-Laryea"
5
+ },
6
+ "plugins": [
7
+ {
8
+ "name": "faostat-skills",
9
+ "source": {
10
+ "source": "npm",
11
+ "package": "faostat-skills",
12
+ "version": "^0.2.0"
13
+ },
14
+ "description": "AI skills for analyzing UN FAOSTAT food & agriculture data — country profiles, trade analysis, climate assessments, commodity briefings, maps, infographics, and more."
15
+ }
16
+ ]
17
+ }
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "faostat-skills",
3
- "version": "0.1.0",
3
+ "version": "0.2.1",
4
4
  "description": "Analysis skills for UN FAOSTAT food and agriculture data. Country profiles, commodity briefings, trade analysis, climate assessments, and data visualizations.",
5
5
  "author": "Griffiths Obli-Laryea",
6
6
  "license": "MIT",
7
7
  "repository": {
8
8
  "type": "git",
9
- "url": "https://github.com/berba-q/faostat-skills.git"
9
+ "url": "git+https://github.com/berba-q/faostat-skills.git"
10
10
  },
11
11
  "homepage": "https://github.com/berba-q/faostat-skills",
12
12
  "keywords": [
@@ -28,6 +28,7 @@
28
28
  "skills/",
29
29
  "commands/",
30
30
  ".claude-plugin/",
31
+ "marketplace.json",
31
32
  "README.md",
32
33
  "LICENSE"
33
34
  ]
@@ -0,0 +1,216 @@
1
+ ---
2
+ name: faostat-analytical-brief
3
+ description: Use when the user wants a short, FAOSTAT-style analytical brief — a multi-page PDF policy document in the FAOSTAT house visual style, with a HIGHLIGHTS box, global/regional/country sections, numbered figures with source lines, explanatory notes, and a data appendix. Use when the user asks for "an analytical brief on X", "a FAOSTAT-style brief", "a policy brief", "a FAO-style write-up", or a short policymaker-facing report. Keywords: analytical brief, policy brief, FAOSTAT brief, FAO-style, brief, briefing (policy), policymakers, short report (policy). Do NOT use for journalistic long-reads (use `faostat-story`), academic papers (forthcoming `faostat-scientific-paper`), or single-page visual summaries (forthcoming `faostat-infographic`).
4
+ ---
5
+
6
+ # FAOSTAT Analytical Brief
7
+
8
+ Produce a multi-page PDF analytical brief in the FAOSTAT house visual style, with the corresponding multi-sheet xlsx data appendix so every figure and discussion point is reproducible.
9
+
10
+ **Scope of the visual grammar (no FAO branding).** The brief uses the FAOSTAT visual grammar — teal/dark-blue palette, serif titles, → arrow bullets, teal section banners, numbered figures with `Source: FAOSTAT …` lines, and the familiar section order (HIGHLIGHTS / BACKGROUND / GLOBAL / REGIONAL / COUNTRY / EXPLANATORY NOTES / NEXT RELEASE / REFERENCES). It does **not** reproduce the FAO logo, "Food and Agriculture Organization of the United Nations" masthead, ISSN strip, "FAO Statistics Division" stamp, "Required citation: FAO. …" line, or any other FAO branding. The output must be clearly attributable as a user-generated analysis, not an FAO publication.
11
+
12
+ ## Prerequisites
13
+
14
+ Confirm the FAOSTAT MCP tools are available: `faostat_get_data`, `faostat_search_codes`, `faostat_list_domains`, `faostat_get_metadata`. If they are not, tell the user and stop.
15
+
16
+ Python packages (install on demand via `pip install <pkg> --break-system-packages`):
17
+ - `plotly`, `pandas`, `kaleido` (figure rendering + PNG export, reused from `faostat-map`)
18
+ - `reportlab` (PDF assembly via Platypus)
19
+ - `openpyxl` (xlsx data appendix)
20
+
21
+ The forthcoming figure renders compose on top of `faostat-viz` (line/bar/stacked-bar) and `faostat-map` (choropleths). When a brief needs a map, invoke the map skill's rendering guidance rather than reimplementing.
22
+
23
+ ## Cross-skill invariants (do not violate)
24
+
25
+ All 6 invariants from the FAOSTAT skill suite apply unchanged:
26
+
27
+ 1. **FILTER vs DISPLAY element codes.** `faostat_get_data` takes FILTER codes (e.g., `'2510'`); never pass DISPLAY codes (`'5510'`).
28
+ 2. **Year syntax.** Comma-separated lists only (`'2010,2011,...,2024'`); colon ranges return empty.
29
+ 3. **Element filter required** on every `faostat_get_data` call.
30
+ 4. **TCL for national trade aggregates, TM only for partner breakdowns.** Never sum TM rows to reconstruct national totals.
31
+ 5. **China composite default (user preference, Apr 2026).** Default to composite `China` (area 351) for country rankings, top-N lists and country-level analysis. Offer `China, mainland` (41) as an opt-in — do not substitute 41 unless the user asks for 41 explicitly. Flag the choice in the Methodology sheet, and include the caveat whenever a China number is quoted: FAOSTAT's own publications default to 41, so a brief using 351 will show a marginally larger "China" value than the FAO data-portal default. (Map figures inside the brief are an exception: they use the disaggregation path — area 41 on the CHN polygon with HKG / MAC / TWN rendered separately — because choropleths cannot sensibly render 351. See the map skill.)
32
+ 6. **`faostat_get_rankings` HTTP-500 fallback.** Reconstruct rankings from `faostat_get_data` + client-side sort; document fallback in the Methodology sheet.
33
+
34
+ ## Workflow
35
+
36
+ ### Step 1 — Gather parameters
37
+
38
+ Confirm or elicit from the user:
39
+ - **Topic/domain** — map to a FAOSTAT domain (QCL, TCL, GT, ET, PP, FBS, FS, RFN, RL, etc.).
40
+ - **Scope** — global (default, matching most reference briefs), regional, or a named country subset.
41
+ - **Time window** — a year range. Reference briefs use 15–25-year windows; default to the most recent 15 years if the user gives nothing.
42
+ - **Thematic breakdown** — optional. Production briefs split by commodity group; emissions briefs split by component (farm-gate / land-use / pre-and-post); trade briefs split by dimension (volume / value / concentration); climate briefs split by temporal slice. Pick a breakdown from the domain or ask the user.
43
+ - **Cover image** — optional user-supplied path. Default to a generic abstract teal gradient placeholder.
44
+ - **Brief number** — optional; omit by default (no number in cover kicker).
45
+ - **HTML sibling** — off by default; on request only.
46
+
47
+ ### Step 2 — Plan the brief
48
+
49
+ Produce an internal outline before any data pulls:
50
+ - 5–8 HIGHLIGHTS bullets, each with a projected hard number placeholder.
51
+ - 4–7 numbered figures. Pattern:
52
+ - Figure 1 — GLOBAL time series of the headline metric.
53
+ - Figure 2 — REGIONAL breakdown (stacked bar or small multiples across 6 FAO regions).
54
+ - Figure 3 — THEMATIC breakdown (by commodity / component / dimension per the domain).
55
+ - Figure 4 — COUNTRY / TOP-10 bar chart.
56
+ - Figure 5 (optional) — Choropleth map. Use `faostat-map`.
57
+ - Figures 6–7 (optional) — additional regional or indicator figures.
58
+ - 1–2 tables where a cross-region / cross-indicator comparison is cleaner than a chart.
59
+
60
+ ### Step 3 — Pull all data
61
+
62
+ For each figure and table, plan a specific `faostat_get_data` call. Log every call for the Methodology sheet. Always:
63
+ - Pass FILTER element codes.
64
+ - Use comma-separated year lists.
65
+ - Use `response_format='compact'`.
66
+ - Pass `show_unit=True`.
67
+ - For trade aggregates, use **TCL** elements (2610 import quantity, 2910 export quantity, 2612 import value, 2912 export value) — not TM sums.
68
+ - For region figures, pull the 6 continental area codes (Africa 5100, Americas 5200, Asia 5300, Europe 5400, Oceania 5500, World 5000) directly — don't compute them client-side.
69
+ - For top-N country figures, **don't** rely on `faostat_get_rankings`; pull `faostat_get_data` for the domain and element (no area filter) and sort client-side, so an HTTP-500 from `get_rankings` doesn't block the brief.
70
+ - For China in country rankings and country-level analysis, keep composite `China` (area 351) and drop 41 (mainland), unless the user opted into 41 explicitly. (Map figures inside the brief use the disaggregation path — area 41 + HKG 96 + MAC 128 + TWN 214 — because a choropleth cannot render 351 sensibly.)
71
+
72
+ Pull the dataset metadata with `faostat_get_metadata(domain_code=<D>)` so EXPLANATORY NOTES can be auto-generated from the same source the FAOSTAT team uses.
73
+
74
+ ### Step 4 — Compute derived metrics
75
+
76
+ In pandas, compute and store:
77
+ - Period totals and averages.
78
+ - Year-over-year absolute and percentage changes.
79
+ - CAGR over the full window.
80
+ - Shares (country share of regional total, region share of world total).
81
+ - Rankings (top-10 by absolute value, by change, by intensity).
82
+
83
+ Keep the raw rows and the derived columns side-by-side for the xlsx appendix.
84
+
85
+ ### Step 5 — Render figures as PNG
86
+
87
+ Use Plotly Express or Graph Objects with kaleido for static PNG export. Target:
88
+ - 2000×1200 px at `scale=2` for line/bar/stacked-bar charts.
89
+ - 2400×1400 px at `scale=2` for choropleth maps (via `faostat-map`).
90
+ - Colour palette: FAOSTAT house colours — teal `#1F5E7B`, dark blue `#1A3A5F`, warm grey `#7F7F7F`, accent ochre `#D89B2E`, accent green `#4F8A3B`.
91
+ - Sans-serif font for axis labels (Lato / Open Sans if available, else default sans).
92
+ - Source line embedded in the figure body: `Source: FAO. YYYY. FAOSTAT: [Dataset name]. [Accessed MMM YYYY]. https://www.fao.org/faostat/en/#data/[DOMAIN]. Licence: CC-BY-4.0.`
93
+
94
+ Save PNGs under `<outputs>/figures/fig<N>_<slug>.png`.
95
+
96
+ ### Step 6 — Assemble the PDF
97
+
98
+ Use **ReportLab Platypus**. Build a `BaseDocTemplate` with two page templates:
99
+
100
+ **Cover page template** — no FAO branding. Elements, top to bottom:
101
+ - Hero image (user-supplied or generic teal gradient). ~55% of page height.
102
+ - Kicker `FAOSTAT ANALYTICAL BRIEF` in small caps, teal, sans-serif (serial number omitted unless user supplied).
103
+ - Title in dark-blue serif (26pt), centred.
104
+ - Subtitle (year range + scope) in grey serif (14pt), centred.
105
+ - Teal footer band with bar-chart motif (drawn as canvas primitives — small rectangles of varying heights).
106
+ - **No FAO logo. No "Food and Agriculture Organization of the United Nations" masthead. No ISSN. No "FAO Statistics Division" stamp.**
107
+
108
+ **Inside page template** — teal header band with:
109
+ - Brief title + subtitle + (optional brief number) in white sans-serif.
110
+ - Page content area with 2.5cm left/right margins.
111
+ - Footer: page number only. No institutional branding.
112
+
113
+ **Body flow**:
114
+ 1. HIGHLIGHTS box on page 2:
115
+ - "HIGHLIGHTS" caps heading in teal.
116
+ - 5–8 bullets each prefixed with `→`, each carrying a hard number. Use `<b>` tags for the number. Render via Platypus `Paragraph` with custom bullet style.
117
+ 2. `FAOSTAT [DOMAIN NAME]` teal all-caps banner.
118
+ 3. `BACKGROUND` — 2–3 paragraphs of framing and policy context.
119
+ 4. `GLOBAL` — narrative + Figure 1.
120
+ 5. `REGIONAL` — narrative + Figure 2 (optionally Table 1 with regional indicators).
121
+ 6. Thematic subsections (commodity / component / dimension) — each with its own figure.
122
+ 7. `COUNTRY` — top-N narrative + Figure 4 (horizontal bar).
123
+ 8. Optional map figure via `faostat-map`.
124
+ 9. `EXPLANATORY NOTES` — auto-generated from `faostat_get_metadata` covering the dataset scope, update cycle, coverage caveats, aggregation rules.
125
+ 10. `NEXT RELEASE` — single sentence with the next expected release window per FAOSTAT's update cadence.
126
+ 11. `REFERENCES` — DOI-linked bibliography.
127
+
128
+ **Figure rendering in Platypus**:
129
+ ```python
130
+ story.append(Paragraph(f"<b>Figure {n}:</b> {caption}", fig_caption_style))
131
+ story.append(Image(png_path, width=16*cm, height=9*cm))
132
+ story.append(Paragraph(source_line, fig_source_style))
133
+ ```
134
+
135
+ **Typography**:
136
+ - Titles: serif, dark blue (`#1A3A5F`).
137
+ - Section banners: sans-serif, teal (`#1F5E7B`), all-caps.
138
+ - Body paragraphs: serif (Cambria / Georgia fallback), 10.5pt.
139
+ - HIGHLIGHTS bullets: sans-serif (Lato / Open Sans / default), 10pt, `→` bullet marker.
140
+ - Figure caption: sans-serif bold, 9.5pt.
141
+ - Figure source: sans-serif italic, 8pt, grey.
142
+
143
+ **Subscripts**. Never use Unicode subscripts (`CO₂`). Use Platypus XML markup: `CO<sub>2</sub>`.
144
+
145
+ ### Step 7 — Build the xlsx data appendix (required)
146
+
147
+ Use `openpyxl` to write a workbook at `<outputs>/<brief-slug>-data.xlsx` with the following sheets. Every figure and every numeric claim in HIGHLIGHTS must trace back to a sheet row.
148
+
149
+ **Required sheets**:
150
+
151
+ 1. `README` — brief title, pull date, scope, list of FAOSTAT domains/elements/years used, sheet index (sheet name + contents summary).
152
+ 2. `Highlights_data` — one row per HIGHLIGHTS bullet, columns: `bullet_text`, `value`, `unit`, `source_sheet`, `source_row`. This is the audit trail so any reviewer can check every headline number.
153
+ 3. `Fig<N>_<slug>` — one sheet per figure. Columns should match what was plotted (long form with `area`, `year`, `element`, `item`, `value`, `unit` as appropriate). Include any derived columns (CAGR, Δ, share) next to the raw ones.
154
+ 4. `Tab<N>_<slug>` — one sheet per in-brief table, same rows as rendered.
155
+ 5. `Methodology` — one row per `faostat_get_data` call, columns: `call_id`, `domain`, `element_filter_code`, `item_codes`, `area_codes`, `year_list`, `response_format`, `timestamp_utc`, `notes` (e.g., "China composite 351 used for country-level figures; area 41 dropped"; "map figure disaggregated China: 41 + HKG 96 + MAC 128 + TWN 214"; "get_rankings fallback via client-side sort on get_data").
156
+ 6. `Sources` — bibliography. Columns: `id`, `citation`, `url`, `licence`.
157
+
158
+ **Formatting conventions**:
159
+ - Header row bold, teal fill (`#1F5E7B`, white text).
160
+ - Numeric columns right-aligned; text left-aligned.
161
+ - Freeze the first row.
162
+ - Auto-fit column widths (or set to a sensible default and wrap long text).
163
+ - Number format for percentages (`0.0%`), integers with thousands separator (`#,##0`), decimals where native.
164
+
165
+ Link the xlsx from the brief footer: `Data appendix: <brief-slug>-data.xlsx`.
166
+
167
+ ### Step 8 — Write the back matter (no FAO impersonation)
168
+
169
+ Replace every FAO-branded element with neutral author-and-source attribution:
170
+
171
+ - **Authorship line**: `Prepared by [user name / organisation] using FAOSTAT data.`
172
+ - **FAO legal disclaimer**: OMIT. Instead include a short note: "This analysis is based on FAOSTAT data, released under the CC-BY-4.0 licence. Any interpretation, emphasis, or conclusion is the author's and does not represent an FAO position."
173
+ - **Required citation**: `Suggested citation: [author], [year]. [Brief title]. Analytical brief based on FAOSTAT data, accessed [MMM YYYY].` — **no "Required citation: FAO. …" line.**
174
+ - **Cover photo credit**: `Cover image: [source]` — if using a stock or generic image, say so. Never use `© FAO` or `FAO/<photographer>`.
175
+ - **No ISSN. No FAO contact footer. No FAO-catalogue code.**
176
+ - Data-licence footer: `Underlying data © FAO, used under CC-BY-4.0. https://creativecommons.org/licenses/by/4.0/`.
177
+
178
+ ### Step 9 — Save and describe
179
+
180
+ Save outputs to the session workspace:
181
+ - `<outputs>/<brief-slug>.pdf` (primary)
182
+ - `<outputs>/<brief-slug>-data.xlsx` (required appendix)
183
+ - `<outputs>/figures/fig<N>_<slug>.png` (individual PNG figures)
184
+ - `<outputs>/<brief-slug>.html` (optional HTML sibling, if requested)
185
+
186
+ Describe to the user:
187
+ - The headline numbers (repeating the HIGHLIGHTS bullets).
188
+ - Any sparse-data or coverage notes surfaced during the pulls.
189
+ - Any invariant that mattered (e.g., "TCL used for trade aggregates; TM sums would have double-counted re-exports", "China composite 351 used for country rankings; 41 available as opt-in").
190
+ - Direct links to the PDF and the xlsx.
191
+
192
+ ### Step 10 — Offer refinements
193
+
194
+ Ask:
195
+ - "Want a different year window or scope?"
196
+ - "Should I add a country-level map?" (invokes `faostat-map`).
197
+ - "Any highlights you'd like emphasised or deprioritised?"
198
+ - "Replace the cover image?" (user can supply a file path).
199
+ - "Generate the HTML sibling?"
200
+
201
+ ## Error handling
202
+
203
+ - **Empty data pull.** First check FILTER vs DISPLAY (invariant 1), then year syntax (invariant 2), then element exists in the domain.
204
+ - **Sparse region years.** If a region has <80% year-coverage in the window, note it in the REGIONAL narrative and in the Methodology sheet rather than silently interpolating.
205
+ - **`faostat_get_rankings` HTTP 500.** Use the `faostat_get_data` fallback (invariant 6). Log the fallback on the Methodology sheet.
206
+ - **Kaleido install fails.** The skill cannot produce the PDF without PNG renders. Install `kaleido` on demand and retry; if install still fails, fall back to the HTML sibling and tell the user the PDF path requires kaleido.
207
+ - **ReportLab font missing.** If the preferred serif (Cambria / Georgia) or sans-serif (Lato / Open Sans) isn't available in the sandbox, fall back to ReportLab's built-in `Times-Roman` / `Helvetica` without failing. Note the font fallback in the Methodology sheet.
208
+ - **User asked for content implying FAO authorship.** If the user asks to put FAO logos, "Food and Agriculture Organization" masthead, or "Required citation: FAO. …" in the brief, push back: the skill produces FAOSTAT-style analyses for user authorship, not FAO-branded documents. Offer to proceed without the FAO branding.
209
+
210
+ ## Limitations (v1)
211
+
212
+ - Cover-image generation is a placeholder gradient unless the user supplies a path.
213
+ - Typography is limited to ReportLab's built-in fonts and whatever TrueType fonts are available in the sandbox.
214
+ - HTML sibling is v2 — v1 ships PDF + xlsx only unless explicitly requested.
215
+ - Subnational analysis is out of scope (FAOSTAT is country-level).
216
+ - Automatic cross-domain briefs (e.g., production + trade in one brief) are v2; v1 covers one headline domain per brief with optional supporting pulls from 1–2 related domains.
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: faostat-climate
3
- description: Use when the user asks about agricultural emissions, climate impact of farming, agrifood carbon footprint, greenhouse gases from agriculture, deforestation, forest carbon sinks, temperature change, fertilizer emissions, N2O, land use change, emissions intensity, or the climate-agriculture nexus. Keywords: emissions, climate, carbon, greenhouse gas, GHG, deforestation, forest, temperature, warming, N2O, fertilizer emissions, land use, agrifood, emissions intensity, carbon sink
3
+ description: Use when the user asks about agricultural emissions, climate impact of farming, agrifood carbon footprint, greenhouse gases from agriculture, deforestation, forest carbon sinks, temperature change, fertilizer emissions, N2O, land use change, emissions intensity, or the climate-agriculture nexus. Keywords: emissions, climate, carbon, greenhouse gas, GHG, deforestation, forest, temperature, warming, N2O, fertilizer emissions, land use, agrifood, emissions intensity, carbon sink. Do NOT use for a full country food security profile → `faostat-country-profile`. Do NOT use for trend ranking across commodities or countries → `faostat-trends`.
4
4
  ---
5
5
 
6
6
  # Agrifood Climate Analyzer
@@ -26,6 +26,25 @@ Before starting, verify that the FAOSTAT MCP tools are available: `faostat_searc
26
26
  | Pesticides Use | **RP** | Pesticide application data |
27
27
  | Pesticides Trade | **RT** | Pesticide import/export data |
28
28
 
29
+ ## Element Filter Reference
30
+
31
+ Every `faostat_get_data` call below specifies an `element` filter. Without one, emissions domains return dozens of sub-elements per year and the payload explodes. If an element code is unfamiliar, resolve via `faostat_search_codes(domain_code='<dom>', dimension_id='element', query='...')`.
32
+
33
+ | Metric | Domain | Filter code |
34
+ |--------|--------|-------------|
35
+ | Emissions (CO2eq) | GT | `724313` |
36
+ | Share in total emissions (%) | EM | `7231` |
37
+ | Emissions per capita (kg CO2eq/person) | EM | `723112` |
38
+ | Temperature change (°C) | ET | `7271` |
39
+ | Net forest conversion (area, ha) | GF | `6646` |
40
+ | Forest land emissions (CO2eq) | GF | `724313` |
41
+ | Agricultural land (area, ha) | RL | `5110` |
42
+ | Forest land (area, ha) | RL | `5110` (item 6646 Forest land) |
43
+ | N fertilizer use (tonnes) | RFN | `5157` |
44
+ | Pesticide use (tonnes) | RP | `5157` |
45
+
46
+ Year-range syntax: use explicit comma-separated lists (`year='2014,2015,...,2023'`). Colon ranges (`'2014:2023'`) have returned empty in practice.
47
+
29
48
  ## Sub-workflow Detection
30
49
 
31
50
  Read the user's question and select the most appropriate sub-workflow:
@@ -43,15 +62,40 @@ If the question does not clearly match one sub-workflow, present the five option
43
62
  1. Ask for the country if not already specified.
44
63
  2. Resolve the country name to an area code using `faostat_search_codes(domain_code='GT', dimension_id='area', query='<country>')`.
45
64
  - If `requires_confirmation` is true in the response, present the matching options and ask the user to choose. Do NOT proceed until the user confirms.
46
- 3. Pull agrifood systems emissions totals from the **GT** domain:
47
- `faostat_get_data(domain_code='GT', area='<area_code>', response_format='compact')`
48
- Focus on the most recent 10 years. Identify total agrifood emissions and breakdown by source category (farm gate, land use, pre/post production).
65
+ - **China rule.** Default to composite `China` (area code 351) — the roll-up of mainland + HK SAR + Macao SAR + Taiwan — not `China, mainland` (41), unless the user specifies 41 explicitly. Note in the output that FAOSTAT's own publications default to 41, so this profile's China total is marginally larger than the FAO data-portal default.
66
+ 3. Pull agrifood systems emissions totals from the **GT** domain (with element and year filters so the payload is manageable):
67
+ ```
68
+ faostat_get_data(
69
+ domain_code='GT',
70
+ area='<area_code>',
71
+ element='724313', # Emissions (CO2eq) in CO2 equivalents
72
+ year='2014,2015,2016,2017,2018,2019,2020,2021,2022,2023',
73
+ response_format='compact'
74
+ )
75
+ ```
76
+ Identify total agrifood emissions trend and the breakdown by source category (farm gate, land use, pre/post production — these come through as different `item` codes within GT).
49
77
  4. Pull emissions indicators from the **EM** domain:
50
- `faostat_get_data(domain_code='EM', area='<area_code>', response_format='compact')`
51
- Extract per capita emissions, share of national total, emissions per value of agricultural production.
78
+ ```
79
+ faostat_get_data(
80
+ domain_code='EM',
81
+ area='<area_code>',
82
+ element='7231,723112', # Share in total (%), per capita (kg CO2eq)
83
+ year='2019,2020,2021,2022,2023',
84
+ response_format='compact'
85
+ )
86
+ ```
87
+ Extract per capita emissions and share of national total.
52
88
  5. Pull temperature change data from the **ET** domain:
53
- `faostat_get_data(domain_code='ET', area='<area_code>', response_format='compact')`
54
- Identify the warming trend over the available period.
89
+ ```
90
+ faostat_get_data(
91
+ domain_code='ET',
92
+ area='<area_code>',
93
+ element='7271', # Temperature change (°C)
94
+ year='2014,2015,2016,2017,2018,2019,2020,2021,2022,2023',
95
+ response_format='compact'
96
+ )
97
+ ```
98
+ Identify the warming trend over the available period. ET data is monthly — filter to annual items if needed or aggregate to annual averages.
55
99
  6. Synthesize into a structured profile:
56
100
  - **Agrifood Emissions Overview** -- total emissions, trend (rising/falling/stable), breakdown by source
57
101
  - **Normalized Metrics** -- per capita, share of national emissions, per dollar of agricultural output
@@ -64,10 +108,27 @@ If the question does not clearly match one sub-workflow, present the five option
64
108
  1. Ask for the countries or region to compare (minimum 2, maximum 10). Accept country names, region names, or a mix.
65
109
  2. Resolve each entity to area codes using `faostat_search_codes(domain_code='GT', dimension_id='area', query='<name>')`.
66
110
  - Handle `requires_confirmation` for each entity separately. Do NOT proceed until all codes are confirmed.
67
- 3. Pull emissions totals from the **GT** domain for all entities:
68
- `faostat_get_data(domain_code='GT', area='<code1>,<code2>,...', response_format='compact')`
111
+ - Default `China` composite `China` (351), not `China, mainland` (41).
112
+ 3. Pull emissions totals from the **GT** domain for all entities — always with element and year filters:
113
+ ```
114
+ faostat_get_data(
115
+ domain_code='GT',
116
+ area='<code1>,<code2>,...',
117
+ element='724313',
118
+ year='2014,2015,...,2023',
119
+ response_format='compact'
120
+ )
121
+ ```
69
122
  4. Pull emissions indicators from the **EM** domain for all entities:
70
- `faostat_get_data(domain_code='EM', area='<code1>,<code2>,...', response_format='compact')`
123
+ ```
124
+ faostat_get_data(
125
+ domain_code='EM',
126
+ area='<code1>,<code2>,...',
127
+ element='7231,723112',
128
+ year='2019,2020,2021,2022,2023',
129
+ response_format='compact'
130
+ )
131
+ ```
71
132
  Extract per capita and share metrics for normalization.
72
133
  5. Present comparison:
73
134
  - **Absolute emissions** -- rank by total agrifood emissions (latest year)
@@ -149,4 +210,21 @@ If the question does not clearly match one sub-workflow, present the five option
149
210
  - When `requires_confirmation` is true in a search result, always present options to the user and wait for their choice.
150
211
  - Use `response_format='compact'` when querying multiple entities or large time ranges.
151
212
  - For rankings, use DISPLAY element codes (e.g., '5510' for production). For data filtering, use FILTER codes (e.g., '2510' for production).
213
+ - **Always pass an `element` filter to `faostat_get_data`.** Emissions domains return dozens of sub-elements per year and the payload explodes without one.
214
+ - **Always pass an explicit comma-separated `year` list.** Colon ranges like `'2014:2023'` have returned empty in practice.
152
215
  - Always include the source attribution line at the end of any output.
216
+
217
+ ## Error Handling and Reliability Notes
218
+
219
+ - **`faostat_get_rankings` sometimes returns HTTP 500.** If you need rankings (e.g., "top 10 emitters" before the comparison in Sub-workflow B), fall back to `faostat_get_data` across all reporting countries and sort client-side. Document the fallback in the output.
220
+ - **China aggregate rule (user preference, Apr 2026).** Default to composite `China` (351) — the roll-up of mainland + HK SAR + Macao SAR + Taiwan. Do NOT substitute `China, mainland` (41) unless the user specifies 41 explicitly. State the choice in the output and note that FAOSTAT's own publications default to 41, so the numbers here are marginally larger than the FAO data-portal default.
221
+ - **Empty return with colon year range.** Retry with a comma-list.
222
+ - **ET domain is monthly.** Filter to a single month (e.g., Annual `item='6078'`) or compute an annual mean client-side.
223
+
224
+ ## Related Skills
225
+
226
+ | If you need… | Use |
227
+ |---|---|
228
+ | Full country food security profile | `/faostat-country-profile` |
229
+ | Commodity production context | `/faostat-commodity` |
230
+ | Trend ranking across countries | `/faostat-trends` |