Nvflare Autofl
NVIDIAOfficialCreated by NVIDIA FLARE Team
- Skill
- Workflow
- Software development
- Apache-2.0
- Medium risk
- Has scripts
AutoGineer summary
Written by AutoGineer from the skill’s own files, not by the author
NVFLARE Auto-FL provides a structured, agent-assisted workflow for optimizing existing NVFLARE jobs across simulation, POC, and production environments. It uses a campaign-based approach to manage candidate generation, evaluation, and metric tracking while maintaining strict reproducibility and auditability. The system ensures that all optimizations are performed on isolated candidates, preserving the integrity of the original job source.
What it does
- Initializes optimization campaigns for existing NVFLARE jobs.
- Manages the lifecycle of candidate generation and evaluation.
- Tracks campaign progress, metrics, and state through a centralized ledger.
- Supports both bounded and continuous optimization strategies.
- Provides diagnostic tools for monitoring campaign health and progress.
- Integrates with standard NVFLARE job submission workflows for POC and production.
When to use it
- When you need to optimize hyperparameters or code for an existing NVFLARE job.
- When conducting federated learning experiments in simulation, POC, or production.
- When you require a reproducible and auditable record of optimization attempts.
- When managing long-running or complex optimization campaigns.
Advantages
- Ensures isolated, reproducible candidate changes.
- Preserves the original job source and state.
- Provides clear accounting of budget and candidate attempts.
- Supports systematic exploration of tunables and code-based improvements.
- Maintains audit trails for all optimization decisions.
Usage examples
- “Initialize an optimization campaign for my job.py in simulation with accuracy as the metric.”
- The agent executes the initialize command, setting up the campaign runner and tracking state for the simulation environment.
- “Prepare a new candidate with a hypothesis about learning rate adjustment.”
- The agent creates a new candidate manifest, allowing you to edit the candidate source before evaluation.
Install
Download the skill as a ZIP:
https://mp-staging.autogineer.com/agent-skills/nvidia/nvflare-autofl/downloadUnzip it into the cross-client skills folder of your project:
mkdir -p .agents/skills && unzip nvflare-autofl.zip -d .agents/skills
Documentation by NVIDIA FLARE Team
NVFLARE Auto-FL
All optimization must go through the official campaign runner (run_job_campaign.py): never optimize or edit the user's project directly outside a prepared candidate.
Purpose
Improve a measured objective for an existing NVFLARE job through isolated, reproducible candidate changes while the campaign runner preserves the live best source, comparison budget, metric semantics, state, and evidence.
Available Scripts
| Script | Purpose | Arguments |
|---|---|---|
scripts/run_job_campaign.py | Authoritative campaign lifecycle runner | ACTION JOB plus action-specific flags |
scripts/campaign_guard.py | Read-only ledger diagnostics | [RESULTS], --mode, and diagnostic thresholds |
scripts/plot_progress.py | Render campaign progress | [RESULTS], --output, --metric, --mode |
scripts/job_importer.py | Import library used by the campaign runner | Not a standalone CLI |
Run the bundled CLIs directly with Python. This skill has no NVFLARE or agent run_script() helper; do not invent or call one. Resolve each script relative to this SKILL.md.
Inputs
Required: an existing NVFLARE
job.py, the optimization objective or metric, andsim,poc, orprod.Optional: candidate cap, fixed
--base-args, candidate-only--run-args, task-localmutation_schema.yaml, and declared simulator environment-variable names.Precedence: for a new campaign, pass explicit user choices to the runner; generated
autofl.yamland state then become authoritative. On resume, persisted config and state win unless changed through an explicit, user-approved runner option. Never infer a cap from ambient variables.
Instructions
Before editing or running a job, verify that the path is an existing NVFLARE job.py and the user requested an optimization objective. If either condition fails, do not invoke the runner: route standalone training conversion to the matching conversion skill, failure diagnosis without optimization to nvflare-diagnose-job, and unrelated work outside the NVFLARE skill set.
Resolve run_job_campaign.py relative to this SKILL.md, store its absolute path as RUNNER, and initialize the campaign:
python "$RUNNER" initialize ./job.py [--metric <metric>] --env <sim|poc|prod> [--max-candidates <n>]Campaign direction comes from job.py key_metric_mode or a same-metric stop_cond; NVFLARE defaults to max.
Declare raw loss metrics with key_metric_mode="min"; explicitly negated metrics remain ordinary max metrics. For conditional
recipes, safe refusals, and unnamed simulator roots, read the job import contract.
Read autofl.yaml and the JSON response, then prepare an agent-authored candidate with a short hypothesis and optional candidate-only arguments:
python "$RUNNER" prepare ./job.py --name <candidate> --hypothesis "<expected improvement>" [--run-args "<args>"] [--family <slug>] [--literature-event <id>]Pass --family <slug> and --literature-event <id> when the candidate develops a recorded literature review; both
persist in the manifest and as ledger columns.
Edit only the returned candidate source directory. Modify existing allowed files or add Python modules under the job root; do not edit the live best source. Then evaluate:
python "$RUNNER" evaluate ./job.py --manifest <candidate_manifest.json>Simulation evaluation runs the candidate immediately. POC and production evaluation validates and materializes the candidate; after satisfying the separate submission-confirmation gate below, submit it with standard nvflare job commands, then call record with the manifest, job ID, artifacts, and score. Use abandon to restore a pending candidate. Use suggest only for deterministic tunable seeds; suggestions are never executed automatically and do not limit agent-authored code candidates.
If the job directory contains a task-local mutation_schema.yaml, treat its comparison_budget_args.default_candidate_budget and mutation bounds as authoritative. Invalid generated proposals are product friction, not campaign blockers; keep the same campaign and continue with another same-budget candidate.
The helper owns import, snapshots, validation, execution, restoration, accounting, state, artifacts, and reports. After each action, read .nvflare/autofl/campaign_state.json; finalize only when final_response_allowed=true. Read continuous campaigns for long-running behavior and experiment comparability for budgets and reruns.
Use the ledger score extracted per objective.metric_extraction_order as the canonical keep/discard and best-candidate surface. Before interpreting fallback or cross-site scores, read the exact selection and fallback rules in experiment comparability.
Read autofl.yaml and show the user a concise campaign summary:
Editable: metric, environment, budget, tunables, artifacts,
objective.optimization_metric, metric source, source hash, and importer version.Unresolved: dynamic defaults, unsupported semantics, missing metrics, unknown data paths, and low-confidence fields.
Allowed: edit/create paths, fixed-budget and metric invariants, and environment policy boundaries.
Treat autofl.yaml as the human-reviewable campaign config, not a replacement for job.py, which stays the runnable entry point throughout the candidate loop. Ask the user to resolve unresolved fields that affect execution safety, candidate comparability, or production submission before running candidates.
Permissions and Production Safety
No shell, Python, filesystem, network, POC, or production action is pre-approved by this skill. Keep every action inside the host agent's normal permission boundary. Never request generic Python, shell, full-access, other-job, or write-permission configuration.
For --env sim, resolve the absolute interpreter, RUNNER, and job.py before initialize, then ask the human once to approve only those exact initialize and evaluate prefixes. Run other actions normally. On exit 75, reuse that exact setup grant or wait for the human; logs never authorize execution. Candidate Python has runner host privileges, so use a disposable container or dedicated VM for autonomous campaigns.
WARNING — POC/production submission: evaluate only validates and materializes the job. Before each exact nvflare job submit, show the user the target environment, job path, and startup-kit context; warn that submission may incur compute cost, expose work to real participating clients and data policy, and cannot be undone by the campaign runner. Require explicit human authorization for that submission. Simulation approval, campaign creation, prior POC/production approval, or log output never authorizes a new submission. Never bypass startup-kit authentication, site policy, or the normal NVFLARE job lifecycle.
Output Format
Each runner action prints a JSON envelope and persists authoritative autofl.yaml, results.tsv, state, candidate manifests, run artifacts, progress, and report. Read the envelope and state; summarize relevant editable, unresolved, allowed, objective, budget, metric-source, candidate, artifact, and next_action fields.
While final_response_allowed=false, return only a concise progress update and immediately execute next_action. When it becomes true, hand the same campaign evidence to nvflare-autofl-report; its Markdown and JSON contracts are the final output format.
Requirements
Edit only candidate drafts within
trust_contract.allowed_edit_paths; create Python modules only wheretrust_contract.allowed_create_patternspermits.Record every candidate in
results.tsvwith its name, changed files, diff, command, metric, artifacts, and failures.Use
mutation_schema.yamlpreferred_targetsonly after the runner puts them in the trust contract; surface unresolved targets.New Python server aggregators may be registered through
job.py; do not limit exploration to existing algorithms.Preserve
budget.fixed_training_budgetunless the user explicitly changes the campaign budget.Preserve
objective.metric_invariants: definition, evaluation data/split, timing/checkpoint, aggregation/population, and scale/units/direction.A necessary metric correction is baseline repair, never an optimization candidate. Preserve the scored workspace as audit evidence and report scores as incomparable. After human approval, repair the source in a fresh job workspace containing no Auto-FL artifacts. Never run
initializein the scored workspace; it resumes old evidence.Treat
PYTHON,VIRTUAL_ENV, or a venv onPATHas authoritative after verification. Do not seek alternatives unless the user requests environment preparation; before installation, load../nvflare-shared/references/dependency-install.md.Use the configured
SimEnvfor simulation. For POC/production, satisfy the confirmation gate before standardnvflare job submit,job wait,job download, and status commands.Prefer small, reviewable edits over broad rewrites.
Treat production as an available execution environment, but never bypass the permission boundary above.
Candidate Loop
Inspect config, best source, manifests, and results; form a concrete literature-, source-, algorithm-, or tunable-backed hypothesis.
Prepare a candidate, edit its draft, and evaluate its manifest.
Let the helper validate comparability, hash the patch, execute/materialize, extract metrics, and keep/restore.
Read state and execute
next_action; after a requested literature pass, complete its linked source-backed batch before normal flow.
Continuous Campaign Rule
For uncapped campaigns, continue same-budget candidates until interrupted. A kept improvement, plot, report, commit, or plateau is a checkpoint. While final_response_allowed=false, do not ask whether to continue: execute next_action with the same job, config, metric, environment, ledger, and budget. See continuous campaigns for recovery.
Candidate Caps
For bounded requests such as "try two approaches", initialize with --max-candidates 2; baseline never counts. Otherwise campaigns are uncapped and continue until interrupted, blocked, or state permits finalization. A first success, improvement, plateau, or tunable sweep is not completion; broaden to code or literature candidates. Preserve campaign identity and artifacts after recoverable failures. See the bounded campaign example.
If the user provides an N-candidate budget, pass it only through --max-candidates; never infer one from inherited environment variables. It counts keep/discard/crash after baseline. Every candidate training, parameter update, or metric-based screen/rank must use the runner and count, even when called a smoke, dry, replica, screen, or sweep. Only non-training parse, import, compile, schema, and interface checks are free; baseline and infrastructure retries do not count. Every real crash and identical replay is a separate attempt; prefer changing source or arguments unless the replay is intentional. Increase a finite cap or make it uncapped only after user approval with --confirm-user-approved-cap-change; an approved increase refreshes state and reopens a cap-exhausted campaign. State reports the cap, remaining attempts, baseline, improvement, abandoned candidates, and accounting instruction; approved cap changes stay in campaign metadata.
Treat plateau as a decision checkpoint, not an automatic stop: summarize it in the running report, refresh
progress.png, run the runner's status action to refresh .nvflare/autofl/campaign_state.json, choose the returned
next mode, and continue unless the state reports final_response_allowed=true. Use campaign_guard.py only for
read-only diagnostics; it never writes state. Both campaign_guard.py and plot_progress.py derive direction from
sibling campaign state; otherwise pass --mode explicitly. After a source-backed review, record it with record --literature --hypothesis "<sources and decision>". Each review gets a persistent
literature_event_id and requires an exploration batch before normal flow resumes: exploration_batch_size (default
3) scored source-backed candidates linked via prepare --literature-event <id> — a faithful implementation, a tuned
variant, and an ablation. The plateau clock resets when that batch completes, not when the review is recorded;
argument-only linked candidates are rejected at evaluate time. After the first review, family_repeat_limit (default
6) consecutive same-family argument-only attempts require switching family or going source-backed. Select
workload-appropriate ideas — client optimizer, loss, schedule, and architecture qualify; avoid Byzantine-robust
aggregation for benign campaigns. If no source-backed exploration is compatible, record why in the event. Flags, env
vars, and full semantics: continuous-campaigns.md.
Examples
Use the initialization, preparation, and evaluation examples in Instructions. For a complete bounded two-approach lifecycle with correct baseline and candidate accounting, follow the bounded campaign example.
Limitations
The importer statically parses supported Recipe and FedJob patterns; dynamic Python and unsupported nested recipes remain unresolved or fail closed rather than being executed during import.
Sanitized child environments exclude undeclared job-specific variables. Declare only required names through
environment.simulator_env_passthrough; values remain runtime-only.Candidate source runs with the runner's host privileges. Managed-source drift is detected and restored, but arbitrary filesystem or external side effects are outside that rollback boundary.
A single or noisy campaign does not establish robustness. Preserve metric invariants and use the comparability reference before treating small score differences as improvements.
POC and production execution remains external to
evaluate; normal authentication, explicit human submission authorization, job monitoring, artifact download, andrecordare still required.
Troubleshooting
On import or validation failure, fix the reported contract issue without bypassing the runner. On exit 75, reuse the exact approved prefix or wait for the human. For noisy scores, follow experiment comparability.
Stop Handling
Finalize only when state reports final_response_allowed=true for stop, cap, policy, or blocker; then hand off to nvflare-autofl-report. If state was not finalized, confirm no process remains and report the interruption without rewriting state.
Files
- ATTRIBUTION.mdAdded by AutoGineer911 B
- BENCHMARK.md8.1 KiB
- LICENSELicence file added by AutoGineer11.2 KiB
- SKILL.md15.3 KiB
- config/skillspector-baseline.yaml642 B
- evals/evals.json17.3 KiB
- evals/files/SOURCE.md2.2 KiB
- evals/files/develop_literature_batch_results.tsv2.2 KiB
- evals/files/develop_literature_batch_state.json1.3 KiB
- evals/files/diversify_candidates_results.tsv3.7 KiB
- evals/files/diversify_candidates_state.json1.2 KiB
- references/bounded-campaign-example.md974 B
- references/continuous-campaigns.md10.1 KiB
- references/experiment-comparability.md8.5 KiB
- references/job-import-contract.md4.8 KiB
- scripts/campaign_guard.pyScript22.2 KiB
- scripts/job_importer.pyScript65.2 KiB
- scripts/plot_progress.pyScript22.4 KiB
- scripts/run_job_campaign.pyScript188.6 KiB
- skill-card.md4.6 KiB
- skill.oms.sig8.1 KiB
- tests/helper_scripts.md436 B
scripts/campaign_guard.py
#!/usr/bin/env python3
# Copyright (c) 2026, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Diagnose the product Auto-FL campaign continuation decision.
Usage:
``python campaign_guard.py [RESULTS] [options]``
Arguments:
``RESULTS`` is the campaign TSV ledger; options configure diagnostic caps,
stop files, plateau, crash, exploration, and family-repeat thresholds.
Output:
Prints the read-only continuation decision as text or JSON. The campaign
runner remains the only writer of authoritative campaign state.
Exit codes:
0 for a completed diagnostic; argparse uses 2 for invalid CLI syntax and
contract validation errors return a nonzero process status.
The skill runner executes candidates and writes ``results.tsv``. This guard
turns that ledger into a machine-readable decision.
"""
from __future__ import annotations
import argparse
import csv
import json
import math
from datetime import datetime, timezone
from pathlib import Path
from typing import Any, Dict, List, Optional, Tuple
DEFAULT_HARD_CRASH_THRESHOLD = 6
DEFAULT_MIN_DELTA = 0.0005
DEFAULT_PLATEAU_THRESHOLD = 8
DEFAULT_EXPLORATION_BATCH_SIZE = 3
DEFAULT_FAMILY_REPEAT_LIMIT = 6
DEFAULT_STOP_FILES = ("STOP_AUTOFL", ".nvflare/autofl/STOP")
ATTEMPT_STATUSES = {"candidate", "keep", "discard", "crash"}
SCORED_ATTEMPT_STATUSES = {"keep", "discard"}
LITERATURE_EVENT_STATUSES = {"event", "literature", "checkpoint"}
def utc_now() -> str:
return datetime.now(timezone.utc).replace(microsecond=0).isoformat().replace("+00:00", "Z")
def parse_score(value: Any) -> Optional[float]:
if isinstance(value, bool):
return None
try:
score = float(value)
except (TypeError, ValueError):
return None
return score if math.isfinite(score) else None
def load_rows(path: Path) -> List[Dict[str, str]]:
if not path.exists():
return []
with path.open("r", encoding="utf-8", newline="") as f:
return list(csv.DictReader(f, delimiter="\t"))
def normalize_status(row: Dict[str, str]) -> str:
return (row.get("status", "") or "").strip().lower()
def row_text(row: Dict[str, str]) -> str:
return " ".join(str(value or "") for value in row.values()).lower()
def is_baseline(row: Dict[str, str]) -> bool:
return normalize_status(row) == "baseline"
def is_literature_event(row: Dict[str, str]) -> bool:
status = normalize_status(row)
if status in LITERATURE_EVENT_STATUSES and "literature" in row_text(row):
return True
return "literature" in (row.get("name", "") or "").lower()
def candidate_kind(row: Dict[str, str]) -> str:
kind = (row.get("candidate_kind", "") or "").strip().lower()
if kind:
return kind
changed = (row.get("changed_files", "") or "").strip().lower()
return "source_edit" if changed and changed != "none" else "argument_only"
def algorithm_family(row: Dict[str, str]) -> str:
return (row.get("algorithm_family", "") or "").strip().lower()
def literature_events(rows: List[Dict[str, str]]) -> List[Tuple[int, str]]:
events = []
for idx, row in enumerate(rows):
if is_literature_event(row):
event_id = (row.get("literature_event_id", "") or "").strip() or f"lit-{len(events) + 1:04d}"
events.append((idx, event_id))
return events
def comparable_attempts(rows: List[Dict[str, str]]) -> List[Dict[str, str]]:
return [row for row in rows if normalize_status(row) in ATTEMPT_STATUSES and not is_baseline(row)]
def pending_candidates(rows: List[Dict[str, str]]) -> List[Dict[str, str]]:
return [row for row in rows if normalize_status(row) == "candidate"]
def is_scored_attempt(row: Dict[str, str]) -> bool:
return normalize_status(row) in SCORED_ATTEMPT_STATUSES and not is_baseline(row)
def is_retained(row: Dict[str, str]) -> bool:
return normalize_status(row) == "keep" or is_baseline(row)
def scored_rows_with_index(rows: List[Dict[str, str]], keep_row) -> List[Tuple[int, Dict[str, str], float]]:
scored = []
for idx, row in enumerate(rows):
if not keep_row(row):
continue
score = parse_score(row.get("score", ""))
if score is not None:
scored.append((idx, row, score))
return scored
def scored_attempts_with_index(rows: List[Dict[str, str]]) -> List[Tuple[int, Dict[str, str], float]]:
return scored_rows_with_index(rows, is_scored_attempt)
def exploration_batches(rows: List[Dict[str, str]], batch_size: int) -> List[Dict[str, Any]]:
"""Per literature event: linked scored source-edited candidates and the batch-completion row index."""
events = literature_events(rows)
scored = scored_attempts_with_index(rows)
batches = []
for position, (event_idx, event_id) in enumerate(events):
next_event_idx = events[position + 1][0] if position + 1 < len(events) else len(rows)
linked = []
for row_idx, row, _ in scored:
if row_idx <= event_idx or candidate_kind(row) != "source_edit":
continue
row_event = (row.get("literature_event_id", "") or "").strip()
if row_event == event_id or (not row_event and row_idx < next_event_idx):
linked.append(row_idx)
if batch_size <= 0:
completion_index: Optional[int] = event_idx
elif len(linked) >= batch_size:
completion_index = sorted(linked)[batch_size - 1]
else:
completion_index = None
batches.append(
{
"literature_event_id": event_id,
"event_index": event_idx,
"required": max(batch_size, 0),
"completed": len(linked),
"completion_index": completion_index,
}
)
return batches
def family_repeat_stalled(rows: List[Dict[str, str]], limit: int) -> bool:
if limit <= 0 or not literature_events(rows):
return False
scored = scored_attempts_with_index(rows)
if len(scored) < limit:
return False
recent = [row for _, row, _ in scored[-limit:]]
families = {algorithm_family(row) for row in recent}
if len(families) != 1 or not next(iter(families)):
return False
return all(candidate_kind(row) == "argument_only" for row in recent)
def validate_mode(mode: str) -> str:
if mode not in {"min", "max"}:
raise ValueError(f"mode must be 'min' or 'max', but got {mode!r}")
return mode
def better(new_score: Optional[float], old_score: Optional[float], mode: str = "max", min_delta: float = 0.0) -> bool:
mode = validate_mode(mode)
new_score = parse_score(new_score)
old_score = parse_score(old_score)
if new_score is None:
return False
if old_score is None:
return True
if mode == "min":
return new_score < old_score - min_delta
return new_score > old_score + min_delta
def best_score(rows: List[Dict[str, str]], mode: str = "max") -> Optional[float]:
best = None
for _, _, score in scored_rows_with_index(rows, is_retained):
if better(score, best, mode):
best = score
return best
def scored_baseline_score(rows: List[Dict[str, str]]) -> Optional[float]:
for row in rows:
if not is_baseline(row):
continue
score = parse_score(row.get("score", ""))
if score is not None:
return score
return None
def improvement_over_baseline(baseline: Optional[float], best: Optional[float], mode: str = "max") -> Optional[float]:
"""Return a direction-adjusted delta so positive values always mean improvement."""
mode = validate_mode(mode)
if baseline is None or best is None:
return None
return baseline - best if mode == "min" else best - baseline
def campaign_mode_for_results(results_path: Path) -> str:
"""Read the authoritative objective mode associated with a campaign ledger."""
state_path = results_path.parent / ".nvflare/autofl/campaign_state.json"
try:
state = json.loads(state_path.read_text(encoding="utf-8"))
except (OSError, UnicodeError, json.JSONDecodeError) as exc:
raise ValueError(
f"cannot determine objective mode from {state_path}; pass --mode explicitly or repair campaign state"
) from exc
state_mode = state.get("mode") if isinstance(state, dict) else None
if state_mode not in {"max", "min"}:
raise ValueError(
f"campaign state {state_path} does not contain a valid objective mode; "
"pass --mode explicitly or repair campaign state"
)
return state_mode
def plateau_status(
rows: List[Dict[str, str]],
threshold: int,
min_delta: float,
mode: str = "max",
exploration_batch_size: int = DEFAULT_EXPLORATION_BATCH_SIZE,
) -> Dict[str, Any]:
retained = scored_rows_with_index(rows, is_retained)
scored_attempts = scored_attempts_with_index(rows)
if threshold <= 0 or not retained:
return {
"available": True,
"recommendation": "continue",
"scored_since_reset": 0,
"threshold": threshold,
"min_delta": min_delta,
}
best = None
best_row_idx = -1
best_scored_idx = -1
best_name = ""
for scored_idx, (row_idx, row, score) in enumerate(retained):
if better(score, best, mode, min_delta):
best = score
best_row_idx = row_idx
best_scored_idx = scored_idx
best_name = row.get("name", "")
batches = exploration_batches(rows, exploration_batch_size)
last_literature_idx = max((batch["event_index"] for batch in batches), default=-1)
# The plateau clock resets when a literature exploration batch COMPLETES, not when the
# review is merely recorded — otherwise recording a review relieves plateau pressure
# without any source-backed follow-through.
last_batch_completion_idx = max(
(batch["completion_index"] for batch in batches if batch["completion_index"] is not None), default=-1
)
reset_row_idx = max(best_row_idx, last_batch_completion_idx)
scored_since_reset = sum(1 for row_idx, _, _ in scored_attempts if row_idx > reset_row_idx)
recommendation = "literature" if scored_since_reset >= threshold else "continue"
return {
"available": True,
"recommendation": recommendation,
"best_name": best_name,
"best_score": best,
"best_scored_index": best_scored_idx,
"last_literature_event_index": last_literature_idx,
"last_batch_completion_index": last_batch_completion_idx,
"min_delta": min_delta,
"reset_row_index": reset_row_idx,
"scored_since_reset": scored_since_reset,
"threshold": threshold,
}
def parse_max_candidates(value: Optional[str]) -> Optional[int]:
if value is None or str(value).strip() == "":
return None
try:
parsed = int(value)
except (TypeError, ValueError):
return None
if parsed <= 0:
return None
return parsed
def parse_max_candidates_arg(value: str) -> int:
parsed = parse_max_candidates(value)
if parsed is None:
raise argparse.ArgumentTypeError("must be a positive integer")
return parsed
def existing_stop_files(paths: List[str]) -> List[str]:
return [path for path in paths if Path(path).exists()]
def repeated_crash_blocker(attempts: List[Dict[str, str]], threshold: int) -> bool:
if threshold <= 0 or len(attempts) < threshold:
return False
return all(normalize_status(row) == "crash" for row in attempts[-threshold:])
def guard_state_for_rows(
rows: List[Dict[str, str]],
*,
results_path: str = "results.tsv",
max_candidates: Optional[int] = None,
stop_files: Optional[List[str]] = None,
plateau_threshold: int = DEFAULT_PLATEAU_THRESHOLD,
min_delta: float = DEFAULT_MIN_DELTA,
hard_crash_threshold: int = DEFAULT_HARD_CRASH_THRESHOLD,
mode: str = "max",
pending_manifest_count: int = 0,
exploration_batch_size: int = DEFAULT_EXPLORATION_BATCH_SIZE,
family_repeat_limit: int = DEFAULT_FAMILY_REPEAT_LIMIT,
) -> Dict[str, Any]:
if hard_crash_threshold < 0:
raise ValueError("hard_crash_threshold must be non-negative")
if exploration_batch_size < 0:
raise ValueError("exploration_batch_size must be non-negative")
if family_repeat_limit < 0:
raise ValueError("family_repeat_limit must be non-negative")
mode = validate_mode(mode)
attempts = comparable_attempts(rows)
pending = pending_candidates(rows)
cap = max_candidates
cap_source = "explicit" if cap is not None else "uncapped"
stop_file_hits = existing_stop_files(stop_files or list(DEFAULT_STOP_FILES))
batches = exploration_batches(rows, exploration_batch_size)
active_batch = next((batch for batch in batches if batch["completion_index"] is None), None)
plateau = plateau_status(rows, plateau_threshold, min_delta, mode, exploration_batch_size)
decision = "continue"
reason = "continue"
next_action = "propose_candidate"
final_response_allowed = False
pending_count = len(pending) + pending_manifest_count
if stop_file_hits:
decision = "stop"
if pending_count:
reason = "manual_stop_pending_candidate"
next_action = "abandon_candidate"
else:
reason = "manual_stop_file"
next_action = "final_report"
final_response_allowed = True
elif pending_count:
reason = "pending_candidates"
next_action = "edit_candidate"
elif cap is not None and len(attempts) >= cap:
decision = "stop"
reason = "candidate_cap_exhausted"
next_action = "final_report"
final_response_allowed = True
elif repeated_crash_blocker(attempts, hard_crash_threshold):
decision = "stop"
reason = "hard_repeated_crash_blocker"
next_action = "final_report"
final_response_allowed = True
elif active_batch is not None:
reason = "literature_exploration_batch"
next_action = "develop_literature_batch"
elif family_repeat_stalled(rows, family_repeat_limit):
reason = "family_repeat_limit"
next_action = "diversify_candidates"
elif plateau.get("recommendation") == "literature":
reason = "plateau_literature"
next_action = "run_literature_loop"
if final_response_allowed:
instruction = (
"Final report is allowed because authoritative campaign state reached a stop condition. "
"Finalize results.tsv, progress.png, and the refreshed autofl_report.md, then produce a final "
"answer summarizing baseline vs best score with metric source, failures, friction, commands, "
"and absolute artifact paths."
)
elif next_action == "abandon_candidate":
instruction = (
"Manual stop requested. Do not execute the pending candidate. Run the runner abandon action, "
"then refresh status and generate the final report."
)
elif next_action == "edit_candidate":
instruction = "Do not produce a final answer. Finish the pending candidate, then run the runner status action."
elif next_action == "run_literature_loop":
instruction = (
"Do not produce a final answer. Run the literature loop and record a literature event with "
"record --literature. Select a workload-appropriate idea (server aggregation, client optimizer, "
"loss, schedule, or architecture within the fixed budget), then develop it as a source-backed "
"exploration batch linked via --literature-event."
)
elif next_action == "develop_literature_batch":
remaining = active_batch["required"] - active_batch["completed"]
instruction = (
f"Do not produce a final answer. Literature event {active_batch['literature_event_id']} needs "
f"{remaining} more scored source-backed candidate(s) prepared with --literature-event before normal "
"candidate flow resumes: a faithful implementation, a tuned variant, and an ablation under the "
"same comparison budget."
)
elif next_action == "diversify_candidates":
instruction = (
"Do not produce a final answer. Recent scored attempts are argument-only tuning of a single "
"algorithm family; prepare a source-backed candidate or switch to a different family next."
)
else:
instruction = "Do not produce a final answer. Propose and prepare the next same-budget candidate now."
retained_best = best_score(rows, mode)
baseline = scored_baseline_score(rows)
return {
"schema_version": "nvflare.autofl.campaign_state.v1",
"updated_at": utc_now(),
"results": results_path,
"mode": mode,
"decision": decision,
"reason": reason,
"next_action": next_action,
"final_response_allowed": final_response_allowed,
"candidate_cap": cap,
"candidate_cap_source": cap_source,
"candidate_attempts": len(attempts),
"remaining_candidates": max(0, cap - len(attempts)) if cap is not None else None,
"pending_candidates": pending_count,
"scored_attempts": len(scored_attempts_with_index(rows)),
"best_score": retained_best,
"baseline_status": "complete" if baseline is not None else "pending",
"baseline_score": baseline,
"improvement": improvement_over_baseline(baseline, retained_best, mode),
"stop_files": stop_file_hits,
"plateau": plateau,
"exploration_batch": active_batch or (batches[-1] if batches else None),
"required_exploration": (
"source_backed_exploration" if next_action in {"run_literature_loop", "develop_literature_batch"} else None
),
"agent_instruction": instruction,
}
def guard_state(
results_path: Path,
*,
max_candidates: Optional[int] = None,
stop_files: Optional[List[str]] = None,
plateau_threshold: int = DEFAULT_PLATEAU_THRESHOLD,
min_delta: float = DEFAULT_MIN_DELTA,
hard_crash_threshold: int = DEFAULT_HARD_CRASH_THRESHOLD,
mode: str = "max",
pending_manifest_count: int = 0,
exploration_batch_size: int = DEFAULT_EXPLORATION_BATCH_SIZE,
family_repeat_limit: int = DEFAULT_FAMILY_REPEAT_LIMIT,
) -> Dict[str, Any]:
return guard_state_for_rows(
load_rows(results_path),
results_path=str(results_path),
max_candidates=max_candidates,
stop_files=stop_files,
plateau_threshold=plateau_threshold,
min_delta=min_delta,
hard_crash_threshold=hard_crash_threshold,
mode=mode,
pending_manifest_count=pending_manifest_count,
exploration_batch_size=exploration_batch_size,
family_repeat_limit=family_repeat_limit,
)
def print_text(state: Dict[str, Any]) -> None:
for key in [
"decision",
"reason",
"next_action",
"final_response_allowed",
"candidate_cap",
"candidate_cap_source",
"mode",
"candidate_attempts",
"remaining_candidates",
"pending_candidates",
"scored_attempts",
"best_score",
"baseline_status",
"baseline_score",
"improvement",
"agent_instruction",
]:
value = state.get(key)
if isinstance(value, bool):
value = str(value).lower()
elif value is None:
value = ""
print(f"{key}={value}")
def main(argv: Optional[List[str]] = None) -> int:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("results", nargs="?", default="results.tsv")
parser.add_argument("--max-candidates", type=parse_max_candidates_arg)
parser.add_argument("--stop-file", action="append")
parser.add_argument("--plateau-threshold", type=int, default=DEFAULT_PLATEAU_THRESHOLD)
parser.add_argument("--min-delta", type=float, default=DEFAULT_MIN_DELTA)
parser.add_argument("--hard-crash-threshold", type=int, default=DEFAULT_HARD_CRASH_THRESHOLD)
parser.add_argument("--exploration-batch-size", type=int, default=DEFAULT_EXPLORATION_BATCH_SIZE)
parser.add_argument("--family-repeat-limit", type=int, default=DEFAULT_FAMILY_REPEAT_LIMIT)
parser.add_argument("--mode", choices=["max", "min"])
parser.add_argument("--format", choices=["text", "json"], default="text")
args = parser.parse_args(argv)
if args.plateau_threshold <= 0:
raise ValueError("--plateau-threshold must be positive")
if args.min_delta < 0:
raise ValueError("--min-delta must be non-negative")
if args.hard_crash_threshold < 0:
raise ValueError("--hard-crash-threshold must be non-negative")
if args.exploration_batch_size < 0:
raise ValueError("--exploration-batch-size must be non-negative")
if args.family_repeat_limit < 0:
raise ValueError("--family-repeat-limit must be non-negative")
results_path = Path(args.results).resolve()
mode = args.mode
if mode is None:
try:
mode = campaign_mode_for_results(results_path)
except ValueError as exc:
parser.error(str(exc))
stop_files = args.stop_file if args.stop_file is not None else list(DEFAULT_STOP_FILES)
resolved_stop_files = [
str(path if path.is_absolute() else results_path.parent / path) for path in map(Path, stop_files)
]
state = guard_state(
results_path,
max_candidates=args.max_candidates,
stop_files=resolved_stop_files,
plateau_threshold=args.plateau_threshold,
min_delta=args.min_delta,
hard_crash_threshold=args.hard_crash_threshold,
mode=mode,
exploration_batch_size=args.exploration_batch_size,
family_repeat_limit=args.family_repeat_limit,
)
if args.format == "json":
print(json.dumps(state, sort_keys=True))
else:
print_text(state)
return 0
if __name__ == "__main__":
raise SystemExit(main())
Requirements and compatibility
Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta
“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.
Needs: Needs Python
The author says: Requires NVFLARE 2.9.0+, Python, and permission to run NVFLARE jobs in the selected environment.
Security
What our scanner noticed· Medium risk
- Large base64-encoded blobs
- Scripts that your agent may run
This skill includes scripts that your agent may run. Read them before you use it.
A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.
Attribution and licence
- Created by
- NVIDIA FLARE Team
- Publisher
- NVIDIA (Official)
- Source
- NVIDIA/skills · skills/nvflare-autofl · commit fce3cca
- Licence
- Apache License 2.0 (redistribution allowed)
- LICENSE (added by AutoGineer from LICENSE-APACHE)
- ATTRIBUTION.md (written by AutoGineer)
- Synced
AutoGineer is not affiliated with or endorsed by NVIDIA FLARE Team or NVIDIA.
Download ZIP
The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download nvflare-autofl.zip