a2a-demo / app.py
evalstate's picture
evalstate HF Staff
Force install mounted wheel on startup
b049214 verified
Raw
History Blame Contribute Delete
1.48 kB
from __future__ import annotations
import glob
import os
import subprocess
import sys
from pathlib import Path
BUCKET_MOUNT = Path(os.environ.get("FAST_AGENT_BUCKET_MOUNT", "/data"))
CARD_DIR = BUCKET_MOUNT / "agent-cards"
def latest_wheel() -> str:
wheels = sorted(
glob.glob(str(BUCKET_MOUNT / "wheels" / "fast_agent_mcp-*.whl")),
key=os.path.getmtime,
reverse=True,
)
if not wheels:
raise RuntimeError(f"No fast-agent-mcp wheel found under {BUCKET_MOUNT / 'wheels'}")
return wheels[0]
def main() -> None:
wheel = latest_wheel()
subprocess.check_call(
[sys.executable, "-m", "pip", "install", "--no-deps", "--force-reinstall", wheel]
)
os.environ.setdefault("FAST_AGENT_SERVE_OAUTH", "huggingface")
os.environ.setdefault("FAST_AGENT_OAUTH_SCOPES", "access")
os.environ.setdefault("PYTHONUNBUFFERED", "1")
cmd = [
sys.executable,
"-m",
"fast_agent.cli.__main__",
"serve",
"a2a",
"--name",
os.environ.get("FAST_AGENT_A2A_NAME", "a2a-demo"),
"--host",
"0.0.0.0",
"--port",
os.environ.get("PORT", "7860"),
"--instance-scope",
os.environ.get("FAST_AGENT_A2A_INSTANCE_SCOPE", "connection"),
"--agent-cards",
str(CARD_DIR),
"--model",
os.environ.get("FAST_AGENT_MODEL", "kimi"),
]
os.execv(sys.executable, cmd)
if __name__ == "__main__":
main()