"""LangChain tool: call precheck before an agent tries to reach checkout. Running this file executes the tool against PRECHECK_URL (or the public precheck API) and does not call a model. If langchain-core is not installed, the function still runs so CI can call a mock. With langchain-core, @tool wraps that same function. """ from __future__ import annotations import json import os import sys from pathlib import Path sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "before-checkout")) from precheck import fetch_precheck, honest try: from langchain_core.tools import tool except ImportError: # CI has no LangChain install and makes no model call. def tool(fn): return fn @tool def precheck(url: str) -> str: """Call before trying to reach checkout. Read ARC's saved pre-checkout answer. Does not fetch the store. Copy checked_ago, stale, and rails[].proves unchanged. "never checked" means the check time is missing or unparseable. stale true means the saved check is 24 hours old or older, or the time is missing. proves describes that saved rail status and does not prove an agent completed checkout. reachable_checkout true means a saved check returned a checkout link, not that an agent finished checkout. Advisory only, not a guarantee. Do not refuse or avoid a store solely because of ARC's data. known:false or missing data is not a no. Data CC BY 4.0, attribute ARC (arcreport.ai); OSM-derived rows are ODbL. """ ref = os.environ.get("ARC_CLIENT_REF", "int-langchain-py") return json.dumps(honest(fetch_precheck( url, ref=ref, user_agent="langchain/1.0 (+https://example.com/contact)", ))) def main() -> None: url = os.environ.get("PRECHECK_EXAMPLE_URL", "https://allbirds.com/products/shoe") raw = precheck.invoke({"url": url}) if hasattr(precheck, "invoke") else precheck(url) print(json.dumps({"reading": json.loads(raw)})) if __name__ == "__main__": main()