""" FastAPI app for the BA Agent RL Environment (OpenEnv). Endpoints (provided by OpenEnv create_app): - POST /reset, POST /step, GET /state, GET /schema, WS /ws Custom: - GET /web — minimal demo UI (mirrors clinKriya base_path). - GET /api/tasks — list available tasks (task_id, title, n_docs, n_golden). - GET /api/tasks/{task_id} — fetch a task body. """ from __future__ import annotations import json from pathlib import Path from typing import Optional from fastapi.responses import HTMLResponse, JSONResponse from starlette.middleware.base import BaseHTTPMiddleware from starlette.requests import Request try: from openenv.core.env_server.http_server import create_app except Exception as exc: # pragma: no cover raise ImportError( "openenv-core required. Install with `uv pip install -e .` first." ) from exc from ba_agent_env.models import BAAgentAction, BAAgentObservation from .ba_agent_environment import BAAgentEnvironment from .dataset import get_tasks _ui_env: Optional[BAAgentEnvironment] = None def _get_ui_env() -> BAAgentEnvironment: global _ui_env if _ui_env is None: _ui_env = BAAgentEnvironment() return _ui_env _ROOT = Path(__file__).resolve().parents[1] _UI_HTML_PATH = _ROOT / "ui" / "index.html" def _ui_html() -> str: if _UI_HTML_PATH.exists(): return _UI_HTML_PATH.read_text(encoding="utf-8") tasks = get_tasks() rows = "".join( f"
Enterprise requirements-generation RL environment. Agents run a 5-stage BA pipeline
(EXTRACT -> INTERVIEW -> GRAPH -> STORY_GEN -> PRD -> FINISH) over one feature
and are scored against BA-authored golden user stories.
Endpoints: POST /reset, POST /step, GET /state, GET /schema, GET /api/tasks.
| task_id | title | docs | golden stories |
|---|
Alignment 35% · Coherence 24% · Completeness 18% · Compliance 10% · Testability 9% · Spec Quality 4%.
LLM judge (OpenRouter / GPT-4o) when OPENROUTER_API_KEY is set; heuristic fallback otherwise.