Projects finished

Pitch Ledger

A multi-agent system on Azure that turns football match events into audited, personalized insights, where a model writes the words and code checks every number.

Started
Updated
Tags
ai agents, azure, evaluation, sports, hackathon
The Pitch Ledger Studio title, "Where match intelligence meets fan experience", next to an illustration of a green and white football.

Overview

Pitch Ledger turns a football match’s raw events into short insights for three kinds of people: studio producers, analysts and casual fans. The insights show up as captions, on-screen overlays, and a “Tell me more” story for anyone who wants the longer version.

You can try the Studio on Azure or read the code on GitHub.

The main rule behind the design is that a model writes the words and code writes the numbers. An Explainer agent drafts each insight, and an Auditor agent checks every number in it and can send it back or block it before anyone sees it.

These parts work today:

  • Synthetic matches: a generator makes seeded, reproducible matches with fictional clubs and 1 Hz tracking for all 22 players. One match is about 2,500 events and 130,000 tracking rows.
  • Planted scenarios: YAML files inject a known change, such as a late collapse, so I know in advance what the system should notice.
  • Stats engine and moment detector: rolling 5-minute metrics (xG, PPDA, control, chaos), and triggers that cite the event IDs behind them.
  • Agents with an Auditor: Explainer, Auditor, Narrator, Personalizer and Translator. They get numbers from six read-only stats tools, never from memory.
  • Personalization and translation: five audience modes, in English, Spanish and Filipino, for every aired insight.
  • The insight ledger: every insight, audit, approval and overlay is stored as a record.
  • A live pipeline: feed → engine → queue → agents → ledger, with alerts for feed gaps, lag, blocks and model fallbacks.
  • Studio: a Match Centre replay with a 2D pitch, charts and “Tell me more” stories, plus a producer console to approve or block each insight before it airs.
  • An evaluation scorecard: detection, accuracy, planted-error catch rate, coverage and editorial gates.
The Match Centre replaying a match between Northbridge Athletic and Corrowmere Town, 3–1 in the 69th minute. A 2D pitch shows every player’s position. An overlay at the bottom reads “Momentum bar, Corrowmere Town: Corrowmere Town lost control after 57’ and have made many mistakes, letting Northbridge Athletic take charge”, with a “Tell me more” link. Above the pitch, viewers pick a mode, a language, a club, a player to follow and a metric. On the right, a match feed mixes insights with shots and substitutions.
The Match Centre at 69': an aired insight on the pitch, the match feed on the right, and the viewer's mode and language above

Context

Sports broadcasts are full of numbers said with a lot of confidence, like possession, expected goals and distance covered. An AI writing match commentary would say them with the same confidence, whether or not they’re right.

Generating a caption turned out to be the easy part. The harder problem, and the one the design is built around, was producing a caption you could put on air without someone re-checking every figure.

It’s the same rule I set for The T3 Project: if a number can be calculated reliably, I’d rather calculate it than ask a model to guess. Pitch Ledger takes that a step further by adding an agent whose only job is to check the other agents’ work.

The stack is all Azure: Microsoft Foundry for the models, Event Hubs, Service Bus and Web PubSub for the live feed, Cosmos DB as the ledger, Azure Data Explorer for analytics, and Container Apps for hosting, deployed by GitHub Actions. The backend is Python and FastAPI; the Studio is Next.js.

A few parts of the plan changed once I started building on the platform:

  • Fabric → Azure Data Explorer: on day one, because the Fabric trial wasn’t available.
  • Batching the feed: one tracking row per Event Hubs message let lag grow to two minutes, so each run’s rows went into a single message instead.
  • Fan view → Match Centre: a day later.
  • Bigger budgets: the model call budget went from 120 to 160 per run, and the Auditor’s reply cap from 300 to 600 tokens, once real replays showed what the agents actually needed.

Problem

There were two problems I kept coming back to.

The first was trust. Every statistic, trigger, chart and cost estimate is computed in code. The model only supplies the wording, and every number it writes is checked against the value the code calculated. If they don’t match, the insight is rejected.

To see whether that actually works, I planted errors on purpose. Across six offline matches:

  • 95 of 95 insights recomputed correctly.
  • The Auditor caught 33 of 33 planted errors.
  • All 8 scorecard gates passed.

Foundry’s judges scored one match’s insights 5.0 of 5 for groundedness, 4.0 for coherence and 3.5 for fluency. That’s a trade-off I made on purpose: every number in the copy has to match the code, even if the wording reads a little stiff.

The second problem was running it live. Speed and cost both had hard limits, and each one showed up in a real run:

  • Event Hubs’ Basic tier accepts about 1,000 messages a second, which throttled a 60x replay.
  • A full replay used 119 of its 120 allowed model calls.
  • Before the fallback fixes, 18 of 150 texts aired as code-built templates instead of model copy. After the fixes, none did.
  • In Azure, feed lag was 0.4 to 0.9 seconds at the median and 2.0 to 4.6 seconds at the 95th percentile, at 25x speed.

A full replay of one match cost 111 model calls, about 8 US cents. The fixed Azure cost is mostly Event Hubs, estimated at about $11 a month.

Reflection

Looking back, the most important agent is the one that doesn’t write anything. The Auditor only checks the others, and its 33-of-33 record is what makes the rest of the output usable.

Most of the limits I ran into were ordinary engineering ones, like message sizes, throttling, call budgets and token caps, and I only found each of them in a live run.

On the surface, Pitch Ledger is a sports app. Underneath, it’s about the same question I keep coming back to in my other projects: whether anyone can check what a model says, and not only whether it can say it.

Artifacts

  • Live appPitch Ledger StudioThe deployed Studio on Azure. Watch the demo match, or open the producer console.
  • GitHubpimcabanlit/pitch-ledgerThe full code, from the match generator to the agents, tests and Azure setup.