Add fertilizer to input-cost tools (regional $/ton, USDA AgTransport)
input_cost_trend/input_cost_series now accept six fertilizers (urea, uan, anhydrous, dap, map, potash) alongside diesel, with an optional `geo` region (default Cornbelt). Real $/ton + MoM/YoY change + seasonal context. - client: pass geo through; add input_cost_geographies - server: expand VALID_INPUTS; geo param + docstrings - format already unit-aware ($/ton) and geo-aware - README tools table now lists the reference/trend + input-cost tools - CHANGELOG: regional fertilizer input-cost release notes - tests: fertilizer $/ton + region formatting Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
+33
-12
@@ -303,40 +303,61 @@ def price_series(
|
||||
return fmt.fmt_price_series(payload)
|
||||
|
||||
|
||||
VALID_INPUTS = {"diesel"}
|
||||
# Fuel is national (US); fertilizer is regional ($/ton, USDA AgTransport).
|
||||
VALID_INPUTS = {"diesel", "urea", "uan", "anhydrous", "dap", "map", "potash"}
|
||||
_FERT_INPUTS = {"urea", "uan", "anhydrous", "dap", "map", "potash"}
|
||||
|
||||
|
||||
@mcp.tool()
|
||||
def input_cost_trend(
|
||||
item: Annotated[
|
||||
str, Field(description="Input to price. Currently: 'diesel' (U.S. retail $/gal).")
|
||||
str,
|
||||
Field(description="Input to price: 'diesel' (U.S. retail $/gal) or a fertilizer "
|
||||
"($/ton) — 'urea', 'uan', 'anhydrous', 'dap', 'map', 'potash'."),
|
||||
],
|
||||
geo: Annotated[
|
||||
str | None,
|
||||
Field(description="Fertilizer region (default 'Cornbelt'). Other regions: "
|
||||
"'U.S. Gulf NOLA', 'Northern Plains', 'Southern Plains', "
|
||||
"'Southeast', 'Northeast', 'California', 'Pacific Northwest', "
|
||||
"'South Central', 'Central Florida', 'Tampa'. Ignored for diesel (US)."),
|
||||
] = None,
|
||||
years: Annotated[
|
||||
int, Field(ge=1, le=120, description="Baseline window for the seasonal normal/percentile."),
|
||||
] = 10,
|
||||
) -> str:
|
||||
"""Real input cost with the change — e.g. U.S. retail diesel ($/gal).
|
||||
"""Real input cost with the change — retail diesel ($/gal) or fertilizer ($/ton).
|
||||
|
||||
Latest real price + week-over-week and year-over-year moves + seasonal
|
||||
percentile/range. Fills the input-cost side for the advisor (fuel). For
|
||||
current fertilizer $/ton use current_input_price."""
|
||||
Latest real price + period-over-period and year-over-year moves + seasonal
|
||||
percentile/range. Diesel is U.S. weekly (back to 1994); fertilizer is monthly
|
||||
regional (USDA AgTransport, Cornbelt default, back to 2023). This is the
|
||||
input-cost side for the advisor. For a one-off current fertilizer quote from a
|
||||
local dealer feed, current_input_price (DTN) still applies."""
|
||||
it = item.strip().lower()
|
||||
with track("input_cost_trend", item=it, years=years):
|
||||
g = geo.strip() if geo else None
|
||||
with track("input_cost_trend", item=it, geo=g or "", years=years):
|
||||
if it not in VALID_INPUTS:
|
||||
return f"`item` must be one of: {sorted(VALID_INPUTS)}"
|
||||
return fmt.fmt_price_trend(client.input_cost_trend(item=it, years=years))
|
||||
return fmt.fmt_price_trend(client.input_cost_trend(item=it, years=years, geo=g))
|
||||
|
||||
|
||||
@mcp.tool()
|
||||
def input_cost_series(
|
||||
item: Annotated[str, Field(description="Input: 'diesel'.")],
|
||||
item: Annotated[
|
||||
str, Field(description="Input: 'diesel' or a fertilizer ('urea', 'uan', "
|
||||
"'anhydrous', 'dap', 'map', 'potash').")],
|
||||
geo: Annotated[
|
||||
str | None,
|
||||
Field(description="Fertilizer region (default 'Cornbelt'). Ignored for diesel."),
|
||||
] = None,
|
||||
) -> str:
|
||||
"""Raw historical series for a tracked input cost (diesel, $/gal)."""
|
||||
"""Raw historical series for a tracked input cost (diesel $/gal or fertilizer $/ton)."""
|
||||
it = item.strip().lower()
|
||||
with track("input_cost_series", item=it):
|
||||
g = geo.strip() if geo else None
|
||||
with track("input_cost_series", item=it, geo=g or ""):
|
||||
if it not in VALID_INPUTS:
|
||||
return f"`item` must be one of: {sorted(VALID_INPUTS)}"
|
||||
return fmt.fmt_price_series(client.input_cost_series(item=it))
|
||||
return fmt.fmt_price_series(client.input_cost_series(item=it, geo=g))
|
||||
|
||||
|
||||
@mcp.tool()
|
||||
|
||||
Reference in New Issue
Block a user