---
title: "Tool Calling From Scratch"
url: https://eldan.ai/tutorials/tool-calling-from-scratch
canonical: https://eldan.ai/tutorials/tool-calling-from-scratch
locale: en
language: en
updated: 2026-11-23
author: "Eldan Abdrashim"
cite_as: "Eldan Abdrashim. \"Tool Calling From Scratch.\" Eldan.ai, updated 23 November 2026. https://eldan.ai/tutorials/tool-calling-from-scratch."
---

# Tool Calling From Scratch

> Write the agent loop by hand: tool contracts, validation, budgets and replay tests.

## At a glance

- **Format:** tutorial
- **Level:** intermediate
- **Guided time:** 42 min
- **Lessons:** 5
- **Exercises:** 1
- **How free lessons open:** free for newsletter readers: subscribe with an email on a lesson and confirm it
- **Sections:** 1
- **Language:** English, Russian
- **Price (USD):** USD 0
- **Last updated:** 2026-11-23

Write the agent loop by hand: tool contracts, validation, budgets and replay tests.

## What you will be able to do

- Describe a tool as a name, a description and a JSON Schema
- Write a working agent loop in about thirty lines
- Return validation errors the model can recover from
- Bound a run with step, time and token budgets
- Detect repeated calls and stop loops
- Test the loop with a scripted model and no API key

## Curriculum

1. **Lessons** (42 min)
   - [A tool is a contract, concept, 5 min](https://eldan.ai/tutorials/tool-calling-from-scratch/the-tool-contract)
   - [The agent loop in thirty lines, example, 8 min](https://eldan.ai/tutorials/tool-calling-from-scratch/the-loop)
   - [Validate arguments and return errors the model can use, exercise, 15 min](https://eldan.ai/tutorials/tool-calling-from-scratch/validate-and-recover)
   - [Budgets, loops and guards, concept, 7 min](https://eldan.ai/tutorials/tool-calling-from-scratch/budgets-and-guards)
   - [Trace every run and test the loop without a model, check, 7 min](https://eldan.ai/tutorials/tool-calling-from-scratch/trace-and-test)
