Skip to main content

Overview

Tools are LLM-callable functions that extend the agent’s capabilities. Pi includes built-in tools for file operations and command execution, and supports custom tools through the extension system.

Built-in Tools

Pi provides six core tools for working with codebases:

read

Read file contents with automatic truncation:
Features:
  • Automatic truncation (2000 lines or 50KB)
  • Line-numbered output (cat -n format)
  • Binary file detection
  • Full output saved to temp file if truncated
Location: packages/coding-agent/src/core/tools/read.ts

bash

Execute shell commands:
Features:
  • Streams stdout/stderr combined
  • Automatic truncation (last 2000 lines or 50KB)
  • Full output saved to temp file if truncated
  • Process tree cleanup on abort
  • Custom shell configuration support
Location: packages/coding-agent/src/core/tools/bash.ts

edit

Edit files using exact string replacement:
Features:
  • Validates that oldString exists exactly once (unless replaceAll)
  • Preserves file encoding and line endings
  • Returns diff for verification
  • Fails fast if oldString not found or ambiguous
Location: packages/coding-agent/src/core/tools/edit.ts

write

Create or overwrite files:
Features:
  • Creates parent directories automatically
  • Overwrites existing files
  • Returns confirmation with file size
Location: packages/coding-agent/src/core/tools/write.ts

grep

Search file contents using regex:
Features:
  • Regex search across files
  • Glob pattern filtering
  • Sorted by modification time
  • Line number display
Location: packages/coding-agent/src/core/tools/grep.ts

find

Find files by name pattern:
Features:
  • Fast glob-based search
  • Sorted by modification time
  • Respects .gitignore by default
Location: packages/coding-agent/src/core/tools/find.ts

Tool Interface

All tools implement the AgentTool interface:
Location: packages/agent/src/types.ts:146

Creating Custom Tools

Basic Example

Create a simple tool using the extension API:

Streaming Updates

Tools can stream partial results during execution:

Abort Handling

Respond to user interrupts using the abort signal:

Custom Tool Rendering

Tools can provide custom UI rendering for their calls and results:

Tool Operations

Advanced tools can use custom operations for delegation:

Bash Operations

Override how bash commands execute:
Location: packages/coding-agent/src/core/tools/bash.ts:33

Tool Hooks

Extensions can intercept and modify tool execution:

Block Tool Calls

Modify Tool Results

Tool Selection

Control which tools are active:
Tools can also be selected via CLI:

Best Practices

TypeBox provides runtime validation and automatic type inference:
Use onUpdate to provide feedback during execution:
Always check signal.aborted in loops and clean up resources:
The details field is for UI/logging, not the LLM. Use it for rich information:

Next Steps

Extensions

Learn about the extension system

Architecture

Understand the system architecture