匠人学院 JR Academy
Skip to article
Engineering handbook
AI Agent Engineering Handbook

Start with tool calls. Understand how an agent acts, reads observations and stops when something fails. Verify each boundary with complete code and offline tests.

5 chapters·16 guides·Open access
Exercise 2: A RAG Knowledge Assistant
On this page

Lab: A RAG Policy Assistant

Build an assistant that answers from a small, fictional HR handbook and cites the supporting rule. The important result is a supported answer or an honest missing-evidence response, not simply an index that was created successfully.

#Prepare the source

Use this synthetic handbook entry; it is not a real company's policy or employment guidance:

text
Document: demo-handbook, version 1 Meals: reimburse up to $50 per person per meal with a receipt. Annual leave: the fictional example provides 10 days after one year. Sick leave: the fictional example requires a medical certificate.

Preserve document ID, section and version as metadata. Split at meaningful section boundaries. Inspect the chunks so a condition such as “with a receipt” stays with its rule.

#Retrieve before generating

Create embeddings and an index only with an authorized provider or approved local model. The LangChain RAG chapter includes a concrete indexing example and its execution prerequisites.

First inspect retrieval for “Can I claim an $80 meal?” The meal passage must be returned. Then pass the question and passage to the answer stage with instructions to cite the source and avoid adding policy terms.

#A complete illustrative answer

The demo policy does not cover the full $80. It permits up to $50 per person per meal with a receipt, leaving $30 outside that limit. Source: demo-handbook, meals, version 1. This is a fictional policy example.

This answer is prewritten for teaching, not evidence of a live model run.

#Acceptance cases

Test a covered meal, a missing receipt, an unsupported question about parental leave, an updated policy and a user without access. Separate retrieval failure from an answer that ignores the retrieved rule.

When exposing the retriever as a tool, return source IDs and passages rather than only an unsupported answer string. Apply document permissions before retrieval, update embeddings when the source changes, and remove deleted documents from the index.

Improve with multiple documents, metadata filters and reranking only after the basic evidence chain passes.

System Design

Core system design concepts and practical case studies

Learn the trade-offs and patterns that matter in technical interviews.

Open System Design →

FAQ

Which language should I use?
Python and TypeScript both work. Start with the language you can debug; the first exercise uses Python 3.10+ and its standard library.
Does MCP require a specific model?
No. MCP connects applications to tools and context services. Compatibility depends on the host client, transport, protocol version and authorisation; model tool-calling support is a separate check.
Does learning agents guarantee employment?
No. Use a small project to demonstrate requirements analysis, permissions, testing and maintenance. Employment outcomes depend on the role market and your actual skills.

Done reading? Next steps