harnessclientprotocol
The client half of the Unified Harness Protocol, without the HTTP.
Agent tasks take minutes, arrive as a stream of fragments, and fail in ways that are sometimes worth retrying and sometimes not. This package is the mechanics of getting that right — decoding the event stream, noticing a dropped event, assembling text out of deltas, generating idempotency keys, and classifying failures.
There is no network code here. Give it bytes or events; it gives you facts. Bring your own
transport, or use harnessrouter, which is this plus
HTTP.
pip install harnessclientprotocol
Decode a stream
from harnessclientprotocol import SseDecoder, TaskAccumulator
task = TaskAccumulator()
decoder = SseDecoder()
for chunk in response: # any iterable of body chunks
for event in decoder.push(chunk):
task.add(event)
if event["type"] == "response.output_text.delta":
print(event["delta"], end="", flush=True)
task.status # 'completed' | 'failed' | 'incomplete' | 'cancelled'
task.text # the assistant's text, from the terminal event where available
task.tool_calls # the tools the agent invoked
task.annotations # artifact citations — the files it wrote
task.sequence # (False, [7]) when the stream dropped an event
TaskAccumulator treats the terminal event as authoritative and the deltas as an optimisation,
which is the right way round: a dropped connection mid-stream should cost latency, not correctness.
Retry without running the agent twice
from harnessclientprotocol import idempotency_key, is_retryable, backoff_seconds
key = idempotency_key() # attach to every attempt of the same task
is_retryable(code="session_busy") # True — wait for the in-flight task, then retry
is_retryable(code="quota_exhausted") # False — nothing changes until the quota does
backoff_seconds(2, retry_after=30) # 30.0 — the server's own answer wins
Reuse the key across retries. A retry after a timeout without one runs the task a second time, and the first may still be running, editing the same files. It is the most damaging mistake a UHP client can make, and one header prevents it.
Everything exported
| Export | What it does |
|---|---|
SseDecoder |
Incremental SSE decoding; holds partial frames until the rest arrives |
iter_events(chunks) |
Decode an iterable of body chunks into events |
TaskAccumulator |
Stream → the state a user interface actually needs |
output_text(response) |
Assistant text from a finished response object |
artifacts(response) |
The files a task produced, from the message annotations |
idempotency_key() |
A fresh key for a task and all its retries |
backoff_seconds(attempt, ...) |
Exponential backoff with full jitter, deferring to Retry-After |
is_retryable(...), check_sequence(events) |
Re-exported from unifiedharnessprotocol |
Specification
https://github.com/HarnessRouter/harnessrouter/tree/main/protocol
Apache-2.0.
Metadata
Release files for harnessclientprotocol 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 |
|---|---|---|---|---|
| harnessclientprotocol-0.1.0.tar.gz | 9.2 kB | Without provenance | Details for harnessclientprotocol-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| harnessclientprotocol-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for harnessclientprotocol-0.1.0-py3-none-any.whl |
Total release size: 19.1 kB
Release files / harnessclientprotocol-0.1.0.tar.gz
| Download URL | harnessclientprotocol-0.1.0.tar.gz |
|---|---|
| Size | 9.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5bea4b609ca818ee23fbcafc19d503179708a802d6e844faf9964f3e78022a8f
|
|
BLAKE2b-256 checksum How to use checksums |
88072d92bcb80b6d65afbbb0de6c981a06bedfd73b173bd853e65ea5ac7f8469
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.10.10 {"installer":{"name":"uv","version":"0.10.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / harnessclientprotocol-0.1.0-py3-none-any.whl
| Download URL | harnessclientprotocol-0.1.0-py3-none-any.whl |
|---|---|
| Size | 9.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
cab1b72dd7da0edc2651a6c85900f0321316626bc8490c105881944b0b8dbb50
|
|
BLAKE2b-256 checksum How to use checksums |
77e739926eace5bb9d049968df52c2abd9372a7c8cb803175807aa91bf4609af
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.10.10 {"installer":{"name":"uv","version":"0.10.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for harnessclientprotocol 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.