Most users should use the SDK Tool or MCP integration. This page is for advanced use cases where you need custom control over the agent loop.
Two Approaches
SDK Harness Primitives
Use
@morphllm/morphsdk/tools/warp-grep/harness for parsing, formatting, and types. Recommended - battle-tested, type-safe, stays in sync with model updates.Raw API
Hit the API directly with curl. Full control, but you implement everything yourself.
SDK Harness Primitives
The/harness export gives you the building blocks to construct your own agent loop:
Quick Example
Full Working Example
Complete Custom Harness
Complete Custom Harness
API Reference
parseToolCalls(text: string): ToolCall[]
Parse model output into structured tool calls. Automatically removes <think> blocks and extracts <tool_call> tags.
formatToolResult(name, args, output, options?)
Format tool output with XML wrapper for model consumption.
formatTurnMessage(turn: number, maxTurns?: number)
Format turn counter message.
formatAnalyseTree(entries: AnalyseEntry[])
Format directory listing entries as a tree.
resolveFinishFiles(provider, files)
Read file ranges specified in a finish command.
Constants
| Constant | Value | Description |
|---|---|---|
MAX_TURNS | 4 | Maximum agent turns before forced finish |
TIMEOUT_MS | 30000 | Request timeout in milliseconds |
DEFAULT_EXCLUDES | string[] | 60+ patterns to skip (node_modules, .git, dist, etc.) |
SYSTEM_PROMPT | string | The exact system prompt used by the SDK |
Tool Specifications
The model outputs tool calls that you execute locally. Here’s what each tool expects:- grep
- read
- analyse
- finish
Search for regex pattern in files using ripgrep.Syntax:
Provider method:Output format: Ripgrep format
grep '<pattern>' <path>Arguments:| Name | Type | Description |
|---|---|---|
pattern | string | Regex pattern (without quotes in parsed args) |
path | string | Directory or file to search (. for repo root) |
path:line:contentRaw API Access
For full control without SDK dependencies, hit the API directly:- Remove
<think>...</think>blocks - Extract text from
<tool_call>...</tool_call>tags - Parse each line as
command arg1 arg2... - Handle quoted patterns in grep:
grep 'pattern' path
View full system prompt
View full system prompt