A. Module overview
| Field | Value |
|---|---|
| Module ID | L3-M02 |
| Level | 3 - AI Agent Quality Engineer |
| Description | Testing the tool layer of an agent: defining a tool as a two-half contract (a schema for the machine, a name and description for the model) with contract tests and lint; tool selection (cases for the right tool, the wrong tool, no tool and ambiguous cases, sensitivity to listing order, consistency); checking parameters and malicious input (adversarial cases for type, bounds, size, Unicode, paths, injection-like strings, and instructions planted in tool results); a fake tool layer in a sandbox with an effect log, dry-run, idempotency keys, allowlist and denylist, approval, and rate and budget limits; and checking the list and calls of a small MCP server. The module lab is a simulated tool layer for the fictional product ThuVien Mini (a school library assistant), deterministic and offline: no model calls, no real server, no MCP SDK, no API key; tools run only in memory and in a temporary directory. What is known about MCP and the tool use API is quoted from sources read on 2026-11-04: the MCP specification revision 2026-07-28 (the Tools, Overview, Discovery, Versioning, Architecture pages and the changelog) and two MCP security pages, the Claude documentation on tool definitions, handling tool calls and strict tool use, OpenAI's function calling documentation, and three OWASP pages (LLM01, LLM05, LLM06). The reading level of each source is recorded in §12 of each lesson. |
| Why this module matters | Most agent failures happen where the model touches the world: choosing the wrong tool, filling in or being steered into wrong parameters, or a write tool running twice. The tool layer lives in the team's code, so ordinary tests can check it if you have the right case set and log. The module also lays the groundwork for trajectories (L3-M04), reliability (L3-M06) and agent safety (L3-M07). |
| Target professional competency | Level 3, learning outcome 2: "Test tool contracts, tool selection, arguments, permissions and side effects with sandboxed tools". The permissions part is only at the level of allowlist, denylist and approval on request; per-user authorization is not in the lab. |
| Estimated duration | 4 lessons × 120 minutes + 1 lesson × 150 minutes (L05, the longest lesson) = 10.5 hours, plus the module assignment (~4 hours) and quiz (~0.5 hours): ≈ 15 hours for someone who has completed L3-M01. An estimate, not yet measured with real learners. |
| Prerequisites | L3-M01 (the first lesson needs L3-M01-L05). The module reuses, without repeating: tool definitions, the tool_use and tool_result protocol, parameter checks and the four protective layers (L1-M05-L03 and L1-M05-L04), prompt injection and excessive agency (L1-M04), the tool layer in a sandbox, traces and the risk map (L3-M01-L01, L04, L05), contract tests (L1-M01-L04). No API key needed. |
| Module output (deliverable) | A tool validation test suite: contract tests and lint for a tool registry, a tool selection case set (right, wrong, none, ambiguous), a corpus of adversarial cases for parameters, tests for a fake tool layer with an effect log, and tests for the list and calls of a simulated MCP server; plus the small products of each lesson |
| Cost | 0 VND |
What learners build. Step by step, in code-labs/l3-m02: (L01) a subset JSON Schema validator using the standard library, a contract lint for names, descriptions, schemas, effects and examples, and a digest and diff of the tool list; (L02) five simulated tool selection policies, a fifteen-case set, a scoring function with five verdicts, order sensitivity and consistency; (L03) a parameter check chain (name, strict JSON, hidden characters, schema), a corpus of seventy-three adversarial cases, safe_path, flagging instructions in tool results; (L04) a fake tool layer with a hash-chained effect log, dry-run, idempotency, approval, limits and reconcile; (L05) a simulated MCP server and client following the message shapes of the 2026-07-28 specification, checking the list, calls, error codes and list pinning. The lab is independent of the earlier labs and needs only pytest.
What the module does not do. It does not measure real models or agents, it states no price, speed or reliability for any model, server or vendor, and it does not rank or recommend any framework or provider: every number in the lab describes the simulation. It does not run shell commands, network calls or files outside the temporary directory; it does not use an MCP SDK; it does not check transport, authentication or MCP features other than tools. It does not create or edit an automatically running workflow in the repository. It gives no legal opinion. Lints and validators only flag; the loop guard and the limits lint block the run (fail closed); a person decides the thresholds, whether to accept a description change, and every real-world effect.
Terms reused with a different meaning (each lesson has a sentence that separates the senses). tool and function are used interchangeably (L01); schema is the JSON Schema of a tool's parameters, which differs from the schema check of L2-M03-L01; contract here includes the half meant for the model, which is wider than the contract test of L1-M01-L04; validation is checking against a schema, and does not include business rules or authorization (L03); an ambiguous case (several acceptable answers, L02) differs from an edge case (right at the threshold of a constraint, L03); a mock is a fake tool for tests, a sandbox is an isolated zone, and the lab's sandbox differs from an operating-system sandbox (L04); an effect (L04) is a state change beyond the return value; the effect log differs from the trace of L3-M01-L04; server and client in L05 are an MCP server and client, which differ from a web server and the client of a model API; a capability is one side's declaration of the features it supports; stateless is in the sense of the MCP specification revision 2026-07-28; oracle is still the mechanism that decides pass or fail (in L02 it is the expectation table of each case).
B. Learning objectives
| ID | Objective |
|---|---|
| MO1 | Explain a tool definition as a two-half contract, run a contract lint and a validator, and state what they do not check. |
| MO2 | Design and run a tool selection case set with right, wrong, no-tool and ambiguous cases, and read the result as fractions and per-case verdicts without inferring anything about a real model. |
| MO3 | Write adversarial cases for tool parameters by risk family, check paths and hidden characters, and flag instructions planted in tool results. |
| MO4 | Build and test a fake tool layer with an effect log: dry-run, idempotency, allowlist and denylist, approval, limits and budget. |
| MO5 | Check the list and calls of a simulated MCP server: message shape, error codes, version, determinism of the list, and detection of a changed description. |
C. Lessons
| ID | Lesson | Duration | Prerequisite | Concepts | Practical output |
|---|---|---|---|---|---|
| L3-M02-L01 | Defining a tool as a contract | 120' | L3-M01-L05 | two-half contract, well-formed and conform, contract lint, digest and diff | Contract tests for a tool's schema |
| L3-M02-L02 | Testing tool selection | 120' | L01 | three kinds of expectation, five verdicts, no-tool and ambiguous cases, order sensitivity | Right-tool, wrong-tool and no-tool cases |
| L3-M02-L03 | Checking parameters and malicious input | 120' | L02 | the model as an untrusted input, check chain, adversarial case families, safe_path, instructions in tool results |
Adversarial cases for parameters |
| L3-M02-L04 | Fake tools and a sandbox with an effect log | 120' | L03 | effect kinds, dry-run, idempotency, approval, limits, hash-chained log, reconcile |
A sandboxed tool layer with an effect log |
| L3-M02-L05 | MCP for testers: checking the tool list and tool calls of a small server | 150' | L04 | host, client, server, the 2026-07-28 revision with no handshake, two kinds of error, list pinning | Tests for the list and calls of a simulated MCP server |
D. Module assignment
The module assignment (exercises.md): a tool validation test suite for ThuVien Mini v2 (tool contracts, tool selection cases, adversarial cases, a tool layer with an effect log, MCP list and calls, reproduction; acceptance criteria AC1-AC6 and a 100-point rubric) together with one independent challenge (LichHoc). The five independent per-lesson exercises are in code-labs/l3-m02/exercises/ and in §9 of each lesson: fix four broken tools (L01), predict and fix where a policy chooses wrongly (L02), predict the results of twelve calls and write adversarial cases (L03), configure the tool layer and predict a dry-run (L04), predict the answers of the simulated MCP server and write requests (L05).
E. Module assessment
The module quiz quiz.md (12 questions, 20 points, pass mark 70%), the module assignment with acceptance criteria and rubric (exercises.md); the solutions and the instructor guide are for instructors only. The practice for each lesson is practice-01.md to practice-05.md (with .en.md versions), public and with reference answers. The solution set and the instructor's tests are in code-labs/l3-m02/instructor/ and are for instructors only.
F. References
The shared list is in references.md (15 sources re-fetched on 2026-11-04, access dates, how much of each source was read). Each lesson also has its own references table in §12. The MCP specification has dated revisions; every lesson uses the 2026-07-28 revision and says so explicitly.
Objective ↔ assessment matrix
| Objective | Lesson | Independent exercise (§9) | Quiz question | Module assignment criterion |
|---|---|---|---|---|
| MO1 | L01 | exercises/test_l01_contract.py |
Q1, Q6, Q12 | AC1 (and AC6 for the whole module) |
| MO2 | L02 | exercises/test_l02_selection.py |
Q2, Q7, Q9 | AC2 (and AC6 for the whole module) |
| MO3 | L03 | exercises/test_l03_args.py |
Q3, Q11 | AC3 (and AC6 for the whole module) |
| MO4 | L04 | exercises/test_l04_toollayer.py |
Q4, Q8, Q10 | AC4 (and AC6 for the whole module) |
| MO5 | L05 | exercises/test_l05_mcp.py |
Q5, Q12 | AC5 (and AC6 for the whole module) |