morph-warp-grep-v2.1). Use it to build a custom harness in any language. The API follows the OpenAI chat completions format with native tool calling — you pass tool definitions, the model returns structured tool_calls, you execute them locally and send results back as tool messages.
For a complete implementation, see the Python Guide or the Python agent example. For TypeScript SDK wrappers, see Agent Tool.
Message Flow
The agent runs a multi-turn conversation with max 6 turns using OpenAI-compatible tool calling:| Step | Role | Content |
|---|---|---|
| 1 | user | Repo structure + search query |
| 2 | assistant | tool_calls array (structured JSON) |
| 3 | tool | One message per tool call result |
| 4+ | … | Repeat until finish is called |
Initial User Message
The first user message contains two parts:- Repository structure — flat list of absolute paths (depth 2)
- Search query — what the agent needs to find
The repo structure must be flat absolute paths, one per line. First line is the repo root. No indentation, no tree characters. Directories have no trailing
/.API Call
The model has its tools built in — you do not need to pass atools array. Just send the messages and the model returns structured tool_calls.
Agent Response Format
The model responds with a standard OpenAItool_calls array. No XML parsing needed.
The
content field may contain non-empty text — ignore it and use only the tool_calls array. The finish_reason will be "tool_calls" when the model wants you to execute tools.tool messages:
Tool Definitions
The model calls these tools internally — you don’t need to pass them in the request. However, you need to implement each tool locally to execute the calls the model returns:Executing Tools
When the model returnstool_calls, execute each one locally and return the output as a tool message. Here’s a minimal Python implementation:
Turn Counter
After tool results, add auser message with a turn counter and context budget:
| Turn | Message |
|---|---|
| 1 | You have used 1 turn and have 5 remaining |
| 2 | You have used 2 turns and have 4 remaining |
| … | … |
| 5 | You have used 5 turns, you only have 1 turn remaining. You have run out of turns to explore the code base and MUST call the finish tool now |
If the model does not call
finish within 6 turns, the search failed. Return an empty result to your caller.Output Limits
Tools enforce output limits to prevent context explosion:| Tool | Max Lines | On Exceed |
|---|---|---|
grep_search | 200 | Truncate with warning |
list_directory | 200 | Truncate with warning |
read | 800 | Truncate with warning |
glob | 100 files | Truncate |