t27.aiРусский

The hands: tools an agent can call

You will learn

What a tool is, which tools an agent may start at once, and which one waits for your yes.

An agent only reads and writes text. It cannot open a file or run a test by itself. A tool is a function the host runs for it: the agent names the tool, the host checks the name against a list, runs it and sends the result back as text. This spec lists 3 tools: 0 read a file, 1 run the tests and 2 write a file. Reading and testing change nothing, so they run at once; writing changes your project, so it waits for your yes. The loop is capped too: of 9 calls asked in one turn the host lets 5 through, so a stuck agent cannot call tools forever. Plant the bug by setting FREE_BELOW to 3 and the test writing_waits_for_a_yes turns red: writing would run without asking.

Try it

Open the widget and name the two tools that run at once; then run the spec, set FREE_BELOW to 3, and read which test fails. Put the line back and run it again.

Open the interactive lesson →

Vibecoding 20: tools an agent can call ↗

Three tools, which run at once and which wait for a yes, and the cap on calls in one turn. Lesson 20 of the Vibecoding from zero course.

specs/vibecoding/agent_hands.t27

// SPDX-License-Identifier: Apache-2.0
; specs/vibecoding/agent_hands.t27 -- vibecoding lesson 20: the hands of an agent, tools it can call.
; An agent only reads and writes text. A tool is a function the host runs for it: the agent names
; the tool, the host checks the name against a list, runs it and sends the result back. Tool ids:
; 0 read a file, 1 run the tests, 2 write a file. The first two run at once; writing waits for the
; owner to say yes. The loop is capped so a stuck agent cannot call a tool forever.
; Run the tests, then plant the bug named at the bottom and watch one test turn red.

module vibecoding_agent_hands;

pub const TOOL_READ : u8 = 0;
pub const TOOL_TEST : u8 = 1;
pub const TOOL_WRITE : u8 = 2;
pub const TOOL_COUNT : u8 = 3;

; A tool with an id below this one runs without asking.
pub const FREE_BELOW : u8 = 2;

; The agent asked for this many calls in one turn; the host lets this many through.
pub const MAX_CALLS : u8 = 5;
pub const ASKED_CALLS : u8 = 9;
pub const RUN_CALLS : u8 = 5;

test reading_runs_at_once {
    assert TOOL_READ < FREE_BELOW;
}

test running_the_tests_runs_at_once {
    assert TOOL_TEST < FREE_BELOW;
}

; The negative control. Writing is not free: its id is not below FREE_BELOW, so the host asks
; the owner first. Plant the bug by setting FREE_BELOW to 3: this test turns red.
test writing_waits_for_a_yes {
    assert TOOL_WRITE >= FREE_BELOW;
}

test every_tool_has_an_id_in_the_list {
    assert TOOL_WRITE < TOOL_COUNT;
    assert TOOL_COUNT == TOOL_WRITE + 1;
}

test the_loop_is_capped {
    assert ASKED_CALLS > MAX_CALLS;
    assert RUN_CALLS == MAX_CALLS;
}

Open the lesson's spec in the player ↗

All lessons