optim-agent
Act as the sampler inside any coding-agent session: Claude Code, Codex,
OpenCode/OpenClaw, or another agent that can read project files and run shell
commands. Read the project to understand parameter meaning and interactions,
propose one configuration, run the real evaluator, and record the result
through optim-agent's ask/tell API. Let the measured objective, not the agent's
intuition, decide what works.
Load the workflow
Use this file as the operating guide for the active coding agent. In Codex, it
can be installed directly from GitHub:
$skill-installer install https://github.com/Optim-Agent/optim-agent
In Claude Code, OpenCode/OpenClaw, or another coding-agent environment, place
this repository or SKILL.md in the agent-visible workspace and ask the agent
to follow the optim-agent workflow. The workflow does not depend on Codex-only
APIs; it needs file access, shell access, and Python.
Ensure the Python package is importable. Choose one source; do not install both:
# Stable release from PyPI
python -m pip install optim-agent
# Latest source from GitHub
python -m pip install "optim-agent @ git+https://github.com/Optim-Agent/optim-agent.git"
For a reproducible GitHub install, append @<tag-or-commit> after .git.
Workflow
Understand the system. Read the evaluation entry point and every file
that defines the target parameters. Record each parameter's type, legal
range, semantics, interactions, and operational constraints.
Define the experiment. Confirm the scalar objective, minimize or
maximize, trial budget, evaluation command, runtime/cost limit, and fixed
workload or seed. For multiple metrics or hard constraints, agree on one
scalar feasibility or penalty rule before running trials.
Establish a baseline. Evaluate the current/default configuration with the
same command and environment used for every later trial.
Initialize or resume. Keep artifacts in the repository's ignored
.optim-agent-runs/ directory:
if git rev-parse --git-dir >/dev/null 2>&1 && ! git check-ignore -q .optim-agent-runs/; then
printf '/.optim-agent-runs/\n' >> "$(git rev-parse --git-path info/exclude)"
fi
from pathlib import Path
import optim_agent as oa
run_dir = Path(".optim-agent-runs")
run_dir.mkdir(exist_ok=True)
study = oa.create_study(
direction="minimize",
storage=run_dir / "skill-study.json",
seed=0,
)
print([(t.params, t.value, t.state) for t in study.trials])
Run one informed trial. Choose parameters from code understanding and all
completed history, then use explicit ask/tell:
params = {"threshold": 0.72, "budget": 80}
trial = study.ask(params)
try:
value = evaluate_system(**trial.params)
except Exception:
study.tell(trial, state="failed")
raise
else:
study.tell(trial, value)
For a deliberately stopped trial, report the latest valid intermediate
metric first, then call study.tell(trial, state="pruned").
Select the next point. Avoid accidental repeats, explore broadly before
exploiting, respect bounds and constraints, and treat failed regions as
evidence. If the evaluator is noisy, repeat promising configurations under
the same workload before declaring a winner.
Stop and report. Stop at the approved budget or stopping condition.
Report the baseline, best value and parameters, trial count, failed/pruned
trials, convergence trend, and exact reproduction command.
Recovery
JSON storage records a trial when study.tell runs. Before launching an
expensive external evaluation, save its parameters, command, and output path in
a per-trial directory under .optim-agent-runs/. After interruption, inspect
that output before rerunning: if a valid result exists, recreate the same point
with study.ask(params) and record it; otherwise rerun it deliberately.
Use SQLite storage (skill-study.db) only when the user explicitly wants
multiple processes. Sequential trials are the default because each proposal
should use the complete prior history.
Rules
- Use ask/tell in skill mode; do not delegate proposal selection to
AgentSampler when the session agent is meant to read and reason over code.
- Keep evaluation inputs and outputs isolated from production configuration.
- Never fabricate, infer, or manually improve an objective value.
- Record crashes as
failed; record intentional early stops as pruned.
- Preserve the study and trial artifacts so the result is auditable and resumable.
- Do not tune secrets, credentials, or unbounded parameters.
1---2name: optim-agent3description: Use when the user wants to optimize configurable system parameters against a measurable scalar objective, especially for model training, inference, quantitative strategies, reinforcement learning, scientific workflows, or other expensive black-box evaluations where reading the project can improve trial selection.4---5
6# optim-agent
7
8Act as the sampler inside any coding-agent session: Claude Code, Codex,
9OpenCode/OpenClaw, or another agent that can read project files and run shell
10commands. Read the project to understand parameter meaning and interactions,
11propose one configuration, run the real evaluator, and record the result
12through optim-agent's ask/tell API. Let the measured objective, not the agent's
13intuition, decide what works.
14
15## Load the workflow
16
17Use this file as the operating guide for the active coding agent. In Codex, it
18can be installed directly from GitHub:
19
20```text
21$skill-installer install https://github.com/Optim-Agent/optim-agent
22```
23
24In Claude Code, OpenCode/OpenClaw, or another coding-agent environment, place
25this repository or `SKILL.md` in the agent-visible workspace and ask the agent
26to follow the optim-agent workflow. The workflow does not depend on Codex-only
27APIs; it needs file access, shell access, and Python.
28
29Ensure the Python package is importable. Choose one source; do not install both:
30
31```bash
32# Stable release from PyPI
33python -m pip install optim-agent
34
35# Latest source from GitHub
36python -m pip install "optim-agent @ git+https://github.com/Optim-Agent/optim-agent.git"
37```
38
39For a reproducible GitHub install, append `@<tag-or-commit>` after `.git`.
40
41## Workflow
42
431. **Understand the system.** Read the evaluation entry point and every file
44 that defines the target parameters. Record each parameter's type, legal
45 range, semantics, interactions, and operational constraints.
462. **Define the experiment.** Confirm the scalar objective, `minimize` or
47 `maximize`, trial budget, evaluation command, runtime/cost limit, and fixed
48 workload or seed. For multiple metrics or hard constraints, agree on one
49 scalar feasibility or penalty rule before running trials.
503. **Establish a baseline.** Evaluate the current/default configuration with the
51 same command and environment used for every later trial.
524. **Initialize or resume.** Keep artifacts in the repository's ignored
53 `.optim-agent-runs/` directory:
54
55 ```bash
56 if git rev-parse --git-dir >/dev/null 2>&1 && ! git check-ignore -q .optim-agent-runs/; then
57 printf '/.optim-agent-runs/\n' >> "$(git rev-parse --git-path info/exclude)"
58 fi
59 ```
60
61 ```python
62 from pathlib import Path
63 import optim_agent as oa
64
65 run_dir = Path(".optim-agent-runs")
66 run_dir.mkdir(exist_ok=True)
67 study = oa.create_study(
68 direction="minimize",
69 storage=run_dir / "skill-study.json",
70 seed=0,
71 )
72 print([(t.params, t.value, t.state) for t in study.trials])
73 ```
74
755. **Run one informed trial.** Choose parameters from code understanding and all
76 completed history, then use explicit ask/tell:
77
78 ```python
79 params = {"threshold": 0.72, "budget": 80}
80 trial = study.ask(params)
81 try:
82 value = evaluate_system(**trial.params)
83 except Exception:
84 study.tell(trial, state="failed")
85 raise
86 else:
87 study.tell(trial, value)
88 ```
89
90 For a deliberately stopped trial, report the latest valid intermediate
91 metric first, then call `study.tell(trial, state="pruned")`.
926. **Select the next point.** Avoid accidental repeats, explore broadly before
93 exploiting, respect bounds and constraints, and treat failed regions as
94 evidence. If the evaluator is noisy, repeat promising configurations under
95 the same workload before declaring a winner.
967. **Stop and report.** Stop at the approved budget or stopping condition.
97 Report the baseline, best value and parameters, trial count, failed/pruned
98 trials, convergence trend, and exact reproduction command.
99
100## Recovery
101
102JSON storage records a trial when `study.tell` runs. Before launching an
103expensive external evaluation, save its parameters, command, and output path in
104a per-trial directory under `.optim-agent-runs/`. After interruption, inspect
105that output before rerunning: if a valid result exists, recreate the same point
106with `study.ask(params)` and record it; otherwise rerun it deliberately.
107
108Use SQLite storage (`skill-study.db`) only when the user explicitly wants
109multiple processes. Sequential trials are the default because each proposal
110should use the complete prior history.
111
112## Rules
113
114- Use ask/tell in skill mode; do not delegate proposal selection to
115 `AgentSampler` when the session agent is meant to read and reason over code.
116- Keep evaluation inputs and outputs isolated from production configuration.
117- Never fabricate, infer, or manually improve an objective value.
118- Record crashes as `failed`; record intentional early stops as `pruned`.
119- Preserve the study and trial artifacts so the result is auditable and resumable.
120- Do not tune secrets, credentials, or unbounded parameters.