diff --git a/README.md b/README.md index 1e978e7..1160500 100644 --- a/README.md +++ b/README.md @@ -31,4 +31,9 @@ curl -s -X POST http://localhost:8000/process_data \ ``` Returns `{ "emails": "..." }`. +### Stateless mode +- Sessions are ephemeral and in-memory only; no SQLite persistence. +- Each request creates a new session and it is deleted after completion. +- Web UI works, but conversation history resets on refresh/restart. + diff --git a/main.py b/main.py index e9a79e0..4ce793e 100644 --- a/main.py +++ b/main.py @@ -37,7 +37,8 @@ if os.getenv("GEMINI_API_KEY") and not os.getenv("GOOGLE_GENAI_API_KEY"): os.environ["GOOGLE_GENAI_API_KEY"] = os.getenv("GEMINI_API_KEY") AGENTS_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), "agents") -SESSION_SERVICE_URI = "sqlite:///./sessions.db" +# Stateless: use in-memory session service (no SQLite persistence) +SESSION_SERVICE_URI = None ALLOWED_ORIGINS = ["*"] SERVE_WEB_INTERFACE = True @@ -62,14 +63,25 @@ def process_data(data: dict = Body(...)): ) final_text = None - for event in _api_runner.run(user_id="api-user", session_id=session.id, new_message=content): - if getattr(event, "content", None): - for part in event.content.parts or []: - text = getattr(part, "text", None) - if text: - final_text = text - - return {"emails": final_text or ""} + try: + for event in _api_runner.run(user_id="api-user", session_id=session.id, new_message=content): + if getattr(event, "content", None): + for part in event.content.parts or []: + text = getattr(part, "text", None) + if text: + final_text = text + return {"emails": final_text or ""} + finally: + # Ephemeral: delete session after each request + try: + _api_runner.session_service.delete_session_sync( + app_name=_api_runner.app_name, + user_id="api-user", + session_id=session.id, + ) + except Exception: + # Best-effort cleanup + pass if __name__ == "__main__":