Tools

Bilge equips the LLM with 7 coding tools for interacting with your codebase. The LLM autonomously decides which tools to use based on your request.


Overview

ToolDescriptionBest For
read_fileRead file contents with line numbersInspecting code, understanding structure
write_fileCreate or overwrite filesGenerating new modules, configs, scripts
edit_fileExact string replacementTargeted code modifications
run_bashExecute shell commandsRunning tests, git operations, builds
glob_filesFind files by glob patternDiscovering project structure
grep_codeRegex search across filesFinding usages, patterns, definitions
list_directoryList directory contentsExploring directory layout

read_file

Read file contents with line numbers and optional offset/limit.

Parameters

ParameterTypeRequiredDefaultDescription
file_pathStringYesAbsolute or relative path to the file
offsetIntNo1Starting line number
limitIntNo2000Maximum number of lines to read

Behavior

  • Returns file contents with line numbers (e.g., 1│ module Bilge)
  • Lines longer than 2000 characters are truncated with a notice
  • Returns total line count and lines shown
  • Handles missing files with an error message

Example Response

{
  "content": "  1│ module Bilge\n  2│ \n  3│ using HTTP\n...",
  "total_lines": 37,
  "lines_shown": 37
}

write_file

Create or overwrite a file. Parent directories are created automatically.

Parameters

ParameterTypeRequiredDescription
file_pathStringYesAbsolute or relative path
contentStringYesFile content to write

Behavior

  • Creates the file and any missing parent directories
  • Overwrites existing files without warning
  • Returns the number of bytes written

Example Response

{
  "status": "ok",
  "path": "/home/user/project/src/new_file.jl",
  "bytes_written": 256
}

edit_file

Perform exact string replacement in a file. The target string must appear exactly once.

Parameters

ParameterTypeRequiredDescription
file_pathStringYesPath to the file
old_stringStringYesExact string to find (must be unique)
new_stringStringYesReplacement string

Behavior

  • Reads the file and searches for old_string
  • Fails if the string is not found or appears more than once
  • Writes the modified content back to the file
  • Returns the file path on success
Uniqueness Requirement

The old_string must appear exactly once in the file. If it appears multiple times, the tool returns an error asking the LLM to provide a larger, unique context string. This prevents accidental multi-edits.

Example Response

{
  "status": "ok",
  "path": "/home/user/project/src/agent.jl"
}

run_bash

Execute a shell command with a configurable timeout.

Parameters

ParameterTypeRequiredDefaultDescription
commandStringYesShell command to execute
timeout_secondsIntNo120Maximum execution time in seconds

Behavior

  • Runs the command in the agent's working directory
  • Captures stdout and stderr separately
  • Enforces a timeout (default: 120 seconds)
  • Returns exit code, output, and timeout status

Example Response

{
  "exit_code": 0,
  "stdout": "Test Summary...\n  All tests passed!",
  "stderr": "",
  "timed_out": false
}

glob_files

Find files matching a glob pattern.

Parameters

ParameterTypeRequiredDefaultDescription
patternStringYesGlob pattern (e.g., **/*.jl, src/*.toml)
pathStringNoWorking dirDirectory to search in

Behavior

  • Supports * (any characters in filename), ** (recursive directory), and ? (single character)
  • Results sorted by modification time (newest first)
  • Limited to 500 results
  • Returns file paths relative to the search directory

Supported Patterns

PatternMatches
*.jlAll .jl files in current directory
**/*.jlAll .jl files recursively
src/**/*.jlAll .jl files under src/
test/test_*.jlTest files matching prefix
*.{jl,toml}Not supported — use separate calls

Example Response

{
  "files": ["src/agent.jl", "src/tools.jl", "src/repl.jl"],
  "total": 3
}

grep_code

Search file contents with regex patterns.

Parameters

ParameterTypeRequiredDefaultDescription
patternStringYesRegex pattern to search for
pathStringNoWorking dirDirectory to search in
globStringNo""Filter files by glob pattern
context_linesIntNo0Lines of context before and after matches

Behavior

  • Uses grep -rn under the hood with regex support
  • Can filter files by glob pattern (e.g., only search *.jl files)
  • Returns matching lines with file paths and line numbers
  • Supports context lines for surrounding code

Example Response

{
  "matches": "src/agent.jl:115:function process_turn(agent::BilgeAgent, user_input::AbstractString)\nsrc/repl.jl:121:            result = process_turn(agent, input)",
  "exit_code": 0
}

list_directory

List the contents of a directory with file sizes.

Parameters

ParameterTypeRequiredDefaultDescription
pathStringNoWorking dirDirectory to list

Behavior

  • Shows directories with a / suffix
  • Shows files with human-readable sizes
  • Entries sorted alphabetically
  • Returns total entry count

Example Response

{
  "entries": [
    "docs/                      (dir)",
    "src/                       (dir)",
    "test/                      (dir)",
    "Project.toml               378 bytes",
    "README.md                  3551 bytes"
  ],
  "total": 5
}

Tool Limits and Safety

Output Truncation

Tool output is truncated at max_output_chars (default: 100,000 characters) to prevent overwhelming the LLM's context window. A notice is appended when truncation occurs.

Bash Timeout

Shell commands are killed after the timeout (default: 120 seconds) to prevent runaway processes.

Glob Limit

File glob results are capped at 500 entries to prevent excessive output.

Line Truncation

Lines longer than 2000 characters are truncated in read_file output.