𝗦𝗰𝗼𝗿𝗶𝗻𝗴 𝗔𝗜 𝗔𝗴𝗲𝗻𝘁𝘀: 𝗗𝗲𝘁𝗲𝗿𝗺𝗶𝗻𝗶𝘀𝘁𝗶𝗰 𝗠𝗲𝘁𝗿𝗶𝗰𝘀 + 𝗮𝗻 𝗟𝗟𝗠 𝗝𝘂𝗱𝗴𝗲

You run many small AI agents. You have agents for backend, frontend, mobile, and devops. Each agent has one job.

When you have many agents, you face a problem. You do not know if they are good. You do not know if a prompt edit makes them better or worse. Saying "it looks fine" does not work at scale.

I built a framework to solve this. It uses numbers to measure performance and improves prompts automatically.

The Strategy

Measure what you can measure with math first. Use an LLM judge only when you must. Deterministic metrics are fast and free. An LLM judge is slow and costs money.

How the system works:

• The harness runs each agent as a separate process. • It feeds a task to the agent. • It captures the output. • It scores the result against expected data.

The agent only needs to read from stdin and write to stdout. It can be Python or a shell script. The harness does not care.

Five core metrics to track:

  • Accuracy: Does the output match the goal?
  • Fuzzy score: How similar is the text to the target?
  • Timeout rate: How often does the agent fail to finish?
  • Safety violations: Does the output match unsafe patterns?
  • Reproducibility variance: Does the agent give the same answer every time?

If an agent is correct but inconsistent, it is a bug.

The LLM Judge

Some things are hard to measure with math. You need to know if an agent stayed in its role or followed constraints.

For these cases, an LLM judge reviews the work. It receives a rubric and the agent output. It returns a structured verdict. I validate this verdict against a JSON schema so it does not break the report.

The judge does more than just grade. It must suggest fixes. A critique like "this is weak" is useless. A critique like "add a JSON block to the prompt" is actionable.

The Improvement Loop

Failures go into a file. This file feeds an automated loop. The system looks at the weakest part of a prompt and tries to fix it. It keeps a pool of good candidates. It writes the best versions back to the code.

A single score is a snapshot. Use history to track trends. This tells you if you are getting better over time.

Build your foundation on deterministic metrics. Use the judge as a scalpel, not a hammer.

Valutare gli agenti AI: metriche deterministiche e un LLM Judge

Valutare gli agenti AI è molto più difficile che valutare i modelli linguistici (LLM) tradizionali. Mentre un LLM viene tipicamente valutato sulla sua capacità di generare testo coerente, un agente deve eseguire azioni, utilizzare strumenti e raggiungere obiettivi complessi in ambienti dinamici.

La sfida della valutazione degli agenti

Gli agenti AI non sono solo generatori di testo; sono sistemi che interagiscono con il mondo. Questo introduce diverse dimensioni di valutazione:

  1. Correttezza dell'azione: L'agente ha chiamato lo strumento giusto?
  2. Efficacia del ragionamento: Il piano d'azione è logico?
  3. Successo dell'obiettivo: L'agente ha effettivamente risolto il problema?
  4. Efficienza: Quanti passaggi o quanto costo sono stati necessari?

Metriche Deterministiche

Le metriche deterministiche sono basate su regole fisse e forniscono risultati oggettivi e riproducibili.

1. Corrispondenza Esatta (Exact Match)

Ideale per output strutturati o risposte brevi. Se l'agente deve rispondere "Sì" o "No", la corrispondenza esatta è la metrica più semplice.

2. Espressioni Regolari (Regex)

Utili per verificare se l'output segue un formato specifico, come un indirizzo email, un numero di telefono o un formato data particolare.

3. Validazione dello Schema JSON

Se l'agente deve produrre output in formato JSON per essere consumato da un altro sistema, la validazione dello schema è fondamentale per garantire che i campi siano presenti e del tipo corretto.

4. Esecuzione del Codice

Se l'agente scrive codice (ad esempio Python), il modo migliore per valutarlo è eseguirlo in un ambiente sandbox e verificare se produce il risultato atteso.

LLM-as-a-Judge

Nonostante la precisione delle metriche deterministiche, esse falliscono quando è necessaria una valutazione semantica o qualitativa. Qui entra in gioco l'approccio "LLM-as-a-Judge".

In questo scenario, si utilizza un modello linguistico più potente (come GPT-4o o Claude 3.5 Sonnet) per valutare l'output di un modello più piccolo o di un agente.

Vantaggi:

  • Comprensione semantica: Può valutare se il significato è corretto, anche se le parole sono diverse.
  • Valutazione del tono: Può determinare se la risposta è professionale, amichevole o appropriata al contesto.
  • Ragionamento complesso: Può analizzare i passaggi logici seguiti dall'agente.

Svantaggi:

  • Costo: Utilizzare modelli avanzati per ogni valutazione può essere costoso.
  • Latenza: La valutazione tramite LLM è più lenta rispetto alle metriche deterministiche.
  • Bias del giudice: L'LLM giudice può avere dei bias (ad esempio, tendere a preferire risposte più lunghe).

L'approccio ibrido: La soluzione migliore

Per una valutazione completa, la strategia migliore è combinare entrambi i metodi.

  1. Filtro Deterministico: Usa metriche deterministiche per scartare immediatamente gli output che violano le regole di base (es. JSON non valido o formato errato).
  2. Valutazione Semantica: Usa l'LLM Judge per valutare la qualità, la pertinenza e la logica degli output che hanno superato il primo filtro.

Conclusione

Non esiste una singola metrica che possa catturare tutta la complessità di un agente AI. Costruire un framework di valutazione robusto richiede un mix di rigore deterministico e intuizione semantica fornita dagli LLM.


Optional learning community: https://t.me/GyaanSetuAi