liveBook · Manning

Chapter 9: Evaluation and performance for LLMs and agents

What you will learn in chapter 9 of Building Reliable AI Systems

The chapter introduction explains why increasingly capable LLM and agent systems need attention to both silent hallucinations and performance under production load.

After this chapter you will be able to

What it builds on

Section by section

Introduction

The chapter introduction explains why increasingly capable LLM and agent systems need attention to both silent hallucinations and performance under production load.

Key terms: hallucination, retrieval system, agent, multi-agent architecture, orchestrator, cache, tool invocations

9.1 Identifying and measuring hallucinations

This section explains why confident but incorrect LLM outputs are hard to spot and why measuring hallucinations is necessary before addressing them.

Key terms: hallucinations, framework for measurement

9.1.1 Four steps to identify and measure hallucinations

This section presents a four-step process for measuring chatbot hallucinations: establish authoritative grounding data, build representative and adversarial tests, validate factual claims, and report actionable metrics.

Key terms: grounding dataset, grounding data, authoritative information, generic test set, adversarial test set, measurement test sets, claims, potential hallucinations, human review, grounding defect rate (GDR)

9.1.2 FActScore: fine-grained factual evaluation

This section explains how FActScore evaluates individual factual claims in a response and notes the cost of that finer-grained assessment.

Key terms: FActScore, atomic facts, grounding data, GDR, LLM calls, reference responses, text-overlap metrics

9.1.3 ROUGE for summarization evaluation

This section explains how ROUGE compares generated text with reference text for summarization evaluation and why word overlap alone cannot establish factual accuracy.

Key terms: ROUGE, generated text, reference text, expected responses, ROUGE-1, unigram, ROUGE-2, bigram, ROUGE-L, longest common subsequence

9.1.4 LLM-as-a-judge: A holistic approach

This section explains how an LLM judge evaluates hallucinations, why its judgments can be unreliable, and how production systems check them.

Key terms: LLM-as-a-judge, reference, hallucinations, ROUGE, judge models, biases, subtle factual errors, multiple judge models, majority votes, human validation

9.1.5 Red teaming and stress testing

This section explains how red-teaming exposes LLM failures that standard evaluations may miss and uses repeated testing and refinement to improve reliability.

Key terms: red-teaming, adversarial testing, metrics and benchmarks, extreme scenarios, edge cases, continuous feedback loop, adversarial examples, stress tests, human oversight and validation

9.1.6 Using monitoring frameworks to detect hallucinations

The section explains why production hallucination detection needs monitoring and shows how Phoenix can classify outputs so teams can track and alert on hallucination rates.

Key terms: development-time evaluation, data drift, MLOps, Phoenix, HALLUCINATION_PROMPT_TEMPLATE, HALLUCINATION_PROMPT_RAILS_MAP, llm_ classify, judge LLM, reference text, results DataFrame

9.2 Essential architectural patterns for performance

This introduction explains why an LLM application's architecture matters for responsiveness, scalability, and cost before previewing performance patterns.

Key terms: LLM-powered application, scale, high-end models

9.2.1 Token streaming: Presenting answers incrementally or at the same time

This section compares streaming an answer as it is generated with showing a completed reply, explaining when each presentation choice helps and what it risks.

Key terms: token streaming, tokens, partial feedback, token-streaming, asynchronous function, chunks

9.2.2 Handling surges with batching: System-level vs. OpenAI’s Batch API

This section contrasts application-level batching for near-real-time traffic with OpenAI’s Batch API for large offline jobs and explains how to choose between them.

Key terms: system-level batching, queue, concurrency, traffic spikes, OpenAI Batch API, .jsonl, custom_id, batch job, Files API, real-time user queries

9.2.3 Caching for efficiency

This section explains how exact-match and semantic caching reduce repeated LLM calls while using similarity checks and cache invalidation to protect answer quality.

Key terms: exact string matching, semantic caching, vector embeddings, embedding model, vector database, similarity search, cached response, similarity threshold, poor matches, LLM fallback

9.2.4 Multimodel fallback: Matching each query to the right model

This section explains how multimodel fallback routes queries by difficulty to balance answer quality, cost, and latency.

Key terms: multimodel fallback, router, classifier, query complexity, heuristics, machine-learning classifier, function calling, decision layer, two-pass approach, confidence or quality check

9.2.5 Project: Building an e-commerce LLM service with batching, caching, and model fallback

Builds an e-commerce LLM service that uses queued batching, semantic caching, model routing, and optional streaming to handle busy periods efficiently.

Key terms: request_queue, enqueue_request, batch_size, system-level batching, GPTCache, semantic-level caching, ONNX embedding model, similarity threshold, detect_complexity, choose_model

9.2.6 Further improvements

The section outlines ways to refine a running e-commerce LLM service for cost, speed, routing accuracy, and freshness.

Key terms: tokens, gpt-5.4, gpt-5.4-mini, GPTCache, cached answers, prompt compression, token use, intent, meta prompting, two-pass fallback

9.3 Evaluating agent performance

This section explains why evaluating agents requires looking beyond standalone LLM metrics to assess both outcomes and the steps that produce them.

Key terms: accuracy, hallucination rate, latency, token efficiency, decision-making process, execution path, end-to-end assessments, reasoning and execution pipeline, granular step-by-step analysis, failure points

9.3.1 Core metrics for evaluating LLMs

The section explains why evaluating an agent requires looking beyond the quality of its final text output.

Key terms: output quality metrics, agents, intent, tools, intermediate reasoning, tool call

9.3.2 Evaluating agents: Beyond traditional LLM metrics

This section explains how to evaluate an agent’s completed task and inspect its actions and execution steps for problems that a final answer alone may hide.

Key terms: end-to-end testing, intent classification, actions, final response, internal workflow, parameter extraction, tool calls, LangSmith, expected tool calls, trajectory

9.4 Summary

Where this is used later

Concepts explained in this chapter

← Chapter 8: Multi-agent systems Chapter 10: Deploying and monitoring →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.