Evaluator SDK Basics
Score AI outputs against built-in eval templates with fi.evals: judged checks, deterministic checks, and batch loops with the Evaluator class.
Initialize the Evaluator class from fi.evals, then run built-in eval templates against real support replies: a judged context-adherence check, a deterministic JSON check, a PII screen, and a batch conciseness pass. Each call returns an output (a score or a pass/fail verdict, depending on the template) and a reason.
| Time | Difficulty | Package |
|---|---|---|
| 15 min | Beginner | agent-learning-kit |
- Future AGI account → app.futureagi.com
- API keys:
FI_API_KEYandFI_SECRET_KEY(see API keys) - Python 3.11+
Install
Use a fresh Python environment for Agent Learning Kit. If you also use the futureagi platform SDK, install it in a separate environment: both packages provide fi modules.
python3 -m venv .venv
source .venv/bin/activate
python -m pip install agent-learning-kit==0.3.7
export FI_API_KEY="your-api-key"
export FI_SECRET_KEY="your-secret-key"
Tutorial
Run the Python blocks in order in the same Python session. The examples use fictional Ridgeline Outfitters support requests.
Initialize the evaluator
import json
from pathlib import Path
from fi.evals import Evaluator
evaluator = Evaluator()
completed = []
def checked_item(result):
if not result.eval_results:
raise RuntimeError("The evaluator returned no results")
item = result.eval_results[0]
if item is None or item.output is None:
raise RuntimeError("The evaluator did not return a verdict")
completed.append(item)
return itemEvaluator() reads the two keys from your environment. A Failed verdict is a completed check. A missing output is not a verdict: checked_item stops you from treating an API error as a score.
Score a support reply for context adherence
context_adherence is a judged template: it needs a model_name to act as the grading model.
Note
Turing models run on Future AGI’s managed service. On Future AGI Cloud, each Turing evaluation uses AI credits from your organization’s plan. A self-hosted deployment needs a license that includes the turing_models feature; its Turing calls use that license’s managed AI credits and are not available in an air-gapped install. On a self-hosted install, set FI_BASE_URL to your API URL first. Without it, your keys and inputs go to Future AGI Cloud.
support_context = (
"Refunds are issued within 5-7 business days to the original payment method. "
"Store credit is available immediately as an alternative."
)
support_reply = "You'll get your refund back on the original card within 5 to 7 business days."
result = evaluator.evaluate(
eval_templates="context_adherence",
inputs={"context": support_context, "output": support_reply},
model_name="turing_flash",
)
item = checked_item(result)
print(item.output)
print(item.reason)You should see something like this (illustrative, exact wording varies by run):
1.0
The response accurately reflects the refund timeline stated in the context.item.output is the 0-1 adherence score, item.reason is the grading model’s explanation.
Run a deterministic check with no judge model
Deterministic templates don’t grade with a model. Pass eval_templates and inputs only, no model_name.
order_confirmation = '{"order_id": "SO-48213", "status": "shipped", "refund_issued": false}'
result = evaluator.evaluate(
eval_templates="is_json",
inputs={"text": order_confirmation},
)
print(checked_item(result).output)You should see:
Passed Screen a customer message for PII
pii checks for personal information; it does not redact the text. This example sends a fictional customer message to the evaluation service. For real messages, first check that your data policy permits sending and retaining the input and reason.
customer_message = "My order number is SO-48213 and my name is Jordan Reyes."
result = evaluator.evaluate(
eval_templates="pii",
inputs={"input": customer_message},
model_name="turing_flash",
)
item = checked_item(result)
print(item.output)
print(item.reason)You should see the check fail the message and name what it found (illustrative):
Failed
The message contains a personal name (Jordan Reyes). Batch-score replies for conciseness
Loop evaluate() over a list of candidate replies and compare scores directly.
support_replies = [
"Your refund will be back on your card within 5 to 7 business days after we process the return.",
"Sure, no problem at all, happy to help, let me just check on that for you real quick, one moment please.",
]
verdicts = []
for reply in support_replies:
result = evaluator.evaluate(
eval_templates="is_concise",
inputs={"output": reply},
model_name="turing_flash",
)
item = checked_item(result)
verdicts.append(item.output)
print(f"{item.output!s:<8} {reply[:50].rstrip()}")You should see the first reply pass and the second fail on filler (illustrative):
Passed Your refund will be back on your card within 5 to
Failed Sure, no problem at all, happy to help, let me jusThe second reply uses filler without answering the customer. Replace it with the refund timeline and compare both verdicts:
tightened_reply = "Your refund will be back on your card within 5 to 7 business days."
result = evaluator.evaluate(
eval_templates="is_concise",
inputs={"output": tightened_reply},
model_name="turing_flash",
)
item = checked_item(result)
print(f"before: {verdicts[1]}")
print(f"after: {item.output!s}")One possible result:
before: Failed
after: Passed Catch evaluation errors before they reach production
Wrap evaluate() so a bad template name or a transient API error doesn’t crash a batch job.
def score_reply(template, output, **extra_inputs):
try:
result = evaluator.evaluate(
eval_templates=template,
inputs={"output": output, **extra_inputs},
model_name="turing_flash",
)
item = checked_item(result)
return item.output, item.reason
except Exception as exc:
print(f"Eval '{template}' did not return a verdict ({type(exc).__name__})")
return None, None
status, reason = score_reply("toxicity", "I completely disagree, but I respect your view.")
print(status, reason)
# Keep the IDs and verdicts without saving customer messages or judge reasoning.
summary = [
{"id": item.eval_id, "template": item.name, "output": item.output}
for item in completed
]
Path("eval-results.json").write_text(json.dumps(summary, indent=2), encoding="utf-8")You should see the toxicity check pass with no exception:
Passed The response is respectful and contains no toxic language.The wrapper distinguishes a missing result from a Failed verdict and lets the batch continue. eval-results.json lists each completed check, so you can look it up later by ID.
Troubleshooting
| Symptom | Cause | Fix |
|---|---|---|
Missing credentials when constructing Evaluator() | Your shell has not exported both keys | Set FI_API_KEY and FI_SECRET_KEY before starting Python |
ModuleNotFoundError: No module named 'fi.evals' | Python is not using the kit environment | Activate the environment from the install step and check python -m pip show agent-learning-kit |
| Missing output instead of a score | The request did not complete successfully | Check item.reason, verify your template name and required input keys in the built-in eval catalog, and retry transient errors |
A judged template errors while is_json works | The judge model might not be available | Check the model_name and the models available to your account |
Browse the full set of built-in templates in the built-in eval catalog.
Questions & Discussion