LlmToolkit.CodeTools (llm_toolkit v0.1.0)

Copy Markdown View Source

Base code tools implementing LlmToolkit.ToolResolver.

Provides 12 tools every agentic consumer needs to interact with a filesystem, shell, and the web.

Tools

ToolPurpose
read_fileRead file contents with offset/limit
write_fileWrite or overwrite a file
edit_fileExact-match single edit (pi safety model)
multi_editMultiple edits in one call with rollback
append_to_fileAppend content to a file
bashExecute shell commands
grepSearch file contents (ripgrep)
globFind files by name pattern
list_directoryList directory contents
treeVisual directory tree with sizes
file_infoFile metadata (size, type, mtime)
http_getFetch a URL

Safety Model

The edit_file tool uses exact string matching with uniqueness validation — the same model as pi's edit tool: oldText must match exactly once before any write occurs. No silent corruption.

multi_edit extends this with transactional semantics: if any edit in the batch fails, all changes are rolled back. The file is never left in a partial state.

Path Resolution

All file paths are resolved relative to cwd. When called through resolve/1 (the ToolResolver callback), cwd defaults to ".". When called through resolve/2, the caller provides the working directory.

Summary

Functions

Resolve and execute a tool call within the given working directory.

Functions

resolve(call, cwd)

@spec resolve(LlmToolkit.Tool.Call.t(), String.t()) ::
  {:ok, String.t()} | {:error, String.t()}

Resolve and execute a tool call within the given working directory.

The cwd parameter is the dispatch working directory. Falls back to "." if no cwd is provided (via resolve/1).