Phase 14: Agent Engineering

Tool Use and Function Calling

Toolformer (Schick et al., 2023) started self-supervised tool annotation. Berkeley Function Calling Leaderboard V4 (Patil et al., 2025) sets the 2026 bar: 40% agentic, 30% multi-turn, 10% live, 10% non-live, 10% hallucination. Single-turn is solved. Memory, dynamic decision-making, and long-horizon tool chains are not. Explain Toolformer's self-supervised training signal: keep tool annotations only when execution reduces next-token loss. Name BFCL V4's five evaluation categories and what each measures. Implement a stdlib tool registry with schema validation, argument coercion, and execution sandboxing. Diagnose the three 2026 open problems: long-horizon tool chaining, dynamic decision-making, and memory. Early tool use asked: can the model predict a correct function call? Modern tool use asks: can the model chain tools across 40 steps, with memory, with partial observability, with recovery from tool failures, without hallucinating tools that do not exist? Toolformer established the baseline: models can learn when to call tools with self-supervision. BFCL V4 defines the 2026 evaluation target. The gap between them is the space production agents live in. Idea: let the model annotate its own pretraining corpus with candidate API calls. For each candidate, execute it. Keep the annotation only if including the tool result reduces loss on the next token. Fine-tune on the filtered corpus. Tools covered: calculator, QA system, search engines, translator, calendar. The self-supervision signal is purely about whether…

Tool Use and Function Calling: Toolformer (Schick et al., 2023) started self-supervised tool annotation. Berkeley Function Calling Leaderboard V4 (Patil et…

This free lesson is part of the AI Engineering from Scratch curriculum. Read the full explanation, run the lesson code, and verify the result in the interactive reader or from the repository source.

Browse the complete course catalog or open this lesson on GitHub.