SkyNet:基于 FastAPI/Next.js/OpenAI 兼容模型的 AI 辅助文件合规审查系统

SkyNet 是一个 AI 辅助文件合规审查系统,适用于需要对文档、演示稿、PDF、图片和文本文件进行规则化审核的团队。

Branch2Tags0
FilesLast commitLast update
5 months ago
5 months ago
4 months ago
6 months ago
5 months ago
6 months ago
4 months ago
4 months ago
5 months ago
5 months ago
6 months ago

SkyNet

SkyNet is an AI-assisted file compliance review system for teams that need to inspect documents, slides, PDFs, images, and text files against configurable review rules. It combines a FastAPI/Agno AgentOS backend, a Next.js review workspace, PostgreSQL storage, and OpenAI-compatible model providers.

The project is designed as a practical open-source starter for building internal content review, document compliance, brand consistency, and publication approval workflows.

Features

  • Multi-format file review for PDF, PPTX, DOCX, images, Markdown, and plain text.
  • OpenAI-compatible model integration, including OpenAI and compatible providers.
  • Built-in generic review rules for brand naming, content safety, factual accuracy, intellectual property, privacy, formatting, and presentation quality.
  • Structured review reports with result, summary, risk level, evidence, and suggestions.
  • Background review queue with configurable concurrency and task timeout.
  • PostgreSQL-backed audit history with list, detail, and delete workflows.
  • Rule inspection page that reads the public rule set from the backend prompt.
  • Docker Compose deployment with Nginx, frontend, backend, and PostgreSQL services.

Architecture

Browser
  |
  v
Next.js frontend
  |
  | /api/agentos/* rewrite
  v
Agno AgentOS + FastAPI backend
  |
  +--> PostgreSQL audit history
  |
  +--> file preprocessors for PDF, PPTX, DOCX, text, and images
  |
  +--> OpenAI-compatible model API

In production, Nginx is the single public entry point. The frontend and backend are kept on the internal Docker network, and model credentials are only mounted into the backend container.

Repository Layout

.
├── backend/                 # FastAPI + Agno AgentOS backend
│   ├── app/
│   │   ├── agents/          # Review agent construction
│   │   ├── api/             # Business API routers
│   │   ├── db/              # SQLAlchemy session and models
│   │   ├── hooks/           # File preprocessing hooks
│   │   ├── prompts/         # Compliance prompt and public rules
│   │   ├── repositories/    # Persistence access layer
│   │   ├── services/        # Review queue and parsing services
│   │   └── tools/           # File extraction helpers
│   ├── tests/               # Backend test suite
│   ├── agentos.py           # AgentOS application
│   └── run.py               # Local backend entry point
├── frontend/                # Next.js 15 + React review workspace
│   ├── src/app/             # App Router pages
│   ├── src/components/      # UI, chat, and audit components
│   ├── src/hooks/           # Review and stream handling hooks
│   ├── src/lib/             # Frontend utilities and rule metadata
│   └── public/              # Static assets
├── deploy/                  # Nginx configuration
├── docker-compose.yml       # Production-style local deployment
├── package.json             # Root orchestration scripts
└── .env.example             # Environment variable template

Requirements

  • Node.js 18 or newer
  • pnpm 9 or newer
  • Python 3.11 or newer
  • uv
  • PostgreSQL 16 or compatible
  • An OpenAI-compatible chat model endpoint

Docker users only need Docker and Docker Compose for the full stack, but local development is faster when Node.js, pnpm, Python, uv, and PostgreSQL are installed.

Quick Start

Install all dependencies:

pnpm run setup:all

Create local configuration:

cp .env.example .env

Edit .env and provide at least:

OPENAI_API_KEY=your_api_key
REVIEW_MODEL=gpt-5.2
DATABASE_URL=postgresql+psycopg://skynet:skynet@localhost:5432/skynet

Start the development servers:

pnpm run dev

Default local URLs:

Frontend: http://localhost:3000
AgentOS:  http://localhost:7777

The default Agent ID is:

file-compliance-agent

Configuration

SkyNet reads backend configuration from .env in the repository root.

Variable Required Default Description
OPENAI_API_KEY Yes None API key for OpenAI or an OpenAI-compatible provider.
OPENAI_BASE_URL No None Base URL for compatible providers. Leave empty for OpenAI defaults. A host-only URL is normalized with /v1.
REVIEW_MODEL No gpt-5.2 Model used for file review.
DATABASE_URL Yes None PostgreSQL connection string.
OPENAI_TIMEOUT_SECONDS No 360 Timeout for a single model request.
OPENAI_MAX_RETRIES No 0 Retry count for model requests.
AUDIT_REVIEW_TIMEOUT_SECONDS No 480 End-to-end timeout for one review task.
AUDIT_REVIEW_MAX_CONCURRENCY No 5 Maximum number of concurrent review tasks.
MODEL_PROVIDER No auto Provider selection mode. Compatible aliases such as qwen and dashscope resolve to OpenAI-compatible mode.
OPENAI_API_MODE No chat Model API mode.
AGENTOS_RELOAD No true Enable backend reload in local development.
AGENTOS_TRACING No false Enable AgentOS tracing.
AGENTOS_CORS_ORIGINS No * Comma-separated CORS origins.

Docker Compose overrides DATABASE_URL inside the backend container so it points to the internal postgres service.

Development

Install frontend and root Node.js dependencies:

pnpm run setup

Install backend dependencies:

pnpm run setup:backend

Run both services:

pnpm run dev

Run services independently:

pnpm run backend
pnpm run frontend

Useful frontend commands:

pnpm --dir frontend dev
pnpm --dir frontend build
pnpm --dir frontend run typecheck
pnpm --dir frontend run validate

Useful backend commands:

cd backend
uv run python run.py
uv run pytest tests -v
uv run ruff check .

Review Rules

The source of truth for backend review behavior is:

backend/app/prompts/compliance_prompt.md

The public rule section is delimited by:

<!-- public-rules:start -->
<!-- public-rules:end -->

The /rules page and /audit-rules API parse that public section and show it to users. Keep rules concise, testable, and provider-neutral. Avoid embedding private organization names or business-specific policies in the open-source default rule set.

Current rule groups:

Group Scope
Brand Brand naming, terminology, product and organization names.
Compliance Content safety, political compliance, IP, licenses, privacy, and confidentiality.
Content Factual accuracy, citations, consistency, outdated material, and presentation quality.
Format Numbers, dates, punctuation, spelling, and language quality.

Review results are normalized into three outcomes:

Result Meaning
Pass No clear violation found.
Fail At least one clear violation found.
Needs review Suspicious or unverifiable issue that needs human judgment.

API Overview

The backend exposes AgentOS routes plus business APIs used by the frontend.

Method Path Description
GET /audit-rules Return public review rules parsed from the prompt.
POST /audit-reviews/run Submit a review task.
GET /audit-reviews List review history.
GET /audit-reviews/{id} Fetch one review record.
DELETE /audit-reviews/{id} Delete one review record.

During local frontend development, Next.js rewrites:

/api/agentos/* -> http://localhost:7777/*

Testing and Quality

Run the full repository lint command:

pnpm run lint

Run backend tests:

cd backend
uv run pytest tests -v

Run frontend validation:

pnpm --dir frontend run validate

The current Next.js lint command uses next lint, which is deprecated in Next.js 16. Projects upgrading to Next.js 16 should migrate to the ESLint CLI.

Docker Deployment

Build and start the full stack:

docker compose up --build

Default production-style entry point:

http://localhost:14576

Services:

Service Internal address Notes
nginx :80 Public entry point, exposed as localhost:14576.
frontend frontend:3000 Next.js production server.
backend backend:7777 AgentOS and business APIs.
postgres postgres:5432 PostgreSQL 16 with persistent volume.

Nginx forwards /api/agentos/* to the backend and disables response buffering for streaming model output.

Security Notes

  • Never expose .env or model provider credentials to the frontend.
  • Treat uploaded files as untrusted input.
  • Review reports are AI-assisted and should not be used as the sole authority for legal, regulatory, or publication decisions.
  • For public deployments, add authentication, rate limiting, upload size limits, file retention policies, and operational logging before exposing the service.
  • Verify that model providers and storage locations meet your data handling requirements before processing sensitive documents.

Troubleshooting

ModuleNotFoundError: No module named 'agno'

Start the backend through uv:

pnpm run setup:backend
pnpm run backend

or:

cd backend
uv sync
uv run python run.py

PostgreSQL connection failed

Check that PostgreSQL is running and that DATABASE_URL points to the correct host. When using Docker Compose, the backend container receives an internal database URL automatically.

Model requests timeout

Increase OPENAI_TIMEOUT_SECONDS for slow providers and AUDIT_REVIEW_TIMEOUT_SECONDS for large files. Also verify the model name, API key, and base URL.

Frontend cannot reach backend

In local development, confirm that the backend is running on localhost:7777. In Docker, confirm that AGENTOS_PROXY_TARGET is set to http://backend:7777.

Contributing

Contributions are welcome once the repository is published with a license and contribution policy. For now, use the following workflow:

  1. Open an issue describing the problem or proposed change.
  2. Keep changes focused and covered by tests where possible.
  3. Run pnpm run lint and relevant backend/frontend tests before submitting.
  4. Document behavior changes in this README or the relevant package README.

Good first areas to improve:

  • Authentication and multi-user support.
  • Upload limits, file retention settings, and admin controls.
  • Rule set presets for different industries.
  • More structured model output validation.
  • Additional deployment examples.

License

This repository does not currently declare a root open-source license. Add a LICENSE file and update package metadata before publishing or redistributing it as an open-source project.

Introduction

SkyNet 是一个 AI 辅助文件合规审查系统,适用于需要对文档、演示稿、PDF、图片和文本文件进行规则化审核的团队。

Customize your domain