← All Examples Example 05 / 12 Multi-Step Tool Chaining & Pairwise Elo Ranking
Prompt-First Example 05 · Evaluations · Tools · PairwiseRanker Elo

Multi-Step Tool Chaining &
Pairwise Elo Ranking

Verify that models invoke calculator and statistics tools across multi-step arithmetic via PiTurnResult.toolCalls, then compute position-swapped round-robin Elo.

File: examples/evals/tool-math.ts Recreate: pnpm tsx examples/evals/tool-math.ts Packages: @umwelten/evaluation @umwelten/pi
01 — The Prompt You Give Pi
“Build an evaluation script using @umwelten/evaluation that equips models with calculatorTool and statisticsTool on a multi-item grocery + 8% sales-tax problem. In verify(response, turn), award points both for hitting $28.88 AND for making at least 3 real tool calls in turn.toolCalls, then pass all model outputs to PairwiseRanker to compute round-robin Elo standings.”
Paste directly into pi or your coding agent with @umwelten/* installed. 5 min walkthrough
02 — The Example That Gets Built

Live workspace source: examples/evals/tool-math.ts

Read directly from disk at site-build time — byte-for-byte identical to the typechecked script in this repo.

TypeScript examples/evals/tool-math.ts
pnpm tsx examples/evals/tool-math.ts
1#!/usr/bin/env node
2/**
3 * Multi-step tool-calling & Elo pairwise ranking over `@earendil-works/pi-ai`.
4 *
5 * Usage:
6 *   pnpm tsx examples/evals/tool-math.ts          # instant deterministic mock
7 *   pnpm tsx examples/evals/tool-math.ts --live   # live cloud + local models
8 */
9
10import "@umwelten/pi";
11import {
12  calculatorTool,
13  EvalSuite,
14  PairwiseRanker,
15  statisticsTool,
16} from "@umwelten/evaluation";
17import {
18  DEFAULT_FAST_JUDGE,
19  FAST_MODEL_ROSTER,
20  QUICK_FAST_MODELS,
21} from "../_shared/fast-models.js";
22import { setupExampleRuntime } from "../_shared/mock-runtime.js";
23
24setupExampleRuntime(FAST_MODEL_ROSTER);
25
26const suite = new EvalSuite({
27  name: "tool-math-smoke",
28  systemPrompt:
29    "You are a careful mathematician. Use the calculator and statistics tools for every arithmetic step and end with the exact final number.",
30  temperature: 0,
31  tools: {
32    calculator: calculatorTool,
33    statistics: statisticsTool,
34  },
35  models: QUICK_FAST_MODELS,
36  allModels: FAST_MODEL_ROSTER,
37  tasks: [
38    {
39      id: "grocery-total",
40      name: "Grocery Total",
41      prompt:
42        "Compute the total cost of: 3 apples at $1.25 each, 2 loaves of bread at $3.50 each, 4 bottles of water at $0.75 each, and 1 cake at $12.99. Add 8% sales tax. Use the calculator tool.",
43      maxScore: 5,
44      verify: (response, turn) => {
45        const hasExact = /28\.88/.test(response);
46        const calls = turn?.toolCalls.length ?? 0;
47        return {
48          score: (hasExact ? 3 : 0) + (calls >= 3 ? 2 : calls >= 1 ? 1 : 0),
49          details: `exact28.88=${hasExact}, toolCalls=${calls}`,
50        };
51      },
52    },
53  ],
54});
55
56const records = await suite.run();
57const okRecords = records.filter((r) => !r.error);
58if (okRecords.length >= 2) {
59  const ranker = new PairwiseRanker(
60    okRecords.map((r) => ({
61      key: `${r.provider}:${r.model}`,
62      provider: r.provider,
63      model: r.model,
64      responseText: r.responseText,
65    })),
66    {
67      judgeModel: DEFAULT_FAST_JUDGE,
68      judgeInstructions: ["Prefer exact 28.88 with clear subtotal + tax breakdown."],
69      pairingMode: "all",
70    },
71  );
72  const ranked = await ranker.rank();
73  console.log(
74    "\nPairwise Elo standings:",
75    ranked.rankings.map((e) => `${e.provider}:${e.model} → Elo ${Math.round(e.elo)}`),
76  );
77}
03 — Captured Execution Telemetry

Captured stdout from running pnpm tsx examples/evals/tool-math.ts

Captured Run Output pnpm tsx examples/evals/tool-math.ts
🧪 Mode: MOCK (@earendil-works/pi-ai fauxProvider) — pass --live to hit real APIs & local GPUs

🧪 tool-math-smoke
══════════════════════════════════════════════════════════════════════
Tasks:   1 (Grocery Total)
Models:  5
Max:     5 per model
Run:     #001
══════════════════════════════════════════════════════════════════════

📝 Grocery Total
  ✅ google:gemini-4-hydrogen
  ✅ anthropic:claude-haiku-5-5
  ✅ openrouter:z-ai/glm-5.3-flash
  ✅ ollama:gemma4:26b
  ✅ openrouter:openai/gpt-6-luna
  ✅ google:gemini-4-hydrogen → 5/5 exact28.88=true, toolCalls=3
  ✅ anthropic:claude-haiku-5-5 → 5/5 exact28.88=true, toolCalls=3
  ✅ openrouter:openai/gpt-6-luna → 5/5 exact28.88=true, toolCalls=3
  ✅ openrouter:z-ai/glm-5.3-flash → 5/5 exact28.88=true, toolCalls=3
  ✅ ollama:gemma4:26b → 5/5 exact28.88=true, toolCalls=3


🏁 TOOL-MATH-SMOKE — FINAL RANKINGS
══════════════════════════════════════════════════════════════════════════════════════════════════════════════
Model                                         Score        Grocery   Cost       Time    
──────────────────────────────────────────────────────────────────────────────────────────────────────────────
🥇 ollama:gemma4:26b                           5/5 (100%)   5/5       $0.0000    0.0s    
🥇 openrouter:z-ai/glm-5.3-flash               5/5 (100%)   5/5       $0.0000    0.0s    
🥇 anthropic:claude-haiku-5-5                  5/5 (100%)   5/5       $0.0001    0.0s    
🥇 openrouter:openai/gpt-6-luna                5/5 (100%)   5/5       $0.0001    0.0s    
🥇 google:gemini-4-hydrogen                    5/5 (100%)   5/5       $0.0019    0.0s    

💰 Total cost: $0.0022

Pairwise Elo standings: [
  'openrouter:z-ai/glm-5.3-flash → Elo 1562',
  'openrouter:openai/gpt-6-luna → Elo 1529',
  'google:gemini-4-hydrogen → Elo 1499',
  'anthropic:claude-haiku-5-5 → Elo 1472',
  'ollama:gemma4:26b → Elo 1439'
]
04 — How & Why This Extends Pi

Architectural notes

Inspecting turn?.toolCalls on PiTurnResult proves the model actually invoked statistics followed by calculator rather than doing brittle mental arithmetic, while PairwiseRanker evaluates both (A, B) and (B, A) orders to cancel judge position bias.