Skip to main content

AgentOpt Skill

End-to-end workflow: user files → ZIP → upload → optimize → poll → results.

Trigger

Activate when user says things like:
  • “optimize my agent / prompt”
  • “run agentopt on my files”
  • “improve my system prompt using the optimizer”
  • /AgentOpt

Prerequisites

Ask for these if not already provided:

Step 1 — Validate & convert files

agent.py requirements

Must have EDITABLE and FIXED boundary markers, and export run_batch:
Conversion rules:
  • If user’s code has no EDITABLE SECTION START marker → wrap their SYSTEM_PROMPT + run_batch in the EDITABLE section, append the FIXED boundary block verbatim.
  • If run_batch doesn’t exist → wrap their inference logic inside the template above.
  • MODEL must be set to the target model string.
  • The FIXED boundary block must not be modified.
Reference examples: examples/gaia/agent.py, examples/finance_agent/agent.py

eval.py requirements

Must define score(expected: str, predicted: str) -> float returning 0.0–1.0.
Conversion rules:
  • If user has a different metric (e.g. F1, BLEU, exact_match) → wrap it in a score(expected, predicted) function that returns float 0–1.
  • If user has no eval → use the exact/partial match template above, noting that they should customize it for their task.
Reference examples: examples/gaia/eval.py, examples/finance_agent/eval.py, examples/trail/eval.py

dataset.json requirements

JSON array of {"input": str, "answer": str} objects. Minimum 10 rows.
Conversion rules:
  • CSV with input/answer columns → python3 -c "import csv,json,sys; rows=list(csv.DictReader(open('data.csv'))); json.dump([{'input':r['input'],'answer':r['answer']} for r in rows],sys.stdout,indent=2)"
  • Different column names → remap to input/answer.
  • JSONL → python3 -c "import json,sys; data=[json.loads(l) for l in open('data.jsonl')]; json.dump(data,sys.stdout,indent=2)"
  • Fewer than 10 rows → warn the user; optimizer requires minimum 10.

Step 2 — Build ZIP


Step 3 — Upload ZIP to Cloudflare R2

Requires R2 credentials in environment:

Step 4 — Submit optimization job

Full request body: Response:

Step 5 — Poll status until complete

Poll every 30 seconds. Show live progress each iteration.
Status values: queuedrunningcompleted | interrupted | failed AgentOpt-specific status fields:

Step 6 — Fetch and display results

Result fields (agentopt):

Complete end-to-end script

Save to /tmp/run_agentopt.sh and run:
Usage:

Reference examples

Pre-built working examples in examples/: Quick test with a pre-built example:

Error handling


Validating agent.py locally before submitting