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.
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
sayfor the user,actionsto run in order, anddonewhen 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.
- The model sends a reply: a short note and one fenced JSON block with say, actions and done.
- The host runs the actions in order and stops at the first failure.
- The host sends the results back as an observation, the next user message, and the model replies again.
- A reply with done set to true ends the loop.
Why plain text
- 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.
- 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.
- 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.
```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
action 1read_file
- path
- "a.go"
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.
```json
{"say": "Turning on the flag.", "actions": [{"tool": "edit_file", "args": {"path": "config.py", "find": "enabled = False", "replace": "enabled = True", "dry_run": False}}], "done": True}
```What the parser returns
action 1edit_file
- dry_run
- false
- find
- "enabled = False"
- path
- "config.py"
- replace
- "enabled = True"
- done
- true
- explicitDone
- true
- ignoredBlocks
- 0
- say
- "Turning on the flag."
Python True and False outside strings become JSON booleans. From the conformance suite: vector repair-python-true-false, spec section 6.3.
```json
{"say": "Editing.", "actions": [{"tool": "edit_file", "args": {"path": "a.txt", "find": "x", "replace": "y"}}What the parser returns
action 1edit_file
- find
- "x"
- path
- "a.txt"
- replace
- "y"
- done
- false
- explicitDone
- false
- ignoredBlocks
- 0
- say
- "Editing."
A json fence that ends mid-object with no closing fence. From the conformance suite: vector cut-off-in-fence-missing-brace-and-fence, spec section 6.1.
```json
{"say": "Running the tests.", "actions": [{"tool": "shell", "args": {"command": "npm test"}}], "done": false}
```
<observation step="2">
results of your actions:
- shell npm test -> ok: 12 passed
</observation>
```json
{"say": "All tests pass.", "actions": [], "done": true}
```What the parser returns
action 1shell
- command
- "npm test"
- done
- false
- explicitDone
- true
- ignoredBlocks
- 1
- say
- "Running the tests."
The model writes an observation and a final reply after its block; only the first block runs. From the conformance suite: vector imagined-observation-second-block, spec section 6.1.
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
npm install @heurica/tapimport { 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.
pip install heurica-tapfrom heurica_tap import parse, format_result_line, format_observation
result = parse(reply_text) # the model's reply, as plain text
if result.ok:
actions = result.reply.actions
lines = []
for action in actions:
ok, output = run_tool(action.tool, action.args) # your code
lines.append(format_result_line(action.tool, str(action.args), "ok" if ok else "FAILED", output))
if not ok:
break # stop at the first failure
skipped = len(actions) - len(lines)
observation = format_observation(1, lines, skipped=skipped)
# Send the observation back as the next user message.Or let run_agent 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 vectorsHow 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.