Getting started¶
The full user-facing guide lives in the repo’s README.md at the root, and is inlined below so it stays canonical there. If you’re reading this on GitHub Pages, the content is identical to the README on the repository landing page.
OnField Assistant 🌵 (ofa)¶
An AI-powered reasoning and autonomous execution agent tailored for the NLR Kestrel HPC system. OnField Assistant (ofa) utilizes a local Large Language Model orchestrator (powered by Ollama and gemma4:31b-it-q8_0) alongside Retrieval-Augmented Generation (RAG) using ChromaDB to help researchers build cases, compile complex scientific codebases, organically navigate Kestrel’s HPC documentation, and execute multi-step SLURM jobs natively.
Features¶
Automated Hardware Allocation: When invoked from a Kestrel login node, the
ofawrapper seamlessly detects the environment and spins up an interactive GPU node allocation (targeting H100 partitions). It loads the CUDA module that matches the node’s OS (set per site insite.toml) before launching the LLM.Autonomous ReAct Framework (Plan & Execute): The assistant is instructed to follow a strict planning phase before acting. It creates persistent
planblocks and iterates autonomously using a variety of parsed markdown blocks:writeandedit: For creating and modifying files in the current workspace.bash: For interactive terminal commands with real-timesubprocess.Popenstreaming back to the user.sbatch: For dispatching background jobs and checking on their SLURM queue status without freezing the conversational loop.searchandfetch: For searching the internet or reading external web documentation when unsure.
Domain-Specific Modes: By passing command-line arguments, the overarching python execution loop swaps the injected system prompts and RAG databases to act as specialized domain experts (e.g., general codebase engineering, specific AMReX compilation, or ReFrame module migrations).
Private data indexing: Each user can index their own data (
ofa --add-private <dir>) into a per-user store that is retrieved automatically alongside the shared corpora — no write access to the shared install required. See Index your own private data.Optional proprietary/frontier models (LiteLLM backend): By default ofa runs fully locally (nothing leaves the node). Optionally,
ofa --litellm(orOFA_BACKEND=litellm) routes model calls to an internal OpenAI-compatible LiteLLM gateway for a frontier model on hard cases, while still using ofa’s local RAG + prompts. Opt-in and announced; the API key stays server-side. See Use a proprietary/frontier model (LiteLLM backend).Optional large open-weight models (vLLM backend): Models too large for one GPU are selected like any other (
ofa --model nemotron-3.5-super-vl:120b-a12b);ofastarts or reuses a vLLM server for them on whole GPU nodes, and the server stops itself when idle. Everything stays on Kestrel. See Use a large multi-GPU / multi-node model (vLLM backend).Intelligent Context Management: To survive long debugging or compilation sessions, the agent intelligently handles Context Window Collapse. Massive compiler toolchains are dynamically truncated. In deeply extended sessions (over 20 turns), older terminal stdout logs are systematically compressed while preserving the agent’s fundamental reasoning and the user’s initial instructions to avoid amnesia.
Robust Fault Tolerance & Safeguards: The Python orchestrator natively intercepts hanging shell commands with
/dev/nullstdin piping. It tracks consecutive execution errors, pausing the autonomous loop if the agent hallucinates a failing command 3 times in a row, dropping control back to the human user. The daemon catchesSIGTERMsignals for 30-minute allocation timeouts, shutting down gracefully.
Usage¶
Run the ofa command from a Kestrel login node after loading the
assistant module. That module puts ofa on $PATH, exports
$OFA_ROOT, and wires up the Python + ChromaDB + Ollama toolchain
bundled with the deploy.
module load assistant
ofa --help
If you’d rather drive ofa from VS Code Chat (the eight modes appear
directly in Copilot Chat’s model picker) instead of the shell, skip
straight to Use ofa from VS Code Chat
below — that section handles the module load automatically inside a
one-click SLURM allocation. The CLI examples in this section are for
the terminal-native path.
# Default mode: general coding / software-engineering assistant
$ ofa
# Single-shot query (runs without a continuous prompt loop)
$ ofa "explain what a __global__ kernel does in CUDA"
# Specialized Agent Modes
$ ofa --openfoam # OpenFOAM case generator (was the default in versions <= 1.0)
$ ofa --code # General coding assistant (redundant — this is the default now)
$ ofa --hpc # Kestrel HPC, SLURM documentation, and topology expert
$ ofa --amrex # AMReX C++ framework assistant
$ ofa --marbles # MARBLES (LBM thermal solver on AMReX) assistant
$ ofa --quantum-computing # Quantum computing (rigorous verification of gates / unitarity / tensor order)
$ ofa --vasp # VASP (Vienna Ab initio Simulation Package) — tutorials, notes, pinned build/module doc
$ ofa --rhel9_reframe # ReFrame integration expert strictly adhering to the Kestrel RHEL9 software stack
# Additional Flags
$ ofa --resume # Resume the previous interactive session (uses $OFA_SCRATCH/.ofa_session.json)
$ ofa --save <dir> # (with --openfoam) save generated template cases to a directory
$ ofa --no-rag # Disable ChromaDB context retrieval; relies solely on standard LLM weights
$ ofa --fast # (with --openfoam) single-shot file generation (skip plan stage)
$ ofa --litellm # Use an internal LiteLLM gateway (frontier model) with ofa's local RAG;
# run once for setup steps. Composes with any mode: ofa --litellm --amrex
$ ofa --vllm # Use a vLLM server you started by hand (see the vLLM section below)
$ ofa --model <id> # Use another model from the registry (default gemma4:31b-it-q8_0);
# large models start their own multi-GPU server automatically
$ ofa --list-models # List the model registry and exit
$ ofa --add-private <dir> # Index your own files into a per-user private RAG store
# BYOK / programmatic server (OpenAI-compatible HTTP endpoint on this node)
$ ofa --serve # Start the local HTTP server; see docs/byok-vscode.md
$ ofa --serve --serve-enable-tools # Also forward OpenAI tool_calls to Ollama (experimental)
$ ofa --serve --serve-quiet # Silence per-request stderr log (banner + errors still print).
# Handy when --serve shares a shell with an interactive TUI
# (e.g. opencode on RHEL9) so background traffic doesn't leak
# into the foreground display.
Architecture¶
bin/ofa: The frontend Bash CLI wrapper. It routes SLURM jobs, sanitizes nested PMI and SLURM context variables to avoid step allocation deadlocks, natively forces the correct CUDA toolkit loads, and acts as the entrypoint for the Python environment.src/ofa_main.py: The central python controller. Handles Ollama binary lifecycle management viasubprocess, processes ChromaDB interactions (_hybrid_search), loops user input, captures output, and dictates the strict regex parsing logic for the tool-calling mechanism.src/ofa_server.py: OpenAI-compatible HTTP shim used byofa --serve— exposes ofa’s system prompts + RAG + memory + multimodal (vision) at/v1/chat/completionsfor VS Code BYOK,curl, and the Python client below.src/ofa_client.py: Zero-dependency (stdlib-only) Python client.from ofa_client import ask, Session— see the next section.src/rebuild_indices.py: Config-driven RAG (re)ingester. Readscollections.tomland refreshes the ChromaDB collections declared there. See Updating the RAG indices.collections.toml: Declarative source-to-collection mapping consumed by the rebuild script (extend it when you add a new source or a new collection).examples/: Worked end-to-end scripts users can copy verbatim. Currently shipsfit_and_ask.py— acurve_fitdemo that shows theSession+ JSON-extraction patterns in ~230 LOC.prompts/: Directory configuring the personas.common.txtestablishes the global rules for the agent, establishing the planning pipeline, code syntax standards, and environment constraints.code.txt,hpc.txt, and others inject the role-specific capabilities.vectordb/: The persistent storage directory for the offline ChromaDB ingestors, containing chunked embeddings for Kestrel’s manuals, OpenFOAM examples, and RHEL module stacks.
Install on a new HPC¶
ofa was written for NLR’s Kestrel but is portable to any Linux HPC with a Slurm scheduler and a GPU node. The installer bootstraps everything you need — a private Miniforge Python distribution, the Ollama binary, an embedding model, and (optionally) the default LLM — into the repo checkout itself. No system-wide changes.
git clone https://github.com/nileshsawant/onfield-assistant.git
cd onfield-assistant
./install.sh
What it does, in order (each step is opt-out via a flag):
Miniforge — downloads and installs into
env/, giving you a self-contained Python 3.11+ without touching the host’s system Python.Python deps —
pip install -r requirements.txtinside that env. Top-level packages are pinned to a known-good set snapshotted from the Kestrel deploy, so a fresh install is reproducible rather than a moving target.Ollama binary — pulls the latest static release from github.com/ollama/ollama into
bin/ollama. Arch-aware (x86_64 / aarch64). The Linux release bundles CUDA (+Vulkan) backends only — on AMD/ROCm or GPU-less clusters Ollama falls back to CPU inference; the installer detects this and warns.Embedding model — snapshots
BAAI/bge-small-en-v1.5from HuggingFace intoembedding_model/(~120 MB) via thehfCLI.LLM — prompts to pull
gemma4:31b-it-q8_0(~34 GB) intomodels/. Skip with--skip-model-pullif you want to pull a different model, or curate a smaller one viaOFA_INSTALL_MODEL_ID.site.tomlwizard — interactive prompts for site name, scheduler (slurmornone), partition/GRES/ntasks, GPU-stack module, protected paths, etc. Writessite.tomlat the repo root. Falls back to the annotatedsite.example.tomlin--non-interactivemode.RAG indices — if
repos/is populated (percollections.toml), rebuilds the ChromaDB collections. A fresh clone ships no corpora (repos/*is gitignored) — the installer lists the source dirscollections.tomlexpects so you can populate the ones you want, then runsrc/rebuild_indices.py.env.sh+ Lmod template — writes a sourceable activation script and an Lmod modulefile template undertools/.Large-model engines (opt-in) —
--with-vllmbuilds the vLLM env inenv/envs/vllm, and--with-llamacppbuildsllama-serverintolib/llama.cppfor the large multi-GPU models. Their weights are downloaded separately.
Sites behind a proxy or internal mirror: curl, pip, and hf honor the standard HTTPS_PROXY, PIP_INDEX_URL, and HF_ENDPOINT environment variables, so set those before running the installer.
Useful flags:
./install.sh --skip-model-pull # don't pull gemma4:31b-it-q8_0
./install.sh --skip-wizard # don't run the site.toml wizard
./install.sh --skip-indices # don't rebuild RAG (populate repos/ later)
./install.sh --non-interactive # scripted install, opt-in steps default to skipped
./install.sh --force # redo work even if artifacts already exist
./install.sh --prefix /path/to/checkout # install target (default: install.sh's dir)
./install.sh --with-vllm # also build the vLLM env for the large models (~10 GB)
./install.sh --with-llamacpp # also build llama-server with CUDA (git, cmake, CUDA toolkit)
./install.sh --help # full flag list + env-var overrides
Before you run ofa for real on a new site, audit these files — they’re the pieces the installer can’t infer:
site.toml— verify partition names, GRES, walltime, account-discovery command.collections.toml— replace the Kestrel-specific RAG corpora (amrex,marbles-papers,HPC, …) with sources that make sense for your users.prompts/— the mode prompts template the site identity (name, org, long name) and a short environment note (OS, login nodes, module stack, partitions;environmentinsite.toml) automatically viasite.toml, but leave Kestrel-specific technical content (CUDA module versions, partition names likestandard/hbw,/nopt/nrelprotected paths, Gila cross-references inopenfoam.txt, the RHEL8→RHEL9 body inreframe.txt) as literal text. Rewrite those bits for your cluster; templating them would produce prompts that lie confidently about your setup.Large multi-GPU models (optional) — not set up by default. Without them,
ofa --model <large model>stops right away with a message, and everything else works. To offer them (see Use a large multi-GPU / multi-node model):run
./install.sh --with-vllm --with-llamacpp. Run it on a GPU node, or setOFA_INSTALL_CUDA_ARCH(e.g.90for H100); load your CUDA module or setOFA_INSTALL_CUDA_HOME;download the weights into
vllm-models/andllamacpp-models/;set the Kestrel-specific defaults in
env.shor your module file (commented examples are generated):OFA_VLLM_PARTITION,OFA_VLLM_GPUS_PER_NODE, andOFA_VLLM_NCCL_PLUGIN/OFA_VLLM_LIBFABRIC(Slingshot NCCL plugin; set the plugin to empty on other networks).Edit
RECIPESinsrc/ofa_vllm.pyif your nodes have a different GPU count or memory.
Once you’re satisfied, source the env and go:
source $OFA_ROOT/env.sh
ofa --help
Updating the RAG indices¶
The vector store under vectordb/ is populated from source directories declared in collections.toml at the repo root. To keep the indices current when you git pull a source repo, add a new source, or drop new documents into an existing one, run the rebuild script:
python3 $OFA_ROOT/src/rebuild_indices.py # rebuild all configured collections
python3 $OFA_ROOT/src/rebuild_indices.py --collection <name> # scope to one collection
python3 $OFA_ROOT/src/rebuild_indices.py --list # show configured collections (no model load)
python3 $OFA_ROOT/src/rebuild_indices.py --dry-run # preview additions / skips / orphans
python3 $OFA_ROOT/src/rebuild_indices.py --force # ignore mtime cache; re-embed everything
python3 $OFA_ROOT/src/rebuild_indices.py --clear --collection <name> # drop and rebuild from scratch
python3 $OFA_ROOT/src/rebuild_indices.py --incremental # additive-only: keep chunks in the store even if their source files were removed
Behaviour:
Idempotent. Chunk IDs are SHA-256 of
collection + relative path + chunk index, so re-runs upsert rather than duplicate. Per-file mtime is cached invectordb/.rebuild_state.json; unchanged files are skipped (embedding is by far the slow step).Mixed content per collection. Each collection can list code directories, PDF directories, or both. Each chunk is tagged with a
source_typemetadata field so retrievers can distinguish source files from documents and cite PDF page numbers.Missing source directories are logged and skipped. You can declare a source path in
collections.tomlahead of populating it — the collection activates as soon as content lands.Notebook handling.
.ipynbfiles are parsed as JSON and stripped of cell outputs before chunking, so base64-encoded plot outputs and long stdout dumps don’t pollute retrieval.Orphan sweep. Code files that were previously indexed but no longer exist on disk are removed from the collection on the next rebuild. Two opt-outs are available:
Per-source, in
collections.toml: setkeep_missing = trueon a source entry. Missing files under that root are retained in the store while sibling sources in the same collection continue to sweep normally. Typical use: a papers/PDFs source that shares a collection with a git-tracked code source — the code side should still lose deleted files ongit pull, but the papers side should not.Global, on the command line:
--incrementaldisables the sweep for every source in this run. Useful when you want a single ingest pass to be additive-only for reasons unrelated to source policy.
Run the rebuild inside a Kestrel GPU allocation so the embedding model uses the H100 — the login node’s CUDA driver is older and falls back to CPU, which is considerably slower. Typical wall-times on H100 are a few tens of seconds per thousand chunks.
When rebuilding a collection that was previously indexed by an older ingester, use --clear on the first pass so its stale chunk IDs (from the older scheme) are dropped rather than left alongside the new ones. Subsequent rebuilds don’t need --clear.
Edit collections.toml to add a new collection or a new source directory. Paths starting with / are absolute; others resolve relative to $OFA_ROOT. See the header comment inside that file for the schema.
Common maintenance workflows¶
Concrete recipes for the four situations you’ll actually run into. Each
one runs rebuild_indices.py via the bundled interpreter
($OFA_ROOT/env/bin/python) so you don’t need module load assistant
in the shell — useful for one-shot maintenance where you don’t want to
disturb the interactive environment.
1. Refresh a git-tracked source repo (HPC docs, AMReX, reframe, MARBLES)¶
The repos/HPC, repos/amrex, repos/reframe-universal, and
repos/marblesThermal trees are plain git clones (not submodules).
When upstream publishes new content, pull and rebuild:
cd $OFA_ROOT/repos/HPC && git pull && cd $OFA_ROOT
./env/bin/python src/rebuild_indices.py --collection hpc_docs
--collection scopes the run to one collection so an unrelated
gitignored source (say repos/quantum-papers) isn’t touched. The
mtime cache in vectordb/.rebuild_state.json means only files whose
content actually changed on disk get re-embedded — expect
“[+] N added/updated [=] M unchanged” with a small N and large
M after a routine git pull.
For AMReX, reframe, MARBLES: substitute --collection amrex_src,
--collection reframe_src, or --collection marbles_src.
3. Update a collection where some source files were deliberately emptied¶
Example: repos/quantum-papers/ was cleared to avoid copyright issues,
but you still want the previously-indexed knowledge to remain
available to ofa. The [[collections.quantum_computing.sources]]
entry for repos/quantum-papers already has keep_missing = true
(marbles-papers uses the same pattern), so a plain rebuild is safe:
./env/bin/python src/rebuild_indices.py --collection quantum_computing
Rebuild log will explicitly report:
[~] keep_missing: retaining 8 file entries under sources marked keep_missing=true
[+] N added/updated [=] M unchanged [-] 0 orphaned
The [-] 0 orphaned line is the important one — no papers chunks
were swept away. Chunks from the code source alongside are updated
normally.
If you add keep_missing = true to a source for the first time, no
--clear is needed; the flag only affects future orphan sweeps, not
already-indexed content.
4. Add a new collection or source¶
Edit collections.toml:
[collections.my_new_collection]
description = "Short human-readable description shown by --list."
[[collections.my_new_collection.sources]]
path = "repos/my-new-content" # relative to $OFA_ROOT
type = "code" # or "pdf"
extensions = [".md", ".py"] # ignored for type="pdf"
# keep_missing = true # optional; see workflow 3
# page_ranges = { "file.pdf" = "23-" } # optional PDF slicing
Then populate repos/my-new-content/ and rebuild:
./env/bin/python src/rebuild_indices.py --collection my_new_collection
To wire the new collection into an ofa mode’s retriever, edit the
retrieve_<mode>_context() function in src/ofa_main.py and add a
query against the new collection with a sensible top-k budget.
Without that wiring, the collection is queryable via
src/ofa_client.py but not automatically injected into chat context.
Where to run¶
The RHEL9 login nodes (kl3, kl5) and any compute-node GPU allocation
work. Without a usable GPU the embedder falls back to CPU at ~30
chunks/second, which is adequate for routine updates (a full HPC-docs
rebuild of ~730 chunks takes about 4 minutes). If you already have a
compute-node allocation open, run there for GPU-speed embedding (~5Ă—).
Index your own private data¶
Beyond the shared corpora, each user can index their own data into a
per-user private store that ofa retrieves automatically alongside the
built-in collections — no write access to the shared install required.
# Index a directory (re-run to refresh after edits)
ofa --add-private ~/my-project-notes
ofa --add-private ~/papers --private-name lit-review # custom label
# See what you've indexed
ofa --list-private
# Remove one collection, or everything
ofa --forget-private my-project-notes
ofa --forget-private all
After indexing, just ask ofa (any mode, CLI or VS Code) — private hits are
merged into the retrieved context and clearly marked PRIVATE DATA in the
prompt. Supported today: text and code files (.md, .rst, .txt, source
files, .tex, .ipynb, config files), .pdf, and Office .docx / .xlsx.
Office extraction is text-only and lossy — it drops styling, comments,
tracked changes, and (for spreadsheets) formulas, keeping computed values.
Scanned / equation-heavy PDFs (vision OCR). Plain text-layer extraction
mangles dense math and scanned pages (garbled symbols, (cid:N) artifacts).
ofa detects such pages and automatically re-reads them with the local
vision model — nothing leaves the node. This is on by default; no flag
needed.
|
Behaviour |
|---|---|
|
Default. OCR only pages whose text layer looks degraded; clean pages stay on the fast text path. |
|
OCR every page. Use for fully-scanned documents. Slow. |
|
Disable OCR entirely (fast, text-only). |
ofa --add-private ~/papers # auto-OCRs degraded pages
ofa --add-private ~/scans --private-ocr force # OCR every page (slow)
ofa --add-private ~/notes --private-ocr off # text-only, no OCR
Auto/force OCR needs a vision-capable OFA_MODEL (the default
gemma4:31b-it-q8_0 qualifies); if the model has no vision head, ofa
prints one notice and indexes text-only. Each OCR’d page is rendered to an
image and transcribed to Markdown + LaTeX by the model (~seconds per page),
so an OCR-heavy corpus takes longer to index. To re-index an existing
collection with different settings, just re-run --add-private on the same
directory.
Where it lives. The private store is a separate ChromaDB instance under
$OFA_SCRATCH/vectordb-private, created 0700; its metadata file is 0600.
It is never written to the shared vectordb/. Override the location with
OFA_PRIVATE_VECTORDB.
What to keep in mind for private data:
Retrieved private snippets are sent to whatever client is connected. From the CLI that stays on the compute node, but via VS Code / BYOK they reach your laptop and become part of that editor’s chat history.
ofawrites$OFA_SCRATCH/.ofa_session.jsonand.ofa_history0600, but$OFA_SCRATCHitself is created by the site — confirm its permissions if the data is sensitive.Do not run
ofa --serve --serve-no-authwhile private data is indexed; it would serve that data to anyone who can reach the port.ofaprints a warning if you do. Auth is on by default.The private store rides in your scratch space; treat it with the same care as any other file you place there.
Memory & Session Context¶
The assistant maintains its transient session state natively in your scratch directory (~/.ofa_session.json). Tilde expansion within the tool orchestrator is deliberately handled safely to target your literal home directory instead of generating corrupt relative paths.
If your SLURM allocation expires, the custom signal handlers will safely write the final context to disk. You can then request a new allocation and simply run ofa --resume (with any of your targeted flags) to perfectly reconstruct the context window.
Any permanent global preferences (e.g., “always use 4 spaces for indentation”) mentioned to the assistant are extracted into an isolated ~/.ofa_prefs.txt file and automatically sourced into all future context windows.
Use a proprietary/frontier model (LiteLLM backend)¶
By default ofa is fully local: model inference runs on the node via
Ollama and nothing leaves the machine. For hard problems where you’d
rather lean on a frontier model, ofa can optionally route its LLM
calls to an internal LiteLLM gateway (an OpenAI-compatible endpoint)
while still using ofa’s local RAG corpora, prompts, and agent loop.
Only the chat completion is delegated; retrieval and orchestration stay
on the node.
This is strictly opt-in and clearly announced at startup. The default
backend remains ollama.
One-time setup¶
Get your personal API key from the LiteLLM web UI (that page also lists the model names available to you).
Store the key so
ofacan read it. Either option works:# Option A: a 0600 file in your scratch (recommended — persists) umask 077 printf '%s\n' 'sk-your-key-here' > "$OFA_SCRATCH/.ofa_litellm_key" # Option B: an environment variable (per-shell) export OFA_LITELLM_API_KEY='sk-your-key-here'
ofawarns if the key file is group/world-readable, so keep it0600.(Optional) Pick a model. Set it once via env, otherwise
ofauses its built-in default gateway model:export OFA_LITELLM_MODEL='<model-name-from-the-web-ui>'
Running ofa --litellm before the key is configured prints these exact
setup steps and exits, so you can always just run it to see what’s left.
Usage¶
# Route through the gateway; composes with any mode or flag
$ ofa --litellm
$ ofa --litellm --amrex
$ ofa --litellm "explain this SLURM error"
# Equivalent to the flag, e.g. for scripts / the BYOK server
$ OFA_BACKEND=litellm ofa
$ OFA_BACKEND=litellm ofa --serve
Run ofa --litellm when a backend is already configured to see the
current base URL, model, and key source, plus how to change each.
Environment variables¶
Variable |
Purpose |
Default |
|---|---|---|
|
|
|
|
API key (overrides the key file) |
(unset) |
|
Gateway base URL (must include |
internal gateway |
|
Model name from the web UI |
built-in default |
|
Send images to the gateway model ( |
|
The key file lives at $OFA_SCRATCH/.ofa_litellm_key. Compute nodes can
reach the gateway, so --litellm works inside a normal SLURM allocation.
Use a large multi-GPU / multi-node model (vLLM backend)¶
Some open-weight models are too large for the single H100 that ofa gets
by default. You select them exactly like any other model, and ofa runs
them on their own vLLM or
llama.cpp server on one or more whole
GPU nodes. Everything stays on Kestrel. RAG, prompts and the agent loop still
run in ofa’s own allocation, and only the chat completion goes to the
model’s nodes.
ofa --model nemotron-3.5-super-vl:120b-a12b # 1 GPU node, vision
ofa --model trinity-large-thinking:fp8 --hpc # 2 GPU nodes; any mode works
ofa --model inkling-2-small:594b-a17b # 2 GPU nodes, vision
ofa --model ergo:1.1t-a55b # 4 GPU nodes, 1M context, text only
export OFA_MODEL=nemotron-3.5-super-vl:120b-a12b # or make it your default
In VS Code, pick the model in the OFA: Model setting, then run OFA: Disconnect → OFA: Connect.
What happens:
On the login node,
ofareuses your running server for that model, or submits one and shows its progress. The first start usually takes 3–5 minutes once nodes are free, mostly reading the weights from/nopt(faster when a node has read them recently); for 2-node models, waiting for two free nodes on a busy day can add more. Pressing Ctrl+C stops waiting but leaves the server starting; run the same command again to connect.Later sessions reuse the server instantly. It stops by itself after 60 minutes without requests (or at its 4-hour walltime), so it does not hold nodes while unused. If it has stopped,
ofasays so; runofaagain to start a fresh one.The weights are shared in
$OFA_ROOT/vllm-modelsand$OFA_ROOT/llamacpp-models; nothing is downloaded.
To stop a server early, find it with squeue --me (job name
ofa-vllm-<model>) and scancel <jobid>, or
scancel -n ofa-vllm-<model> (e.g. ofa-vllm-inkling-2-small_594b-a17b).
Server logs are in $OFA_SCRATCH/ofa-vllm-logs/.
So a session with a large model uses two jobs: the model server above
(whole GPU nodes, shared by all your sessions of that model) and your
usual ofa (or ofa-vscode) job, which runs RAG, prompts and tools.
Exiting ofa or OFA: Disconnect in VS Code ends only the second; the
server stays up for the next session until it has been idle for an hour.
Each model has its own server, so switching models starts another one;
stop the old one if you are done with it.
Available models¶
|
Hugging Face repo |
Nodes |
Notes |
Eval score |
Time per answer |
|---|---|---|---|---|---|
|
|
1 |
vision, tools, thinking; 1M context |
0.86 |
~4 s |
|
|
2 |
tools, thinking; 256K context |
0.88 |
~37 s |
|
|
2 |
vision, tools, thinking; 384K context |
not yet re-run on vLLM |
— |
|
|
4 |
tools, thinking (always on); 1M context |
not yet run |
— |
(default, for reference) |
via Ollama |
ÂĽ |
vision, tools, thinking |
~0.91 |
~14 s |
Nemotron and Trinity are ungated US open-weight models under the OpenMDW-1.1
license. Inkling 2 Small (Thinking Machines Lab, US) is Apache 2.0; it needs
a nightly vLLM build (env/envs/vllm-nightly), and vLLM can only split it
across 8 GPUs on 2 nodes. In tests
it reads long prompts at roughly 9,000 tokens/s and writes about 60 tokens/s.
A 1-node llama.cpp fallback (3-bit GGUF, 128K context) is described in
src/ofa_vllm.py.
Amazon Ergo (Amazon Frontier Model Research, US) is under the Amazon Ergo
Open-Weights License, which is free for internal and research use and comes
with an acceptable-use policy (e.g. not for users under 18, no attempts to
circumvent its safety training). It is a 1.1-trillion-parameter model tuned
for coding and agentic work and cannot read images. It needs its own vLLM
build (env/envs/vllm-ergo) and 4 whole GPU nodes per server, so start
it only when you need it and stop it when done. In tests it read a
182K-token prompt in 38 s and writes about 48 tokens/s.
Scores come from eval/run_eval.py (37 questions across all modes). The
default single-GPU model is still the best all-rounder, especially in code
mode. The big models are for experimentation, or for tasks where you’ve seen
the default struggle. NVIDIA-Nemotron-3-Ultra-550B (2 nodes) was tried and
dropped: its vLLM engine hung mid-run.
Settings¶
Variable |
Purpose |
Default |
|---|---|---|
|
Partition for the server job |
|
|
Walltime for the server job |
|
|
Stop the server after this many minutes without requests ( |
|
|
Nodes to avoid, e.g. a GPU node that keeps failing |
(none) |
|
Where the shared vLLM weights live |
|
|
Where the shared GGUF files live |
|
|
GPUs requested per server node |
|
|
|
|
|
CUDA runtime libraries |
Kestrel’s CUDA 12.8 |
|
Slingshot NCCL plugin and libfabric; empty plugin = TCP |
Kestrel’s builds |
The server recipes (nodes, GPU layout, vLLM environment and vllm serve
arguments per model) are in src/ofa_vllm.py. To add a model, download its
weights into $OFA_ROOT/vllm-models, add a recipe there, and add its sampling
settings to MODEL_REGISTRY in src/ofa_main.py. Models that need a newer
vLLM than the default environment can use a separate one, built with
OFA_VLLM_NIGHTLY=1 OFA_VLLM_ENV=$OFA_ROOT/env/envs/vllm-nightly tools/vllm-env.sh
and named in the recipe’s env.
Recipes with "engine": "llamacpp" run a GGUF file from
$OFA_ROOT/llamacpp-models with tools/llamacpp-serve.sbatch on one node.
That uses llama-server built from source into $OFA_ROOT/lib/llama.cpp
(version in lib/llama.cpp/VERSION), with CUDA, for the H100s (sm_90), and
with its web UI disabled. On a new site ./install.sh --with-llamacpp builds
it. To rebuild an existing install by hand, on a GPU node:
git clone --depth 1 https://github.com/ggml-org/llama.cpp && cd llama.cpp
export CUDA_HOME=/nopt/nlr/apps/kestrel-gpu/cuda/12.8.1 PATH=/nopt/nlr/apps/kestrel-gpu/cuda/12.8.1/bin:$PATH
cmake -S . -B build -DGGML_CUDA=ON -DCMAKE_CUDA_ARCHITECTURES=90 -DBUILD_SHARED_LIBS=OFF -DLLAMA_CURL=OFF
cmake --build build -j 32 --target llama-server
cp build/bin/llama-server $OFA_ROOT/lib/llama.cpp/bin/
With NCCL’s Slingshot plugin, vllm-serve.sbatch sets
FI_CXI_DISABLE_HOST_REGISTER=1 FI_MR_CACHE_MONITOR=userfaultfd NCCL_CROSS_NIC=1 NCCL_NET_GDR_LEVEL=PHB NCCL_SOCKET_IFNAME=hsn unless they
are already set; without them a multi-node model can hang in its first
warm-up with all GPUs at 100%.
Troubleshooting¶
GPU check failed on <node>; retrying without it: the server job checks every GPU before loading.ofaretries once without the bad node; please report the node to HPC operations.the … server job … ended before it was ready: open the log it names and look for the firstERRORline.The … server may have stopped after being idle: exit and runofaagain to start a new one.this conversation is longer than <model>'s context window: start a new chat, or switch to a model with a larger context (see the table).[N image(s) omitted: <model> cannot read images]: the conversation holds images (e.g. from an earlier vision model) and the current model is text-only, soofareplaced them with this note.A reply stops right after “Let me …:” (Agent mode): the model announced an action without a usable tool call. Type proceed. If it keeps happening, check OFA: Show Logs for
turn ended with no tool calland report that line. Very long chats make this more likely; start a new chat per task.
Advanced: run the server by hand¶
tools/vllm-serve.sbatch can serve any local model directory, and
ofa --vllm connects to it. Use this for models without a recipe.
OFA_VLLM_MODEL=/path/to/model \
OFA_VLLM_ARGS="--trust-remote-code --enable-auto-tool-choice --tool-call-parser xml_tools --reasoning-parser think_tags" \
sbatch -A <account> -p gpu-h100s --nodes=1 -t 04:00:00 $OFA_ROOT/tools/vllm-serve.sbatch
# when its log says "vLLM ready":
ofa --vllm # composes with any mode flag and with --serve
xml_tools and think_tags are parsers for the <tool_call> and <think>
formats these models use; vllm-serve.sbatch loads them from
tools/vllm_parsers.py. The job writes its address and a per-job API key to
$OFA_SCRATCH/.ofa_vllm_endpoint.json (mode 0600, removed when it ends). In
VS Code, set ofa.backend to vllm to use a hand-started server.
Other vllm-serve.sbatch settings: OFA_VLLM_NAME (served model name;
default the directory name), OFA_VLLM_MAX_LEN (default 131072),
OFA_VLLM_STARTUP_TIMEOUT (default 5400 s), OFA_VLLM_IDLE_MINUTES,
OFA_VLLM_ENDPOINT, OFA_VLLM_ENV (default $OFA_ROOT/env/envs/vllm; build
it on a new site with tools/vllm-env.sh), and OFA_VLLM_NCCL_PLUGIN
(Slingshot NCCL plugin; empty falls back to TCP). Weights can be fetched with
$OFA_ROOT/env/envs/vllm/bin/hf download <repo> --local-dir <dir> in a batch
job.
Use ofa from VS Code Chat (the OnField Assistant extension)¶
VS Code’s Chat / Copilot Chat picker can drive ofa if you install the
bundled OnField Assistant extension on the Kestrel-remote side. The
extension registers the eight ofa modes as a LanguageModelChatProvider
and handles the SLURM allocation, the login-node TCP bridge, and the API
key for you — nothing needs to be configured on your laptop.
End-to-end verified flow (Mac laptop + Kestrel + VS Code Remote-SSH):
Attach VS Code to Kestrel. Standard Remote-SSH — open a new window connected to your Kestrel login node.
Install the extension on the remote. In the Kestrel-attached window:
Cmd+Shift+X→⋯menu at the top of the Extensions sidebar → Install from VSIX… → pick/nopt/nrel/apps/cpu_stack/software/openfoam/assistant/vscode-ext/ofa-vscode.vsix. Reload when prompted. The extension shows up under SSH: KESTREL asofa-vscode.Bring up the server.
Cmd+Shift+P→ OFA: Connect. This allocates a debug GPU node, launchesofa --serve --serve-enable-tools, and opens a TCP bridge (built into the extension; no extra tools needed) on login-node port49643. Watch progress with OFA: Show Logs. Wait for the connect-success toast.Chat. Open Copilot Chat (
Cmd+Ctrl+I). Click the model picker at the bottom of the panel and pick any entry under OnField Assistant (Kestrel) — e.g.ofa · hpc. Ask mode works for Q&A; Agent mode additionally lets the model apply edits and run commands via tool calls.
Tear down with Cmd+Shift+P → OFA: Disconnect — this releases
the SLURM job and closes the bridge. Subsequent sessions only need
step 3; if the job a window started is still alive after a reload or an
SSH reconnect, that window picks it up again automatically instead of
queueing a new one. Other windows leave it alone (you can still attach
one with OFA: Connect if the first window isn’t using it), and an
automatic reconnect never cancels or replaces a job the window didn’t
start, so several open windows don’t fight over one session.
On connect the extension only says which job it uses: pick an OnField Assistant model in the chat model picker. No URL or API key needs pasting.
Troubleshooting the extension¶
“Remote Extension host terminated unexpectedly” (repeatedly): each Kestrel login node limits every user to 6 GiB of memory for all their processes there. Several VS Code windows on the same login node (each with its own extension host, Python language server and Copilot runtime) can exceed it, and the kernel kills the largest process. Close windows you don’t need, connect some windows to a different login node (e.g.
kl5instead ofkl6), or disable Pylance in windows where you don’t edit Python. After many reconnects, Remote-SSH: Kill VS Code Server on Host clears leftover servers.job … is in use by another VS Code window: that job belongs to another window; use OFA from there, or disconnect it there first.Jobs you did not expect: each window starts its own
ofa-vscodejob when you connect it.squeue --me -n ofa-vscodelists them; OFA: Disconnect in a window releases its job.
How the extension handles keys and ports¶
You never copy a token. ofa --serve generates (or reuses) a bearer
token at $OFA_SCRATCH/.ofa_api_key and prints it in its startup
banner; the extension scrapes that line, keeps the value in memory for
the lifetime of the connection, and sends it as an
Authorization: Bearer … header on every request. Because both the
extension and the server run on the Kestrel side, the token never
crosses to your laptop and is never written to any VS Code config.
This is the main difference from the older BYOK route, where you pasted the token into Chat: Manage Language Models → gear → Update API Key because Copilot Chat read it from VS Code’s per-provider secret storage. The extension bypasses secret storage entirely.
Ports likewise need no attention: the compute-node listen port is
chosen per user and persisted in $OFA_SCRATCH/.ofa_serve_port, while
the login-node bridge is pinned to 49643
(ofa.laptopSideBridgePort). The bridge is re-established on every
connect, so a new SLURM allocation on a different node needs no
reconfiguration.
Token limits are derived from the model you select in ofa.model
rather than hardcoded, so the picker advertises the real context window
(the default gemma4:31b-it-q8_0 runs at its full 262144-token
context). Changing ofa.model requires
OFA: Disconnect → OFA: Connect, since the backing LLM is chosen
when ofa --serve starts.
Deprecated: the manual BYOK route¶
Earlier versions required registering the modes yourself in a
laptop-side chatLanguageModels.json via
tools/byok-update-config.py. The extension replaces that, and running
both leaves you with two redundant groups in the model picker —
OFA (Kestrel) from BYOK and OnField Assistant (Kestrel) from the
extension — pointing at the same server. If you see both, delete the
OFA (Kestrel) provider (via Chat: Manage Language Models, or by
removing that object from chatLanguageModels.json) and reload.
The BYOK path is still documented for non-VS-Code clients and manual
setups: docs/byok-vscode.md.
Bring your own agent¶
ofa --serve speaks the OpenAI /v1/chat/completions API (the same
endpoint the VS Code BYOK setup above uses), so any agent framework
that lets you point at a custom base_url + api_key can use ofa as
its backend LLM — not just VS Code. Two verified integrations:
Use ofa from opencode (RHEL9 · access-gated)¶
opencode is a terminal-native coding TUI. On Kestrel
it’s shipped as a module (RHEL9 nodes only, granted on request — ask the
maintainers). Once you have access, it can talk to ofa --serve as one of
its providers so the whole ofa mode family shows up in its model picker
alongside the built-in serveai and local-ollama providers.
One-time setup. Create ~/.config/opencode/opencode.json with an ofa
provider block whose baseURL / apiKey reference {env:OFA_BYOK_URL} and
{env:OFA_BYOK_TOKEN}, listing the eight ofa modes as separate models. The
{env:…} substitution happens at opencode startup, so the file never has to
be re-edited when the allocation, port, or token changes. The opencode
maintainers can share a template.
Per-allocation flow.
# 1) Load ofa and start its server. This writes the auto-picked port and
# bearer token to $OFA_SCRATCH/.ofa_serve_port and $OFA_SCRATCH/.ofa_api_key.
module load assistant
ofa --serve --serve-quiet --serve-enable-tools &
# Wait until "[ofa-serve] Ctrl+C to stop." appears, then press Enter to get
# the shell prompt back. The server keeps running under job control (&).
# 2) Load opencode. Loading it does NOT overwrite your opencode.json.
module load opencode
# 3) Wire ofa's live endpoint into the environment. opencode.json substitutes
# {env:OFA_BYOK_URL} / {env:OFA_BYOK_TOKEN} at startup, so ofa is picked up
# dynamically each allocation without editing any config file.
OFA_SCRATCH="${OFA_SCRATCH:-/scratch/$USER}"
export OFA_BYOK_URL="http://localhost:$(cat $OFA_SCRATCH/.ofa_serve_port)/v1"
export OFA_BYOK_TOKEN=$(cat $OFA_SCRATCH/.ofa_api_key)
# 4) Optional — also drop ./opencode.json in the current directory so its
# built-in serveai + local-ollama providers show up alongside ofa in the
# model picker for this workdir. Skip this if you only want ofa.
_write_opencode_json
# 5) Launch. The model picker lists "OnField Assistant 🌵" with 8 modes.
opencode
--serve-quiet matters here because ofa’s --serve stderr shares the
terminal with opencode’s TUI — without it every request prints a
[ofa-serve] <model> (<mode>): N msg(s)... line into the foreground.
--serve-enable-tools lets opencode chain file edits and shell commands
through ofa’s tool-calling passthrough instead of one-shot Q&A.
Use ofa from AMReX Agent¶
AMReX Agent is AMReX’s
LangGraph-based coding agent. Its litellm LLM provider talks to any
OpenAI-compatible endpoint (Ollama, vLLM, a LiteLLM proxy, LM Studio, or
an HPC BYOK server like ofa) — see
PR #59 /
docs/api_keys.md in that repo for the general recipe. Pointed at ofa:
module load assistant
ofa --serve --serve-enable-tools
export LITELLM_BASE_URL="http://localhost:$(cat $OFA_SCRATCH/.ofa_serve_port)/v1"
export LITELLM_API_KEY="$(cat $OFA_SCRATCH/.ofa_api_key)"
export LITELLM_MODEL="ofa-code"
unset CBORG_API_KEY # unset whichever other provider key would otherwise take priority
# ~/.amrex_agent/kestrel-ofa.yaml
llm_provider: litellm
llm_model: ofa-code
embedding_provider: huggingface # ofa's /v1 endpoint doesn't serve /v1/embeddings
python amrex_agent.py --prompt "..." --config ~/.amrex_agent/kestrel-ofa.yaml
llm_model accepts any of the eight ofa-* mode IDs — ofa-code,
ofa-hpc, ofa-amrex, ofa-marbles, ofa-openfoam, ofa-reframe,
ofa-quantum-computing, ofa-vasp — pick whichever matches the task.
Programmatic use from Python (ofa_client)¶
Call ofa from your own simulation / diagnostic scripts. The client is
a single stdlib-only Python file that talks to a running ofa --serve
over HTTP — no third-party packages, works in any Python 3.8+
interpreter (bare, venv, conda, spack, container).
One-time setup¶
module load assistant # puts ofa_client on PYTHONPATH
ofa --serve > ofa-serve.log 2>&1 & # start the local server (in your allocation)
trap 'kill %1 2>/dev/null' EXIT # optional: clean up on shell exit
The server writes its bearer token to $OFA_SCRATCH/.ofa_api_key and
its port to $OFA_SCRATCH/.ofa_serve_port. The client reads both
automatically — no URL/token wiring in your script.
ask() — one-shot, stateless¶
Best fit for sim loops where each call is independent (e.g., summarise plot N without any memory of plot N-1).
from ofa_client import ask
# 1. Plain text
text = ask("what is a good turbulence model for cavity flow at Re=1e4?")
# 2. Text plus inline context string
text = ask(
"diagnose this run",
context="Simulation: cavity flow, Re=1000. Diverged at step 4200.",
)
# 3. Text plus a file (tail-reads last 32 KB by default; full_file=True to override)
text = ask("why is this crashing?", file="output/solver.log")
# 4. Text plus an image (Gemma 4's vision head handles it in any mode)
text = ask("describe this plot", image="output/step_0100_pressure.png")
# 5. Everything at once, and pick a specific mode
text = ask(
"diagnose this simulation step",
image="output/step_4200_pressure.png",
file="output/solver.log",
context="Re=1000, cavity flow, k-omega SST turbulence model.",
model="ofa-code", # ofa-openfoam | ofa-hpc | ofa-code | ofa-amrex | ofa-marbles | ofa-reframe | ofa-quantum-computing | ofa-vasp
timeout=60,
)
Full signature:
ask(
prompt: str, # main question (required)
*,
image: str | Path = None, # attach one image (any PIL-readable format)
images: list = None, # attach several
context: str = None, # inline text prepended verbatim
file: str | Path = None, # read one file, fence with its name
files: list = None, # read several
model: str = "ofa-code", # any of the eight ofa-* modes
url: str = None, # override auto-detection
token: str = None, # override auto-detection
timeout: float = 120.0,
full_file: bool = False, # True disables the 32 KB tail-cap
) -> str
Session() — multi-turn, client-side history¶
Use when later turns need the model to remember earlier turns
(interactive code review, iterative parameter refinement,
conversational drill-down). Session accumulates the message list
locally and sends the whole thing on each .ask(), so state survives
server restarts and adds zero memory footprint on the server.
from ofa_client import Session
sess = Session(model="ofa-code", timeout=120)
# Turn 1: attach an image and context; model critiques.
sess.ask(
"look at this fit; is it good?",
image="fit_before.png",
context="model: y = A * exp(-b*x) * cos(omega*x + phi); RMS=0.85",
)
# Turn 2: no need to re-attach the image — it's in the history.
sess.ask(
"based on your critique, propose better initial guesses as JSON: "
'{"p0": [A, b, omega, phi], "maxfev": <int>, "notes": "..."}'
)
print(sess) # Session(model='ofa-code', turns=2)
sess.clear() # forget everything and start fresh
Session.ask() accepts the same kwargs as ask() except model,
url, token, timeout, full_file (those are fixed at
construction).
Parsing structured output from the LLM¶
A reliable pattern for getting parseable numbers back: ask for a fenced JSON code block with an explicit schema, then extract-and-parse with a fallback ladder. LLMs handle “return this JSON schema” much better than “return only a number”.
import json, re
def extract_json(text):
for pat in (r"```json\s*(\{.*?\})\s*```", r"```\s*(\{.*?\})\s*```"):
m = re.search(pat, text, re.DOTALL | re.IGNORECASE)
if m:
try: return json.loads(m.group(1))
except json.JSONDecodeError: pass
for m in re.finditer(r"\{.*?\}", text, re.DOTALL):
try: return json.loads(m.group(0))
except json.JSONDecodeError: continue
return None
See examples/fit_and_ask.py for a worked
end-to-end example: fits a noisy damped sinusoid + harmonic (a function
where scipy.optimize.curve_fit genuinely gets trapped in a local
minimum from a bad initial guess), sends the plot + fit summary to
ofa inside a Session, asks for a prose critique on turn 1 and a
strict-JSON refit suggestion on turn 2, extracts the JSON with the
fallback ladder above, and reruns the fit. A typical successful run
prints:
RMS: 0.5370 -> 0.11xx (IMPROVED, delta -0.42)
Run it in-place:
module load assistant
ofa --serve > /tmp/ofa-serve.log 2>&1 &
cd $OFA_ROOT/examples && python3 fit_and_ask.py
Auto-detection order¶
The client resolves url and token by falling through:
Explicit
url=/token=kwargs.$OFA_BYOK_URLand$OFA_BYOK_TOKENenvironment variables.$OFA_SCRATCH/.ofa_serve_portand$OFA_SCRATCH/.ofa_api_key./scratch/$USER/.ofa_serve_portand/scratch/$USER/.ofa_api_key.Raise
RuntimeErrorwith a clear “no ofa server detected” hint.
Before each request the client also probes /healthz with a 3-second
cap so a dead server (killed allocation, stale port file) surfaces as
an immediate, actionable error — not a two-minute hang.
Robust wrapping in a sim¶
A slow model, expired allocation, or dropped connection should skip the AI call, not crash your sim:
try:
summary = ask(f"summarise pressure field at step {step}",
image=fname, timeout=60)
with open("output/ai_summary.log", "a") as f:
f.write(f"[step {step}] {summary}\n")
except Exception as e:
print(f"[ai summary skipped: {e}]")
Where to go next¶
Full BYOK + VS Code walkthrough:
docs/byok-vscode.md.Deeper explanation of how
ofa --servelayers RAG, memory, and system prompts on top of Ollama:docs/ofa-technical-overview.md§5.3.Reference implementation:
src/ofa_client.pyis ~390 LOC, stdlib only, and the entire public surface is documented inline.