Skip to main content

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.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

harnessclientprotocol-0.1.0.tar.gz (9.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

harnessclientprotocol-0.1.0-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

File details

Details for the file harnessclientprotocol-0.1.0.tar.gz.

File metadata

  • Download URL: harnessclientprotocol-0.1.0.tar.gz
  • Upload date:
  • Size: 9.2 kB
  • Tags: Source
  • Uploaded using 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}

File hashes

Hashes for harnessclientprotocol-0.1.0.tar.gz
Algorithm Hash digest
SHA256 5bea4b609ca818ee23fbcafc19d503179708a802d6e844faf9964f3e78022a8f
MD5 2564069ad04951f803863bd8ec785ce7
BLAKE2b-256 88072d92bcb80b6d65afbbb0de6c981a06bedfd73b173bd853e65ea5ac7f8469

See more details on using hashes here.

File details

Details for the file harnessclientprotocol-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: harnessclientprotocol-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.9 kB
  • Tags: Python 3
  • Uploaded using 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}

File hashes

Hashes for harnessclientprotocol-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cab1b72dd7da0edc2651a6c85900f0321316626bc8490c105881944b0b8dbb50
MD5 97c22e1a459543eb6da699dfdb0d3784
BLAKE2b-256 77e739926eace5bb9d049968df52c2abd9372a7c8cb803175807aa91bf4609af

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page