agi-env API
agi_env provides the shared headless environment and path-resolution layer
used by both AGILab and the core runtime packages. Streamlit/page dependencies
live in the separate agi-gui package under src/agilab/lib/agi-gui.
Usage Example
Instanciation
import asyncio
from pathlib import Path
from agi_cluster.agi_distributor import AGI
from agi_env import AgiEnv
APP = "minimal_app_project"
def agilab_apps_path() -> Path:
marker = Path.home() / ".local/share/agilab/.agilab-path"
if not marker.is_file():
raise SystemExit(
"AGILAB is not initialized. Run the AGILAB installer or "
"`agilab first-proof --json` before this example."
)
return Path(marker.read_text(encoding="utf-8").strip()) / "apps" / "builtin"
async def main():
app_env = AgiEnv(apps_path=agilab_apps_path(), app=APP, verbose=1)
res = await AGI.get_distrib(app_env)
print(res)
return res
if __name__ == "__main__":
asyncio.run(main())
Note
AgiEnv behaves as a singleton. Repeated instantiation updates the same
environment instance. Call AgiEnv.reset() before configuring a new
environment, or AgiEnv.current() to retrieve the active one.
Reference
AGILab environment bootstrapper and utility helpers.
The module exposes the AgiEnv class which orchestrates project discovery,
virtual-environment management, packaging helpers, and convenience utilities used
by installers as well as runtime workers. Supporting free functions provide small
parsing and path utilities leveraged during setup.
Notes on singleton and pre‑init behavior
AgiEnvbehaves as a true singleton. Instance attributes are the source of truth; class attribute reads proxy to the singleton instance when initialised. Methods and descriptors are never shadowed by the delegation.A small subset of helpers is pre‑init safe and can be used before constructing an instance:
AgiEnv.set_env_var(),AgiEnv.read_agilab_path(),AgiEnv._build_env, andAgiEnv.log_info(). These functions avoid hard failures when the shared logger/environment has not been configured yet. Logging in that mode is best‑effort and may fall back toprint.