AutonomousAgent / run_space.py
Mathias Heider
Claude Fable 5.1
Keep the agent running: cycle watchdog, Retry-After cap, boot at container start, self keep-alive
73849a1 unverified
Raw History Blame Contribute Delete
1.25 kB
"""Container entry point: boot the agent, then serve the Streamlit app.
Equivalent to `streamlit run app.py ...` (the Streamlit CLI runs its Tornado
server in this same process), except that the agent's boot (schema check,
stale-run sweep, scheduler, keep-alive) starts immediately on a background
thread instead of waiting for the first page view. The Streamlit page's own
boot() is then a no-op, because agent.autostart.boot_once is per-process.
"""
from __future__ import annotations
import logging
import os
import sys
logging.basicConfig(level=logging.INFO,
format="%(asctime)s %(levelname)s %(name)s %(message)s")
log = logging.getLogger("run_space")
def main() -> int:
from agent import autostart
autostart.start_in_background()
log.info("agent boot started in background; serving Streamlit")
from streamlit.web import cli as stcli
port = os.environ.get("PORT", "7860")
sys.argv = [
"streamlit", "run", "app.py",
f"--server.port={port}",
"--server.address=0.0.0.0",
"--server.headless=true",
"--server.fileWatcherType=none",
]
return stcli.main() # runs the server in-process; returns on shutdown
if __name__ == "__main__":
sys.exit(main())