Module 18. Agents and Tool Use
Try each exercise first. Expand worked answers or project guidance when needed; their open state is shared between RU/EN.
Download course files (.zip) 2588.1 KBThe archive preserves the source folder structure, both languages, and supporting files.
E1. Context and step latency
A loop begins with 3,000 tokens and appends 1,500 on each of 20 steps. Compare full-history prefill with prefix reuse and find final KV at 128 KiB/token. For one step, add prefill of 1,500 tokens for an 8.03B model at 495 TFLOP/s, decode of 90 tokens at 209.4 tok/s, and a 300 ms tool call.
Show answer and solution
Solution. Without reuse, step processes full history . The arithmetic progression gives tokens. Reuse processes initial prefix once and the 19 increments preceding calls once: , a 10.9524 ratio of processed input positions, excluding the growing cost of reading old KV. Final KV is KiB = 4.0283 GiB.
The conditional prefill estimate is ms. Decode is ms and tool latency 300 ms. Total is 778.466 ms, with decode at 55.21%. This is a conditional scenario without queueing or runtime overhead.
E2. Reliability and parallel accounting
Compute twenty-step success for step probabilities 0.98 and 0.95, without and with one independent retry. Find the per-step probability required for 90% success over 50 steps. Then analyze 20 subagents with 400 work minutes, 5 planning minutes, 20 merge minutes, 30K tokens per worker, and 128 KiB KV/token.
Show answer and solution
Solution. Without retry, every step must succeed: and . With one independent retry, per-step success is , or 0.9996 and 0.9975; raising these to the twentieth power gives 0.99203 and 0.95117. Requiring gives .
Perfect partitioning makes worker time minutes and critical path minutes. Speedups are against useful work and end-to-end. Even infinitely many workers leave 25 serial minutes, imposing 16× and 17× ceilings. KV is KiB = 73.242 GiB. Retry independence and perfect partitioning are strong assumptions.
E3. CodeAct and a reproducible trace
Five JSON actions use 90 tokens each; one CodeAct block uses 160 tokens. Compute both ratios and interpret . Then reproduce a trace that repairs a failed call and returns 27.92.
Show answer and solution
Solution. The JSON path uses tokens and five model/tool round trips; CodeAct uses 160 tokens and one. The ratios are and . The value compares 150K simple mask checks with rough arithmetic for one model token; the work units differ, so the ratio is not a measured time fraction.
The reproducible trace first calls lookup(sensor_bach) and receives tool_error; it corrects the key to sensor_batch and obtains 13.96; then it calls the calculator with 13.96 * 2, obtains 27.92, and returns Answer: 27.92. Event kinds are assistant_action → tool_error → assistant_action → tool_result → assistant_action → tool_result → assistant_final → verification_pass, with three registry invocations, one error, and status completed. The invariant is that the failure becomes an observation rather than uncontrolled execution.
E4 [project]
Build a ReAct-style agent with search, calculator, and a safe local executor. On 20 tasks, report task success, protocol-error rate, tool-error rate, steps, and cost. Then attach a read-only MCP server and repeat the evaluation.
Project demos and guidance
Demo for this project exercise: English project-demo notebook for Module 18, section “Demo 1”. It shows a compact reproducible example on small inputs, not a completed solution to the full-scale project.
E5 [project]
Divide analysis of a ten-file project among subagents. Compare sequential and parallel versions by wall-clock time, total tokens, KV memory, duplicated work, and merge conflicts. Add checkpoint recovery after one worker failure.
Project demos and guidance
Demo for this project exercise: English project-demo notebook for Module 18, section “Demo 2”. It shows a compact reproducible example on small inputs, not a completed solution to the full-scale project.