Metadata Card
- Prerequisites: Chapter 17 (Event-Driven Architecture); Basic LLM concepts
- Estimated Time: 45 minutes
- Core Difficulty: Advanced
- Completion Milestone: Design RAG systems and basic Agent patterns
Your Progress
You've learned all the classic crafts in the City of Artisans: from static inspection to layered assembly, from design patterns to engine splitting.
But in 2026, the City of Artisans has a new craft: intelligent forges — they don't just forge from blueprints, they learn and adjust parameters during forging.
Your engines need new intelligent features: auto-match opponents by skill level, answer player questions in natural language. Impossible with traditional mechanical logic alone. You need to integrate AI into the City of Artisans production line. Your Task
AI systems differ from traditional software: traditional is deterministic (same input → same output), AI is probabilistic (same input → multiple possible outputs). This changes testing, error handling, deployment.
Required reading: RAG architecture, Evaluation patterns Selective: Agent patterns (ReAct) Advanced: Cache-Augmented Generation
First Layer: RAG — Retrieval-Augmented Generation
Don't stuff data into the model — stuff it into a database. Retrieve relevant documents, combine with question, send to LLM.
User question → Retriever → Vector DB
↓ ↑
└── Retrieved docs ───┘
↓
Combine into Prompt → LLM → AnswerSecond Layer: Agent Pattern — LLM That Can Act
ReAct (Reasoning + Acting): LLM can call tools (functions/APIs). Thought → Action → Observation cycle.
Key challenge: LLM may loop infinitely. Set max iteration limit.
Third Layer: Cache-Augmented Generation
Cache LLM outputs for similar questions. Use semantic similarity for cache key.
Fourth Layer: Evaluation Patterns
AI testing can't use assertEquals. Use LLM-as-a-judge: another LLM evaluates output quality. Plus production monitoring: collect user ratings.
public String safeAnswer(String question) {
try {
return ragService.answer(question);
} catch (LLMException e) {
return defaultAnswers.getOrDefault(question, "Please try again later");
}
}Common Pitfalls: RAG data freshness, Agent given too many tools, cached results become stale, no fallback when LLM API fails.
Traveler's Notes
AI brings software engineering to a probabilistic world — RAG gives LLM external knowledge, Agents let LLM call tools, CAG uses cache for latency, evaluation makes non-deterministic outputs measurable. In 2026's City of Artisans, AI is becoming a standard module in every system.
Next: API Design & Contract Governance (Chapter 19).