hosting_metadata
One-shot hosting provider and geographic location for the system prompt.
Probed asynchronously at bot startup and merged into
PromptRenderer default_extras.
- async hosting_metadata.probe_hosting_metadata()[source]
Detect cloud provider / region and geographic location (best effort).
Opens one shared
aiohttp.ClientSessionand races the four cloud metadata probes (_aws_probe(),_oci_probe(),_gcp_probe(),_azure_probe()) concurrently viaasyncio.gather(), picking the first provider that responds in gather order (AWS, then OCI, GCP, Azure). It then layers on an IP-based geolocation –_fetch_public_ipv4()feeding_geolocate_ipapi()– and reconciles the two location sources with_merge_location(). All network failures are absorbed by the individual probes, so this function itself never raises and degrades to the placeholder strings"Unknown"/"Location unavailable".Performs only outbound HTTP (link-local IMDS endpoints plus the public ipify/ipapi.co services); no Redis, KG, or filesystem access. Called by
ensure_hosting_metadata_in_prompt(), and exercised directly bytests/test_hosting_metadata.py.
- async hosting_metadata.ensure_hosting_metadata_in_prompt(renderer)[source]
Run
probe_hosting_metadata()once per process; update renderer extras.Probes the host’s cloud provider and location a single time and folds the resulting
hosting_provider/server_locationvalues into the renderer’s Jinjadefault_extrasso the system prompt can surface where the bot is running. Guarded by the module-level_HOSTING_PROBE_LOCKand the_HOSTING_APPLIEDflag, making it idempotent and concurrency-safe across overlapping service-startup calls; if the probe raises it is caught and placeholder extras are applied instead, so the flag is always set and the work runs at most once.Mutates
renderer.default_extrasin place (the only side effect besides the one-shot HTTP performed insideprobe_hosting_metadata()). Intended to be awaited from a service entry point during startup; currently invoked directly only bytests/test_hosting_metadata.py(no in-repo production caller imports this module yet).- Parameters:
renderer (
Any) – The prompt renderer whosedefault_extrasdict receives thehosting_providerandserver_locationkeys; typed loosely asAnyto avoid importingprompt_renderer.PromptRenderer.- Return type:
- hosting_metadata.reset_hosting_metadata_probe_for_tests()[source]
Reset the process-level idempotency flag so the probe can rerun (tests only).
Clears
_HOSTING_APPLIEDtoFalseso a subsequentensure_hosting_metadata_in_prompt()will probe again instead of short-circuiting on the one-shot guard. Pure in-process state mutation with no I/O. Called only fromtests/test_hosting_metadata.py(fixture setup) to give each test a clean starting state; not used in production.- Return type: