Full-stack Document AI · LangGraph Agent

An air-gapped document AI app,
evolved into a declarative agent

DocPilot is an offline-first full-stack desktop web app for engineering documents (specifications, contracts and technical reviews). Built with FastAPI + React, it ships as a single PyInstaller exe and calls LLMs through an OpenAI-compatible endpoint (OpenRouter by default). One principle — tools over tokens. Deterministic code handles calculations and validation; the LLM handles orchestration and narrative.

GitHub repository → LangGraph agent →

01

Context — abundant site documents, restricted networks

Specifications, contracts and technical-review documents on EPC and plant projects are voluminous and repetitive. Yet many sites prohibit external internet and cloud SaaS for security reasons. DocPilot addresses both constraints: (1) it chains four document stages (translate, analyze, review, write) in one app, and (2) installation and startup require only a single executable + local server to run in a browser on an air-gapped network. Swap the LLM gateway to use the same app with an internal endpoint or OpenRouter.

This page presents the anonymized public portfolio version of an internal competition entry. Production secrets, the internal gateway and customer data are excluded.

02

System — a full stack inside one exe

The backend uses FastAPI + SQLite + Fernet (secret encryption); the frontend uses React 18 + Vite + TypeScript + Ant Design. FastAPI serves the frontend build as static assets. Packaged with PyInstaller onedir, DocPilot.exe starts a local server and opens the default browser automatically. The screenshot below shows a short specification clause translated in the actual app: an OpenRouter response in 1.9 seconds, displayed directly in the app UI.

DocPilot translation screen — a specification clause and its live translation result

Sentence-translation mode — an ASME B31.3 piping clause and the actual LLM translation. Connection status, model and active tasks appear at the top.

FastAPISQLiteFernet React 18Vite · TSAnt Design PyInstaller onedirhttpx
03

Four document modules — chaining analysis through deviation drafting

Stages light up sequentially when you scroll into this section. Translate operates independently of this pipeline, with column, whole-file and sentence modes.

Analyze's placeholder context system (top left), the Write and Review modules, and Settings consolidated around one OpenRouter key. Credentials are stored in a locally encrypted file.

04

tools over tokens — LLM orchestration, reliability in code

Industrial domains with little tolerance for errors cannot rely on an LLM alone. DocPilot funnels LLM calls through one thin client (llm_client.py), wrapped in a deterministic reliability layer.

Reliable calls

A global concurrency semaphore, exponential-backoff retries, 429/Retry-After handling and a typed error taxonomy (AUTH/RATE/TIMEOUT/TRUNCATED/…) turn failures into specific codes.

Run recovery

The batch runner manages progress and cancellation, restores active runs after a browser refresh, and retries only the rows that failed.

Any gateway that follows the OpenAI-compatible schema (/chat/completions, Bearer) works. Switching from the internal LLM gateway to OpenRouter required replacing just this client file.

05

Offline delivery — run an executable

build_windows.ps1 installs dependencies from an offline wheelhouse and uses PyInstaller onedir to build DocPilot.exe. Launching it starts a local FastAPI server at 127.0.0.1 and opens the default browser automatically. Secrets are encrypted with Fernet and stored locally; the app communicates externally only with the LLM endpoint. The Python runtime is included in one folder for transfer into an air-gapped environment, without Electron or Tauri.

offline wheelhousePyInstaller onedir Automatic browser launchFernet-encrypted secrets
06

Evolution — adding a declarative LangGraph agent

After stabilizing the app, I explored its evolution into an agent in a separate package (agents/). It performs deviation reviews of EPC specification clauses using a state machine whose complete workflow is declared in YAML and compiled with langgraph. The deployed app runs without langgraph; the agent is an isolated capability showcase.

LLM node Deterministic tool / gate Transparent flag

Named routers return branch labels only; the final status is always written by a deterministic node. Ambiguity triggers a clarify loop (up to 2 attempts by default). If exhausted, the agent reports needs_human_review transparently, without manufacturing certainty.

The traces below are from actual OpenRouter smoke-test runs.

$ python -m agents.run --input samples/validation_fail.json · Clause citing GB/T 700 as its sole standard
  1. extract:  candidate=True  confidence=0.85
  2. clarify(attempt=1):  confidence=0.90  ambiguous=False
  3. validate: ok=False  issues=["standard_ref body 'GB/T' is not a recognized standard"]
  4. output:  status=validation_failed
     └ The deterministic tool rejects the unapproved standard, skips draft and exits
$ python -m agents.run --input samples/ambiguous_clause.json · An ambiguous clause such as “suitable alternative materials may be used”
  1. extract:  candidate=True  confidence=0.70
  2. clarify(attempt=1):  confidence=0.70  ambiguous=True
  3. clarify(attempt=2):  confidence=0.70  ambiguous=True
  4. output:  status=needs_human_review
     └ Still unresolved after 2 attempts → flagged for human review instead of forcing a conclusion

Agent code · YAML · tests →

07

The trajectory of one project

The same problem, refined over time beyond a short-lived demo.

08

Why this project — limitations and next steps

Limitations: standard-reference validation for deviation reviews uses only an illustrative demo set (ASME/ASTM/API/ISO/EN/ANSI), and the agent has few samples. Next: connect a standards-reference database, extend workflows by document type, and revalidate with an internal gateway.

GitHub repository (app, agent and all documentation) LangGraph agent ← Portfolio home