Skip to content

feat(protocol): the ATIF builder gives an id for a call id an endpoint repeats, and reads epoch-millisecond times and base64 media - #952

Draft
earakely-scale wants to merge 2 commits into
mainfrom
edgararakelyan/atif-adapter-helpers
Draft

earakely-scale wants to merge 2 commits into
mainfrom
edgararakelyan/atif-adapter-helpers

Conversation

@earakely-scale

@earakely-scale earakely-scale commented Nov 29, 2026 •

Copy link
Copy Markdown
Collaborator

The ATIF builder now gives adapters what eight of them each kept a copy of: the id to write a call under when an endpoint gives a tool-call id again, a time given in epoch milliseconds, and the bytes of base64 text or a data URL. Nothing existing changes. The adapters switch to these in a follow-up, once a release carries them, since each agent's image installs the protocol from PyPI.

What changes

  • turn.tool_call_id(native_id). A call id is unique across a document, but an endpoint may repeat one, as vLLM numbers each response's calls from zero (functions.<name>:<index>). This gives the id to write the call under: the endpoint's own, or, once the document holds it or gave it out, the first of <native_id>#2, #3 and on that it hasn't. The id is reserved when given, so an adapter that takes ids for several calls before writing them gets distinct ones. Its result names that id, so the adapter still decides which of its calls a result answers.
    • Eight adapters (pi, Letta Code, OpenHands, Antigravity, Hermes, browser-use, OpenCode, pydantic-ai) each have their own copy of this loop. When three of them counted instead of skipping taken forms, they could write a duplicate id and stop the copy; that was fixed in each.
    • An id that isn't a non-empty string is refused with the same error tool_call gives.
  • timestamp_ms(value). A time given as an integer count of milliseconds since the Unix epoch, written as timestamp writes a time to the millisecond. It returns None for any other value and for a count past the years a datetime holds; the four adapters' copies raised there.
  • decode_base64(value) and decode_data_url(value). The bytes of base64 text, and the bytes and media type of a data:<type>;base64,... URL, read as b64decode(validate=True) reads them (from Python 3.11 that refuses bad padding too; 3.10 still takes excess =). Each returns None for a value it doesn't read. Nine adapters decode media one of these two ways.
  • The protocol README's ATIF section describes them.

Testing

  • Unit and property tests (test_atif_adapter_helpers.py, 39):
    • Examples: repeats numbered across tasks, each result on its own call; a number skipping a form the endpoint gave as an id of its own; ids given out and ids written without one both taken; sub-agents sharing the document's ids; a bad id refused as tool_call refuses it; times at and around the epoch; bad base64 and malformed data URLs.
    • Hypothesis properties: random sequences of ids given, written and written without one, across tasks, each id the first free form of its native and the document valid (400 examples); ids equal to the loop the adapters copied (400); every millisecond in datetime's range written and read back as itself; base64 and data URLs round-tripping, and decoding agreeing with strict b64decode on any text.
    • Each rule fails a test when broken: ids given out ignored, calls written ignored, numbering counted, the string check dropped, milliseconds truncated, bools taken as times, out-of-range counts raising, lenient base64, a data URL matched by prefix.
  • Chaos of the helpers themselves (kept outside the repo), 30 minutes on 8 workers of a test host:
    • tool_call_id in 1,668,311 random documents built straight through the builder: several tasks, sub-agents, ids given out and written at once, held and written later in any order, or never written, ids of the adapter's own, endpoint ids that already look like x#2, results by the id each call was written under, tasks ending with calls open, and a live page after every operation. Each id given out matched a model of the rule kept in the script, writing one never clashed, every call and result sat where it was written, and every document and its live pages validated. The adapters' own chaos never reaches ids held before they're written, since every adapter today writes a call as soon as it has its id; this does.
    • timestamp_ms, decode_base64 and decode_data_url against reference rules written in the script (datetime arithmetic, a padding-aware base64 reader, a data-URL parser): 333.7 million values, none apart.
    • Eight bugs planted in the builder, each caught: ids given out forgotten until written, repeats counted without skipping taken forms, calls written without an id ignored, numbering afresh each task, numbering from #1, milliseconds dropped, bools read as times, lenient base64.
  • Nothing else changes: the protocol's ATIF tests and every agent's tests pass (3,672).
  • The API was ported before it's published. All eleven adapters were moved onto these helpers on a branch on top of this one (the follow-up), and that branch was checked against main:
    • Every agent's unit and recorded-fixture tests pass, the recordings replaying to the same documents.
    • Each of the eight agents' adapter chaos ran both main's adapter and the ported one on every seed, 900 s each on a test host: 266,230 seeds, every live page, document, media file and kit finding identical.
    • Each helper an adapter had against what replaces it, on random inputs inside and outside the shapes agents give: 13.0 million rounds, identical but for out-of-range millisecond counts (raised before, no time now) and relay records with counts on a call that wasn't answered, which the relay never writes.

🤖 Generated with Claude Code

Confidence Score: 5/5 · The PR appears safe to merge; no blocking issues were found.RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge; no blocking issues were found.

Summary

Adds shared ATIF helpers for repeated tool-call ids, epoch-millisecond times, and base64 media.

  • Repeated endpoint call IDs get a fresh ID in each ATIF document.
  • Adapters can read endpoint times and base64 media with shared helpers.

Reviews (7) · Last reviewed commit: "docs(protocol): decode_base64 says it re..." · Reviewed by Greptile

…t repeats, and reads epoch-millisecond times and base64 media

Eight agents' adapters each kept their own copy of the rule that numbers a
call id the document already holds (`<id>#2`, `#3`, ...), and one copy
that counted instead of skipping taken forms could write a duplicate.
`turn.tool_call_id(native_id)` now gives that id from the document, which
knows every call written and every id given out. `timestamp_ms`,
`decode_base64` and `decode_data_url` replace the epoch-millisecond and
base64 readers several adapters repeat. Nothing else changes: the
adapters adopt these once a release carries them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@earakely-scale
earakely-scale requested a review from a team as a code owner November 29, 2026 06:10
…e) does

Python 3.10's validate=True still takes excess padding, which later
versions refuse, so "padded as it should be" held only from 3.11.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@earakely-scale

Copy link
Copy Markdown
Collaborator Author

@greptileai review

@earakely-scale
earakely-scale marked this pull request as draft November 30, 2026 17:17

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant