heurica-tap
Python library for TAP, the Text Action Protocol. A model uses tools by writing a short note and one fenced JSON block. No native tool-calling API is needed, so TAP works with any chat model. The protocol is specified in SPEC.md.
The package has no runtime dependencies (standard library only).
Install
pip install heurica-tap
To work from a checkout of the repository, run pip install -e . in packages/python.
Requirements: Python 3.9 or newer.
Quick start
from heurica_tap import parse, run_agent
TOOLS = [{
"name": "read_file",
"description": "Read a file.",
"args": {"path": {"type": "string", "required": True}},
"readonly": True,
}]
def read_file(args):
with open(args["path"], encoding="utf-8") as fh:
return fh.read()
def fake_chat(messages, stop=None):
"""Stands in for a real model: returns one reply, then finishes."""
if len(messages) == 2: # only the briefing and the task so far
return ('Reading the file first.\n```json\n'
'{"say": "Reading.", "actions": [{"tool": "read_file", "args": {"path": "notes.txt"}}], "done": false}\n```')
return '```json\n{"say": "The notes are read.", "actions": [], "done": true}\n```'
# parse() reads one reply on its own:
result = parse(fake_chat([{}, {}]))
print(result.ok, result.reply.actions[0].tool) # True read_file
# run_agent() drives the whole loop:
outcome = run_agent(chat=fake_chat, tools=TOOLS, handlers={"read_file": read_file},
task="Summarize notes.txt")
print(outcome.ok, outcome.answer)
chat receives the message list and a stop keyword (the list AGENT_STOPS). It
returns the model's reply text. Use any provider here; see
examples/openai_compatible.py
in the repository for an OpenAI-compatible endpoint.
API overview
| Name | Purpose |
|---|---|
parse(raw) |
Read a reply. Returns ParseResult with ok, reply or error. Never raises on model text. |
normalize_tool_name(name, extra_aliases=None) |
Lowercase, - and spaces to _, then the alias table. |
AGENT_STOPS |
Stop sequences for the model (SPEC 5.2). |
format_result_line(tool, args, status, output) |
One action's line in an observation. |
format_observation(step, lines, skipped=, ignored_blocks=) |
The <observation> envelope. |
describe_parse_error(error) |
Explanation sent back when a reply cannot be used. |
validate_tools(tools) |
Checks a catalog against schema/tools.schema.json. |
render_catalog(tools) |
Deterministic text rendering of the catalog. |
build_briefing(tools, instructions=, name=) |
The system prompt: reply format, rules and catalog. |
run_agent(...) / run_agent_async(...) |
The loop. Handlers and chat may be sync or async. |
Results are dataclasses (Reply, Action, ParseError, ParseResult, AgentResult).
ParseResult.as_dict() and Reply.as_dict() give the camelCase form used by the
conformance vectors.
Behavior notes
- The parser follows the reference (Anvil's
ActionParser.swift) and SPEC section 6. The conformance vectors define the exact results. - Python's
jsondiffers from Foundation in a few places; the parser reproduces the reference: duplicate keys keep the first value, NaN and Infinity are rejected, lone surrogates are rejected, and integers above 2**53 become floats. - The test suite includes all conformance vectors. It reads
conformance/vectors.jsonfrom a checkout of the repository, so runpython3 -m unittest discover -s testsfrom this folder of a checkout. - The alias table is generated:
python3 scripts/gen_aliases.pyrebuildssrc/heurica_tap/aliases.pyfromaliases.json.
License
MIT. See LICENSE.
Metadata
Release files for heurica-tap 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| heurica_tap-0.1.0.tar.gz | 25.1 kB | Without provenance | Details for heurica_tap-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| heurica_tap-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for heurica_tap-0.1.0-py3-none-any.whl |
Total release size: 45.2 kB
Release files / heurica_tap-0.1.0.tar.gz
| Download URL | heurica_tap-0.1.0.tar.gz |
|---|---|
| Size | 25.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d412611f98c6703ca3c4d037ff8fd6d37ba61188dd55fd8c5835ef9f1d00c972
|
|
BLAKE2b-256 checksum How to use checksums |
1378b1eaf6fbc56b3fe17a7ba10e81fe226013c8654f23c7781726879ff428fb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.15.2
|
Release files / heurica_tap-0.1.0-py3-none-any.whl
| Download URL | heurica_tap-0.1.0-py3-none-any.whl |
|---|---|
| Size | 20.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e6c41dc563d15b3ff2cfce9cb4f0fc2663efbef6c5ca2fd10df6f84113d06178
|
|
BLAKE2b-256 checksum How to use checksums |
5e3afd49b0845e9fc995dcfeabb425fd9f5c2d48c82d70c5b8252c3131cb03a3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.15.2
|
Security for heurica-tap 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.