Random Search
Use RandomSearchOptimizer in Agent Learning Kit to compare independent prompt variations on return tickets and inspect the winning template.
About
Random Search asks a teacher model for several ways to word the same instruction, then runs each variation on every row. Use it when you want to know whether rephrasing an instruction changes the answers, without using one candidate’s score to write the next.
Compare two ways to handle a return
Ridgeline Outfitters wants its agent to ask for an order number before starting a return. Give the candidate generator the original instruction and set teacher_model separately: changing the generator’s model does not change the teacher.
With Python 3.12, install Agent Learning Kit in a virtual environment:
python3.12 -m venv .venv
source .venv/bin/activate
python -m pip install agent-learning-kit==0.3.7
Set OPENAI_API_KEY in the shell where you run the script. Save the example as random_search.py and run python random_search.py. The local Contains metric gives a reply 1 if it includes “order number” (case-insensitive) and 0 otherwise. You do not need Future AGI keys for this example.
from fi.evals.metrics.heuristics.string_metrics import Contains
from fi.opt.base.evaluator import Evaluator
from fi.opt.datamappers import BasicDataMapper
from fi.opt.generators import LiteLLMGenerator
from fi.opt.optimizers import RandomSearchOptimizer
model = "gpt-4o-mini"
tickets = [
{"message": "The rain shell is too big. Can I send it back?"},
{"message": "I would like to return my unused headlamp."},
]