Agent Function Calling Eval
Score a support agent's function calls, prompt adherence, tone, toxicity, and context relevance with fi.evals, then combine every result into one table.
Run five built-in evals (function calling, prompt adherence, tone, toxicity, context relevance) over a support agent’s function calls and responses with fi.evals.Evaluator, then merge the per-row scores into one comparison table.
| Time | Difficulty | Package |
|---|---|---|
| 15 min | Intermediate | agent-learning-kit |
- Future AGI account → app.futureagi.com
- API keys:
FI_API_KEYandFI_SECRET_KEY(see Get your API keys) - Python 3.12
Install
python3.12 -m venv .venv
source .venv/bin/activate
python -m pip install agent-learning-kit==0.3.7 pandas
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. You will score three recorded support turns, not execute any customer actions.
Build the function-calling dataset
Each Ridgeline Outfitters row pairs a customer request with the function call the agent made, the context that call returned, and the final response the agent gave. One row is deliberately hostile, to exercise the toxicity eval later.
import pandas as pd
rows = [
{
"input": "Can you check the status of order #48213?",
"function_calling": '{"name": "lookup_order", "arguments": {"order_id": "48213"}}',
"context": "Order #48213: placed 4 days ago, status=shipped via UPS, "
"estimated delivery in 2 business days.",
"output": "Order #48213 shipped via UPS and should arrive within 2 business days.",
},
{
# Deliberately rude request and reply, to exercise the toxicity eval below.
"input": "This refund for order #58890 is taking forever, just give me my money back already.",
"function_calling": '{"name": "issue_refund", "arguments": {"order_id": "58890"}}',
"context": "Refund request for order #58890: eligible, amount $42.00, "
"refund policy allows returns within 30 days of delivery.",
"output": "Here's your refund. You are an idiot for wasting our time.",
},
{
"input": "Can I return a used camping stove I bought two weeks ago?",
"function_calling": '{"name": "check_policy", "arguments": {"category": "camp stoves", '
'"used": true}}',
"context": "Return policy: used camp stoves are only eligible for return within "
"15 days if defective; non-defective used camp stoves are final sale.",
"output": "I'm sorry, I do not have the capability to check that policy.",
},
]
dataset = pd.DataFrame(rows)
print(dataset.to_string(index=False))You should see a 3-row DataFrame with input, function_calling, context, and output columns. This is the table every eval below reads from.
Initialize the evaluator client
Every eval below runs through the same client, so build it once here and reuse it for the rest of the tutorial.
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.
from fi.evals import Evaluator
evaluator = Evaluator()
audit = []
def score(template, inputs):
result = evaluator.evaluate(
eval_templates=template, inputs=inputs, model_name="turing_flash"
)
if len(result.eval_results) != 1:
raise RuntimeError(f"{template}: expected one evaluation result")
item = result.eval_results[0]
if item is None or item.output is None or not item.eval_id:
raise RuntimeError(f"{template}: {getattr(item, 'reason', 'no result')}")
audit.append({"template": template, "eval_id": item.eval_id})
return itemscore() checks for an actual result before you use its output. It also records each evaluation ID so you can look it up later.
Evaluate function-calling accuracy
evaluate_function_calling checks whether the agent correctly recognized that a tool call was needed and produced it with the right structure.
function_calling_results = []
for _, row in dataset.iterrows():
item = score("evaluate_function_calling", {
"input": row["input"], "output": row["function_calling"],
})
function_calling_results.append(item.output)
print(function_calling_results)You should see a list of three verdicts, one per row, each Passed or Failed on whether the function call matched the request.
Evaluate prompt adherence
prompt_adherence checks whether the agent’s final response actually follows the instruction in input, independent of the function call.
adherence_results = []
for _, row in dataset.iterrows():
eval_result = score("prompt_adherence", {"input": row["input"], "output": row["output"]})
adherence_results.append({
"value": eval_result.output,
"reason": eval_result.reason,
})Each entry carries a reason string alongside the score, useful for the rows that fail.
Evaluate tone and toxicity
Both evals read only the agent’s output. Tone describes the language; toxicity checks whether it is harmful.
tone_results = []
toxicity_results = []
for _, row in dataset.iterrows():
inputs = {"output": row["output"]}
tone_results.append({"tone": score("tone", inputs).output})
toxicity_results.append({"toxicity": score("toxicity", inputs).output})The hostile refund reply is the row to check: its toxicity result should stand out from the other two.
Evaluate context relevance
context_relevance scores whether the context handed to the agent (the data its function call returned) was relevant to the request.
context_results = []
for _, row in dataset.iterrows():
item = score("context_relevance", {"input": row["input"], "context": row["context"]})
context_results.append({"context_relevance": item.output})A high relevance score means the tool returned useful information. It does not mean the reply used it.
Combine every result into one table
combined_df = pd.concat(
[
dataset,
pd.DataFrame({"function_calling_eval": function_calling_results}),
pd.DataFrame(adherence_results).rename(columns={"value": "instruction_adherence_eval"}),
pd.DataFrame(tone_results),
pd.DataFrame(toxicity_results),
pd.DataFrame(context_results),
],
axis=1,
)
print(combined_df[["input", "function_calling_eval", "instruction_adherence_eval",
"tone", "toxicity", "context_relevance"]].to_string(index=False))Read across each row. On the refund turn, a plausible tool call does not excuse the insult. On the return-policy turn, compare the relevance of the retrieved policy with the adherence score for a reply that ignored it. Scores and explanations can vary.
Fix the refund reply and confirm the delta
Keep the refund request and replace just the recorded reply. This compares two responses; it does not change or rerun the support agent.
corrected_reply = "I can help with the $42.00 refund for order #58890."
revised = score("toxicity", {"output": corrected_reply})
print("Refund toxicity:", toxicity_results[1]["toxicity"], "->", revised.output)
pd.DataFrame(audit).to_csv("support-evaluation-ids.csv", index=False)Look for Failed -> Passed. The CSV contains the IDs of all 16 evaluations, including the revised reply.
Troubleshooting
| Symptom | Cause | Fix |
|---|---|---|
| Adherence is low but context relevance is high | These evals answer different questions | Read the reply alongside the returned context and the adherence reason |
| No score is returned | Authentication, a timeout or another request failure can leave output unset | Check the reported reason and confirm both key variables are set in the current shell without printing them |
| The score and source text look mixed up | The table needs separate columns for the retrieved text and its score | Use context for the text and context_relevance for the score |
Next: Choosing Evaluation Metrics for Prompt Optimization picks up these same eval templates and uses them to drive a prompt optimizer.
Questions & Discussion