Overview
Tools are self-contained modules inagent/tools/. Each module exposes two callables:
tool_info()— returns metadata used to build the tool-use prompt.tool_function— the callable invoked when the agent emits a tool call.
agent/tools/__init__.py) discovers and imports all tool modules at runtime.
load_tools
Signature
Parameters
Logging function called with a single string on import errors.
[]— returns an empty list; no tools are active.'all'— loads every*.pyfile inagent/tools/except__init__.py.- A list of stem names (e.g.
['bash', 'editor']) — loads only the named modules.
Return Value
List of tool dicts. Each dict has three keys:
Discovery Behaviour
The loader usesimportlib.import_module to import each candidate. A module is only included if it has both tool_info and tool_function attributes. Any module that lacks either attribute or raises an exception during import causes load_tools to re-raise the exception after logging it — partial tool sets are never silently returned.
Tool Call Format
The model emits tool calls as JSON wrapped in<json> tags:
tool_output field:
multiple_tool_calls=True is passed to chat_with_agent.
Built-in Tools
bash
Runs shell commands in a stateful bash session. Session state (environment variables, working directory, background processes) persists across calls within the same chat_with_agent invocation.
Tool name: bash
Description (as shown to the model):
tool_function(command)
The shell command to execute.
"\nError:\n" separator. Returns an error string prefixed with "Error: " on session or timeout failures.
Implementation details:
- Runs via
asyncio.run(tool_function_call(command)). - Each call creates a fresh
BashSessionthat spawns/bin/bash -i. - Output is collected by waiting for a sentinel string (
<<exit>>) appended after the command. - Timeout: 120 seconds. Exceeding it sets an internal
_timed_outflag and raisesValueError. filter_errorstrips spuriousioctlnoise from stderr before returning.
editor
Views, creates, and edits files. Edit history is tracked in-process so individual edits can be undone.
Tool name: editor
Description (as shown to the model):
tool_function(command, path, ...)
Operation to perform. One of
view, create, str_replace, insert, or undo_edit.Absolute path to a file or directory.
Required for
create. The full content of the file to create.Required for
str_replace. The exact string to locate in the file. Must appear exactly once or the replacement is rejected.Required for
str_replace (replacement text) and insert (text to insert).Required for
insert. New content is inserted after this 1-based line number. Pass 0 to insert before the first line.Optional for
view on a file. [start, end] (1-based). Use [start, -1] to read to end-of-file.<response clipped> marker inserted in the middle.
Command reference:
| Command | Effect |
|---|---|
view | Print file with line numbers (cat -n) or list directory (2 levels deep) |
create | Create a new file. Fails if the path already exists |
str_replace | Replace an exact, unique substring in the file |
insert | Insert lines after a given line number |
undo_edit | Revert the last str_replace or insert on the given path |
FileHistory instance (a dict of path → stack of previous contents). Only the most recent edit per file can be undone per undo_edit call.