Skip to content

Latest commit

 

History

History
258 lines (213 loc) · 13 KB

tools.md

File metadata and controls

258 lines (213 loc) · 13 KB

Tools

The model works by calling tools. Every built-in tool is offered to it beside the tools of any loaded MCP server. The agent loops — call, run, answer with the result — until the task is done, see The agent loop.

The built-in set

Tool What it does Page
bash Run a Bash command below
read Read one numbered page of a file below
write Create or overwrite a whole file below
edit Replace one exact block in a file below
ls List a directory below
apply_patch Apply a Git unified diff Patching
rg / grep Search file contents Searching
fd / find Find files by name Searching
web_search Search the web Web search and fetching
web_fetch Fetch a page as text Web search and fetching
ask_user Put one or more questions to you as a menu Interface
plan Keep the checklist of the work in progress Plan
memory_save, memory_search Save and recall durable notes Memory
announce_task Name the task on the terminal Interface
subagent, report Hand a task to a second agent Sub-agents
load_mcp_tools Load an MCP service's tools on demand MCP servers
load_skill, read_skill_resource Load a skill's instructions, then one of its bundled files Skills

Which search programs are offered is decided once at startup from PATH: rg is preferred over grep, and fd over find. The prompt follows the selection, see Searching.

bash

Runs a command with bash --noprofile --norc -c, not /bin/sh, in the working directory unless the call names another. The command inherits the host environment, permissions and network access — see Security and state.

Argument Required Description
command yes The command line to run
cwd no Directory to run it in, absolute or relative to the working directory
timeout_seconds no Deadline for this call, a whole number of seconds of at least 1; the default is 600 (ten minutes)

cwd is opened once, before the shell starts, and the shell is given that handle rather than a path; a directory that is not there is refused with the path it named, before anything runs. The directory belongs to that one call: the next call runs in the working directory again unless it names one too, and the other tools still resolve their paths from the working directory. It replaces the cd … && … a command would otherwise carry. The call's line always states the directory — the one the call named, or . for the working directory — so where a command runs is read beside the command rather than inferred from a missing argument.

The call returns the merged output and the exit status. A command that runs past the deadline is terminated with its process group, so a background child does not outlive the call. Background processes are not kept across calls. A call that names no deadline gets ten minutes, which is what a build or a test run of this project can take; the tool sets no ceiling above what a call asks for, so a command expected to outlast that says how long it needs rather than being ended short.

The whole of the output is handed over: nothing is trimmed on the way out, so the collector holds what the machine can hold, and a command that prints without end is ended by the deadline rather than by a limit on what it may say. What is too long to show is kept by the cache every tool's long result goes through: an output larger than 8 KiB (8192 bytes) is written to the current run's scratch folder, and the result keeps up to its first 4 KiB with the entry, its line count and its size in bytes, beside the text. A result that already names an entry is never cached again: what is handed to the model is always an entry's own text, never a preview of a preview. Stdout is followed by stderr under a stderr: label, and the counts refer to this normalized, combined text, not the cache-notice lines.

The notice that spells those facts out is not part of the text: a bash result is what the command printed and nothing else, and the notice is written after the call returns, by the cache that kept the rest — the same one every tool's long result is given. A command that printed nothing returns an empty output string; its status fields still describe how it ended.

The result is what the command printed and nothing else. How it ended travels beside the text, in the JSON status fields the model reads: exit_code, timed_out, and termination for a command a signal killed — the signal's name as a shell writes it, SIGTERM. A terminal draws those same fields on the line under the call — ✓ exit 0, ✗ exit 42, ✗ timed out, ✗ SIGTERM — so the ending is stated once, in the same place, for both readers, and never as the first line of the output, where a cached result's preview would not carry it.

ccr_retrieve

Read cached output without rerunning the call that produced it.

Argument Required Description
id yes Cache ID a cached result named
query no Literal substring filter, ignoring ASCII case
offset no 1-based first line, or first matching line with query; default 1
limit no Positive number of lines; defaults to the page capacity

For example, {"id":"012345abcdef","query":"error","offset":1,"limit":20} returns the matching lines as the output holds them. A page carries no line numbers of its own — what is read back is what the tool's result would have been had it fit — so offset counts lines, or matches when query is given, and a partial page tells you the next offset. Cache entries are private to each agent's scratch folder; /new and process exit remove them, and resuming a conversation does not restore old cache entries. An entry is named after its content, so caching the same output twice — a command rerun, a page read again — is one file answered by one ID, and a long task does not fill the folder with copies.

read

Reads one page of a file: offset is the 1-based first line and limit the number of lines, and every returned line is prefixed <number>: so a line reference can be read straight off the output.

Argument Required Description
path yes Path to the file
offset no 1-based number of the first line; defaults to 1
limit no Number of lines; defaults to as many as the page holds

The page holds whole lines only and stops short of the output limit, naming the offset the next page starts at — reading on with that offset repeats and skips nothing. Earlier lines are skipped as a stream, so the back of a file larger than a megabyte can be read without loading it whole. A single line longer than the output limit (minified JSON, say) comes back as its beginning, cut on a UTF-8 boundary, with the suggestion to read the rest with bash.

The numbered lines are the file's own bytes, handed over unchanged — see Result text.

A page already in the conversation is not repeated: a read whose path, page and output are identical to an earlier one is answered with a one-line marker naming that earlier result and the SHA-256 of the contents. The marker is never counted as the earlier result still being there — once it is gone from the context, the page is read in full again, see Sessions.

write

Creates a file or overwrites its entire contents. For an exact block replacement, use edit instead.

Argument Required Description
path yes The file to write
content yes Entire file contents, for creation or full replacement

A write is atomic and keeps the file's permissions.

edit

Replaces exact text in an existing file. The non-empty old_text must match exactly once unless replace_all is true; no match changes nothing, and a match that is not unique is refused rather than guessed at. new_text may be empty to delete the matched text.

Argument Required Description
path yes The file to edit
old_text yes The exact, non-empty text to replace
new_text yes Its replacement
replace_all no Replace every occurrence instead of requiring a unique match (default false)

Occurrences do not overlap: replace_all replaces each place the text is found in what was read, and does not then search the text it inserted.

An edit is atomic and keeps the file's permissions.

The call is drawn as the diff it makes, at the line the old text starts on — one hunk per occurrence when every one of them is replaced:

❯ rename the greeting in greet.txt to hello
  ⚙ edit
  --- greet.txt
  +++ greet.txt
  @@ -2,1 +2,1 @@
  -beta
  +hello
  ✓
    Replaced one exact text block in 'greet.txt' (17 -> 18 bytes)

The line number is counted in the file when the file can be read and still holds that text, and left out of the header when it cannot: what the call asks for is still the change, and the result below it says why nothing was changed. Added and removed lines take the same colours as a patch; see Patching.

ls

Lists a directory. The listing stops short of the output limit and says so rather than cutting a name in half, and honours limit.

Argument Required Description
path no Directory path; defaults to the current directory
limit no Most entries to list, 1–1000; defaults to 100

Output limit

A tool result larger than 8 KiB is cached in the current run's scratch folder: the result keeps the first whole lines up to 4 KiB and then names the cache ID, the line count and the size in bytes, and ccr_retrieve reads the rest back page by page. This is the same cache bash writes to, and an entry is named after its content, so identical output is kept once however often it is produced. One notice says all this, whatever produced the output: it is written by the cache after the call returns, so no tool's text carries a description of another tool's arguments.

  • A result carries the ID of the entry it stands for, and a result that already names one is never cached again: a preview, or a page read back out of an entry, is handed on as it is instead of becoming a preview of a preview.
  • read pages a file and names the offset the next page starts at, so a page the model is walking through says where it stopped.
  • ls and the searches stop short of the limit and say so, so the model narrows the call rather than reading a cut answer as a complete one.
  • bash hands over everything the command printed, however much that is: the collector holds it, and the cache keeps what is too long to show. It is a tool like any other here — no private limit, no cache of its own, and no notice of its own to write.
  • A fetched page, an apply_patch summary, an MCP server's answer and anything else that large is cached the same way. Two results are exceptions: a sub-agent's report, which reaches its caller whole at any size, and load_skill's instructions, which are the procedure the rest of the turn follows rather than output to page through. See Skills.

No tool description quotes the number: the limit lives in the code, not in the prompt.

Result text

A result is the tool's own text, handed to the model as the tool produced it: a file's bytes, a search match, a server's reply, a patch summary. Nothing is sanitised, escaped or rewritten on the way out, so what the model quotes is what it read — escape sequences and bytes that are not UTF-8 included. The terminal is guarded where the preview is written instead, so a result cannot move the cursor or clear the screen it is shown on.

bash is the exception: its body is a program's own, so escape sequences are dropped, a line a carriage return redraws is flattened to what a terminal would have ended up showing, and a tree drawn with the terminal's line-drawing set keeps the corners it showed. A sequence is measured to its real end, so a character set designation takes the bytes it names with it rather than leaving them in the text. A result the tool marks as a failure stays an error, so the model can correct itself.

The model receives a JSON-serialized tool result with output, is_error, exit_code, timed_out, termination, and ccr_id fields. There is no status header. A silent tool has output: ""; status fields describe its outcome. ccr_id is a twelve-character hex string when the result names a cached entry, otherwise null; it is preserved alongside status even when output is a preview. The conversation protocol's Message.content field is unchanged. CCR may replace a long output with a preview and retrieval notice.