CodingAgent.Tools (CodingAgent v0.1.0)

Copy Markdown View Source

Built-in coding tools, defined as ReqLLM.Tool structs so they can be handed straight to ReqLLM.generate_text/3 via the :tools option.

Each tool's callback does the real work and returns {:ok, result} / {:error, reason}, matching ReqLLM.Tool.execute/2's contract.

read/write/edit never touch the real filesystem. They operate on an in-memory map of path => content held in the process dictionary of whichever process executes them (a CodingAgent.Session runs its whole agent loop, tool calls included, in its own GenServer process, so this map is effectively per-session state). CodingAgent.Session seeds this map before each turn via seed_files!/1 and collects it back via take_files/0, then hands it to the caller -- the caller decides whether and how to persist it to disk. There is no shell/bash tool: the agent has no way to reach the real filesystem or run commands, by design.

Summary

Functions

The default toolset: virtual filesystem + skill invocation, given the session's skills.

Replace an exact, unique substring in a virtual file.

Read a virtual file, optionally a line range, with line numbers (like cat -n).

Loads files into the calling process's virtual filesystem, replacing whatever was there.

Invoke a skill by name, loading its full instructions into the conversation as a tool result -- the same mechanism Claude Code uses to run a Skill "within the main conversation" rather than as a sub-agent.

Removes and returns the calling process's current virtual filesystem.

Write content to a virtual file, creating or overwriting it in the in-memory workspace.

Functions

defaults(skills \\ [])

The default toolset: virtual filesystem + skill invocation, given the session's skills.

edit()

Replace an exact, unique substring in a virtual file.

read()

Read a virtual file, optionally a line range, with line numbers (like cat -n).

run_edit(params)

run_read(params)

run_skill(skills, map)

run_write(map)

seed_files!(files)

@spec seed_files!(%{required(String.t()) => String.t()}) :: :ok

Loads files into the calling process's virtual filesystem, replacing whatever was there.

skill(skills)

Invoke a skill by name, loading its full instructions into the conversation as a tool result -- the same mechanism Claude Code uses to run a Skill "within the main conversation" rather than as a sub-agent.

skills is the list of CodingAgent.Skill.t() available to the session.

take_files()

@spec take_files() :: %{required(String.t()) => String.t()}

Removes and returns the calling process's current virtual filesystem.

write()

Write content to a virtual file, creating or overwriting it in the in-memory workspace.