{
  "openapi": "3.1.0",
  "info": {
    "title": "SciencesLoop Agent API",
    "version": "0.1.0",
    "description": "Public-safe RAG / LLM API for the SciencesLoop website agent. Answers are grounded in public portfolio corpus only."
  },
  "servers": [
    {
      "url": "https://api.sciencesloop.com"
    }
  ],
  "paths": {
    "/api/agent": {
      "get": {
        "summary": "Health check",
        "responses": {
          "200": {
            "description": "Service status",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HealthResponse"
                }
              }
            }
          }
        }
      },
      "post": {
        "summary": "Ask the SciencesLoop public-site agent",
        "description": "Answers from public website corpus. The service does not read private repositories or store visitor questions.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AgentRequest"
              },
              "examples": {
                "english": {
                  "value": {
                    "query": "What is Lu Zhang building for AI for Science?",
                    "locale": "en"
                  }
                },
                "chinese": {
                  "value": {
                    "query": "Lu Zhang 的 AI for Science 方向是什么？",
                    "locale": "zh"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Agent answer with citations",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AgentResponse"
                }
              }
            }
          },
          "405": {
            "description": "Unsupported HTTP method",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "500": {
            "description": "Server error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    },
    "/api/openapi": {
      "get": {
        "summary": "OpenAPI document",
        "responses": {
          "200": {
            "description": "OpenAPI 3.1 JSON spec",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    },
    "/api/docs": {
      "get": {
        "summary": "Swagger UI",
        "responses": {
          "200": {
            "description": "Interactive Swagger UI",
            "content": {
              "text/html": {
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "AgentRequest": {
        "type": "object",
        "required": [
          "query"
        ],
        "properties": {
          "query": {
            "type": "string",
            "minLength": 1,
            "maxLength": 800,
            "description": "Question from the website visitor."
          },
          "locale": {
            "type": "string",
            "enum": [
              "en",
              "zh"
            ],
            "default": "en"
          }
        }
      },
      "AgentResponse": {
        "type": "object",
        "required": [
          "mode",
          "answer",
          "citations"
        ],
        "properties": {
          "mode": {
            "type": "string",
            "enum": [
              "llm",
              "retrieval-only",
              "retrieval-fallback",
              "empty"
            ]
          },
          "answer": {
            "type": "string"
          },
          "citations": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Citation"
            }
          },
          "trace": {
            "type": "object",
            "additionalProperties": true,
            "description": "Optional debug metadata. Returned only when INCLUDE_TRACE=true."
          },
          "agent": {
            "type": "object",
            "additionalProperties": true,
            "description": "Structured site-agent metadata: inferred intent, route, plan, actions, and follow-up prompts."
          }
        }
      },
      "Citation": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer"
          },
          "title": {
            "type": "string"
          },
          "url": {
            "type": "string",
            "format": "uri"
          },
          "type": {
            "type": "string"
          }
        }
      },
      "HealthResponse": {
        "type": "object",
        "properties": {
          "ok": {
            "type": "boolean"
          },
          "service": {
            "type": "string"
          }
        }
      },
      "ErrorResponse": {
        "type": "object",
        "properties": {
          "error": {
            "type": "string"
          }
        }
      }
    }
  }
}