Expand description
scx-forge-agent: an LLM-driven optimizer for sched_ext schedulers.
Hybrid loop: deterministic code owns build/validate/keep-revert/stop; the LLM
is called only to propose one coherent policy experiment per round (and to fix
build errors).
The reward function is the built-in validation harness (validate.rs). The
target scheduler is whatever [scheduler].package in the spec names (any
scheds/rust/<name> crate); the agent modifies that crate in place. See
tools/scx_forge_agent/README.md.
ModulesΒ§
- agent_
cli π - Subprocess backends: drive a roundβs edits by shelling out to the
claude,opencode,codex, orcursor-agentCLI in non-interactive mode, run with the scheduler crate directory as the cwd so the CLIβs own tools edit the files in place. The controller then builds/validates the resulting diff exactly as it does for the built-inopenaibackend, so keep/revert/dedup work unchanged. - api π
- OpenAI-compatible
/chat/completionsclient with a tool-calling loop. - color π
- Minimal ANSI coloring for live terminal progress.
- config π
- Model configuration from the spec and
SCX_FORGE_*environment variables, and the backend the agent uses to drive edits. - git π
- In-place checkpoint/revert for the optimization loop, using the git index.
- http π
- HTTP client for an OpenAI-compatible inference endpoint: large request bodies and long server think times.
- interrupt π
- model_
timeout π - progress π
- TTY-only progress spinners for local blocking phases.
- report π
- Optimization run report: per-round history table, markdown and JSON renderers.
- spec π
- Validation spec model (parsed from the TOML the agent points the harness at).
- sudo π
- Resolve how the harness gains root to load the scheduler, and build the
privileged commands. Ported from the Python harnessβs
setup_sudo. - tools π
- Sandboxed tools exposed to the model as OpenAI function calls. Target-crate
tools (
read_file,list_dir,grep, optionalrg,web_fetch, and gatededit_file) resolve paths relative to the scheduler crate or public URLs; comparison tools read other schedulers underscheds/rustbut never write them. Host-topology tools run fixed read-only commands or read fixed sysfs CPU cache metadata paths. Absolute paths and..are rejected, and canonicalized targets must stay inside their configured roots. - usage π
- Token-usage accounting summed across the whole optimization run, plus the
one-line footer (
prompt:24.3k tokens:515) printed at the bottom of the output. The footer shape mirrors boroβs progress UI. - validate π
- Native validation harness: the agentβs reward function.
StructsΒ§
- Active
Model πPrinter - Attempt
Tags π - Optimize
Args π - Optimize
Outcome π
EnumsΒ§
- Phase π
- Two stages of the optimization: tune the schedulerβs existing configuration
knobs first, then propose new mechanisms. The model drives the transition by
emitting the completion sentinel; both phases share the
[ai].roundsbudget.
ConstantsΒ§
- KNOB_MD π
- KNOB_
PHASE_ πDONE_ SENTINEL - Sentinel a knob-phase planner emits when no untested knob value looks promising any more, telling the controller to move on to code changes.
- OPTIMIZER_
MD π - SKILL_
MD π - The resource markdown files are embedded at compile time so prompt edits stay close to the domain text instead of the Rust control flow.
FunctionsΒ§
- agent_
dim π - agent_
error π - agent_
info π - agent_
log π - agent_
success π - agent_
warn π - append_
attempt_ πsummary - attempt_
memory_ πfor_ prompt - attempt_
summary_ πline - base_
system π - bpf_
const_ πvolatile_ initializer_ name - bpf_
const_ πvolatile_ initializer_ only_ vars - build_
keep_ πrunning_ scheduler - build_
with_ πfix_ loop - cargo_
build π - Build the scheduler crate. Returns Err(combined output) on failure.
- cargo_
build_ πwith_ progress - cargo_
program π - classify_
attempt π - classify_
policy_ πarea - coding_
system_ πprompt - configure_
sudo_ πfrom_ spec - contains_
any π - diff_
file_ πpath - direction_
stopword π - edit_
prompt π - The coder is handed exactly the plannerβs plan - nothing else. Build-fix and runtime-fix rounds have no plan, so they fall back to the round context plus the failure to repair.
- expand_
glob_ πpath - expand_
sudo_ πpassword_ file - history_
table π - home_
dir π - ineffective_
round_ πedit_ reason - ineffective_
round_ πnote - install_
ctrl_ πc_ handler - interrupted_
requested π - knob_
edit_ πprompt - Knob-phase coder prompt. With a planner plan (openai backend) it just asks the coder to apply that one-line default change. Without a plan (subprocess backends, which have no separate planner) it carries the round context plus the knob inventory so the coder can pick and apply a knob itself.
- knob_
inventory π - Assemble the scheduler-agnostic knob inventory the knob-phase model tunes
from: the binaryβs
--help(every option, its default, and - for enums - its possible values, rendered by clap). This needs no per-scheduler hand-maintenance, works for anyscheds/rust/<package>crate, and can never go stale relative to the options the scheduler actually exposes. - knob_
phase_ πcomplete - True if a knob-phase planner reply signals the knob space is exhausted.
- knob_
planner_ πprompt - Knob-phase planner prompt: the round context plus an instruction to pick one option to retune (or end the phase). The available options live in the knob-phase system prompt, not here.
- knob_
system_ πprompt - System prompt for the KNOB-TUNING phase: the model picks one existing option per round and changes its default to a single untested value, or signals the phase is done. It never writes new logic here.
- main π
- model_
backend_ πlabel - Backend label for the model footer: just the backend name for the subprocess
CLIs, and
openai @ <base_url>for the built-in HTTP backend so the endpoint is visible. - model_
display_ πname - normalize_
attempt_ πsummary - normalize_
diff π - Normalize a
git difffor dedup: drop theindex <hash>..<hash>lines whose blob hashes are noise, so two textually identical changes compare equal. - normalized_
improvement π - optimize π
- optimize_
loop π - planner_
plan_ πrejection_ reason - planner_
prompt π - planner_
recovery_ πnote - planner_
system_ πprompt - prefix_
at_ πchar_ boundary - print_
final_ πreport - read_
attempt_ πmemory - record_
interrupted_ πround - record_
model_ πtimeout_ round - resolve_
repo_ πroot - round_
context_ πprompt - round_
record π - run_
attempt_ πsummary - run_
coding_ πturn - scheduler_
help_ πtext - Capture the schedulerβs
--helpoutput so the planner can see which CLI options (knobs) already exist. This is the always-current, zero-maintenance source of truth for what the sweep has tuned - no hand-kept signatures. Returns None if the binary is missing or errors. - should_
try_ πruntime_ fix - spec_
sudo_ πpassword_ file - start_
keep_ πrunning_ scheduler - suffix_
at_ πchar_ boundary - validation_
failure_ πfeedback