Skip to main content
A complete Python implementation of the WarpGrep agent loop using OpenAI-compatible tool calling.

Overview

The agent loop:
  1. Send query + repo structure to the API (tools are built in — no tools parameter needed)
  2. Receive structured tool_calls from the response
  3. Execute tools locally (ripgrep, file reads, directory listing, glob)
  4. Send results back as tool messages
  5. Repeat until finish is called (max 6 turns)
Parse tool arguments defensively. The model may send limit or case_sensitive as strings ("50", "false") and grep_search may emit undocumented arguments such as output_lines (an alias for limit). Coerce known keys with the helpers below and ignore anything you do not recognize. The assistant content is null on tool-call turns, and finish returns absolute paths.

Installation

You’ll also need ripgrep installed:

Complete Implementation

Tool Definitions

These are the tools the model calls internally. You don’t need to pass them in the API request (they’re built in), but they’re listed here for reference so you know what to implement locally.

API Client

The model has its tools built in — you don’t need to pass a tools array in the request.

Tool Executors

Each tool call from the model is executed locally. These functions run ripgrep, read files, list directories, and find files by glob pattern.

Tool Dispatcher

Route each tool call to the right executor.

Agent Loop

The main loop ties everything together using standard OpenAI tool calling flow.

Usage

Next Steps