Skip to content

TAP the Text Action Protocol

Tool use for any model, in plain text.

TAP lets a model call tools through a short note and one fenced JSON block. No native tool-calling API required.

A model reply
The week number is off by one, so fix it and run the tests.
```json
{"say": "Fixing the off-by-one.",
 "actions": [{"tool": "edit_file", "args": {"path": "src/date.ts", "find": "week", "replace": "week - 1"}},
             {"tool": "shell", "args": {"command": "npm test"}}],
 "done": false}
```
The note
One short sentence of reasoning. The host can show it, and never treats it as an instruction.
The block
say for the user, actions to run in order, and done when the request is complete.
This reply
Two actions in one turn: an edit, then the tests.

The loop

The host sends a briefing with the reply format and the tool catalog. Then the model replies, the host runs the actions and sends back the results, until a reply says it is done.

  1. The model sends a reply: a short note and one fenced JSON block with say, actions and done.
  2. The host runs the actions in order and stops at the first failure.
  3. The host sends the results back as an observation, the next user message, and the model replies again.
  4. A reply with done set to true ends the loop.

Why plain text

  1. 01

    Fewer round trips

    One reply can carry a whole batch of actions: read three files, or make an edit and then run the tests.

  2. 02

    Smaller prompts

    The tool catalog is a short block of text that stays identical every turn, so it caches well. No JSON schemas on every request.

  3. 03

    Any model

    If a model can follow a format, it can use tools. That includes small, cheap and self-hosted models.

Imperfect models are expected

Models make formatting mistakes. TAP specifies how a host reads imperfect replies as carefully as it specifies the format: trailing commas, Python literals, missing braces, a model writing its own observation.

Repairs never change the contents of a JSON string, because those are often file contents.

What the model wrote
```json
{"say": "Reading two files.", "actions": [{"tool": "read_file", "args": {"path": "a.go"}}, {"tool": "read_file", "args": {"path": "b.go"}},], "done": false}
```

What the parser returns

  1. action 1read_file

    path
    "a.go"
  2. action 2read_file

    path
    "b.go"
done
false
explicitDone
true
ignoredBlocks
0
say
"Reading two files."

Trailing comma after the last action in the array. From the conformance suite: vector repair-trailing-comma-array, spec section 6.3.

Inputs and results are copied verbatim from conformance/vectors.json.

Install and use

Parse a reply, run its actions in order, and send back the observation.

Dependencies
Zero runtime dependencies.
Requires
Node 20 or later, or Python 3.9 or later
License
MIT
Install
npm install @heurica/tap
TypeScript
import { parse, formatResultLine, formatObservation } from "@heurica/tap";

const result = parse(replyText); // the model's reply, as plain text
if (result.ok) {
  const { actions } = result.reply;
  const lines: string[] = [];
  for (const action of actions) {
    const { ok, output } = await runTool(action.tool, action.args); // your code
    lines.push(formatResultLine(action.tool, JSON.stringify(action.args), ok ? "ok" : "FAILED", output));
    if (!ok) break; // stop at the first failure
  }
  const skipped = actions.length - lines.length;
  const observation = formatObservation(1, lines, { skipped });
  // Send the observation back as the next user message.
}

Or let runAgent drive the whole loop with your own chat function and tool handlers. See the package README.

150 test vectors. Two libraries. Both pass every one.

Each vector is raw model text in and the exact parse result out. The TypeScript and Python libraries run the same file in their tests, which keeps them equivalent.

TAP was extracted from Anvil, our coding agent, which uses it today.

Browse the vectors

How it relates to MCP

TAP is the format of the conversation between a model and its host. MCP is how a host connects to tool servers. They work together: a host can speak TAP with the model and call MCP servers behind its tool handlers.

Native tool calling is the better choice when a model supports it well and you want one call per turn. TAP is for when you want batches, a small prompt, or a model that has no tool calling at all.

Start with the spec.

MIT licensed. Version 0.1 draft.