Skip to content

feat(llm-helper): attachments on a single llm.chat call - images and PDF pages named by reference and read by the helper (RFC-0016, step 2) - #145

Merged
acn-ericlaw merged 1 commit into
mainfrom
feat/llm-chat-attachments
Nov 24, 2026
Merged

acn-ericlaw merged 1 commit into
mainfrom
feat/llm-chat-attachments

Conversation

@acn-ericlaw

Copy link
Copy Markdown
Contributor

What

RFC-0016 in mercury-composable (Accenture/mercury-composable#668), build plan step 2: the Node twin of Accenture/mercury-python#82. The field request is Accenture/mercury-python#78. Stacked on #144 (feat/llm-chat-single-call-audit): this one's diff is the attachments alone, and its audit part needs the first.

  • attachments on a single llm.chat call: a non-empty list whose entries are a path inside llm.attachments.root, or {path, pages} for pages of a PDF (13, 1-3,7). The request names a file and never carries one.
  • The helper reads the file in its folder, decides the kind by the first bytes, never by the name, and sends base64 image blocks (PNG, JPEG, GIF, WebP) and document blocks (PDF) before the text of the last turn. pages sends a new PDF with only those pages, in the order named.
  • In a worker thread, in a module of its own (extensions/llm-helper/attachments.mjs). A hash, base64 and a PDF's cut are CPU work, and the helper's event loop carries every other call and every stream, so the reading never runs on it. The Python twin uses a thread of its pool for the same reason.
  • One deadline. params.timeout_ms covers the reading and the model: the caller has its 408 at the deadline whatever a read is doing, and the model call gets what the reading left.
  • One folder, resolved once at start, with the agent tools' workspace rules: a relative path, the resolved path inside the folder (a path that climbs out and a link that leads out are refused), no hidden entry, a regular file.
  • Refused before any model call, by name: more files than llm.attachments.max.count (20), more bytes of files than llm.attachments.max.bytes (20 MB, from the files' sizes before they are read), an image over the backend's limit base64-encoded (10 MB on the Claude API, 5 MB on Amazon Bedrock), an encrypted or unreadable PDF, a page the document does not have. No folder configured is a 503; a folder that is not one stops the application at start; pages without the PDF package is a 503 that names it. attachments on llm.stream or a loop turn is a 400.
  • A new optional package, @cantoo/pdf-lib (MIT, the maintained fork of pdf-lib; the maintainer's choice). It cuts pages and tells an encrypted PDF; pdfjs-dist, already here for the agent tools, only reads. A devDependency here, installed where pages are used; without it a whole document goes as it is. The lockfile gains it and its four dependencies (tslib, culori, fflate, node-html-better-parser). npm install also moved jose into alphabetical order in package.json.
  • The audit (with the audit of a single call): the turn's request keeps each file as {type: attachment, path, pages, media_type, bytes, sha256}, the size and the hash of the source file as it was read, never its bytes.
  • Logs and traces carry the count and the bytes (llm_attachments, llm_attachment_bytes), never a path or a file's content.
  • Tests. The shared file test/vectors/llm-attachments-vectors.json (48 cases) over the eight fixture files of test/fixtures/attachments (marked -text in .gitattributes, since their digests are pinned), all byte for byte the Python pack's, and seven tests: an image's limit by backend, the helper without the PDF package, the deadline over the read, the worker thread, the log, the start with a folder that is not one. Every case passed with no change to a case or a message: the two helpers answer the same statuses in the same words. A cut PDF is checked page by page, never byte for byte.
  • README ("Attachments": who reads the file, the shared folder, what it costs, the folder as readable through the model, what the audit keeps), resources/application.yml, CHANGELOG, the thread.

Why

A bounded AI node that has to read a page - a scanned form, a table printed as an image, a chart, chosen pages of a long PDF - could not give the model what it had to read: text extracted outside the graph loses the layout, and a file's bytes in the request are too large for the event and would reach every log, trace and stored record. The Python pack has taken files by reference since Accenture/mercury-python#82; the two helpers speak one contract, so this pack takes the same field, the same limits and the same messages, proven by the same vector file and fixtures.

Read before merging: every caller that can reach the helper can have a file of the folder sent to the provider and read back in the reply. The folder is deployment configuration, and the README says so.

Defaults: the Python step's, which are RFC-0016's open questions as proposed (one root; the byte bound on source files; no page limit of the helper's own; not on llm.stream; hidden entries refused with no switch).

Checked on the full tree, installed with npm ci from the new lockfile: npm test 827 tests, 751 passed, 0 failed, 76 skipped. Thirty-three mutations of the code, the vector file and a fixture, applied one at a time, were each caught by a test. Not done: no live call with an attachment (no token was spent), and no measurement of a PDF cut beside a running stream, which the worker thread answers by construction only.

After the first pull request is merged and its branch deleted, GitHub moves this one's base to main, as it did for the Python pair.

🤖 Generated with Claude Code

…PDF pages named by reference and read by the helper (RFC-0016, step 2)

llm.chat took text only, so a bounded AI node that had to read a page could
not show it to the model. A request may now name files inside
llm.attachments.root: the helper reads them in a worker thread and inside the
call's deadline, decides the kind by the first bytes and sends base64 image
and document blocks before the last turn's text; pages cuts a PDF to the
pages named. One root with the agent tools' workspace rules, the provider's
limits checked before any model call, never on llm.stream or a loop turn.
With the audit of a single call, the record keeps a reference with the source
file's size and SHA-256, never its bytes. The Node twin of
Accenture/mercury-python#82.

The reading is a module of its own, attachments.mjs, run in a worker thread:
a hash, base64 and a PDF's cut are CPU work, and the helper's event loop
carries every other call and stream. A new optional package, @cantoo/pdf-lib
(a devDependency here), cuts pages and tells an encrypted PDF.

The shared file test/vectors/llm-attachments-vectors.json (48 cases) over
eight fixture files, all byte for byte the Python pack's, and seven tests pin
it; thirty-three mutations of the code, the file and a fixture were each
caught by a test.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Base automatically changed from feat/llm-chat-single-call-audit to main November 24, 2026 07:01
@acn-ericlaw
acn-ericlaw merged commit d8713c0 into main Nov 24, 2026
5 checks passed
@acn-ericlaw
acn-ericlaw deleted the feat/llm-chat-attachments branch November 24, 2026 07:01
acn-ericlaw added a commit to Accenture/mercury-composable that referenced this pull request Nov 24, 2026
…of both features merged

Step 2 of both build plans is on main in the Node pack:
Accenture/mercury-nodejs#144 (the audit of a single call) and
Accenture/mercury-nodejs#145 (attachments). The two RFC entries do not record
it yet.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
acn-ericlaw added a commit that referenced this pull request Nov 24, 2026
…ents on main

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
acn-ericlaw added a commit to Accenture/mercury-composable that referenced this pull request Nov 24, 2026
…e pack, and the Node twin's PDF library as the maintainer's choice (#670)

Each entry's resolution records step 2 as built and merged
(Accenture/mercury-nodejs#144 and Accenture/mercury-nodejs#145): the Node
twin from the same shared vector files and fixtures, what proves it, where
it differs from the Python helper by its runtime and what the step did not
do. In RFC-0016 the Node twin's PDF library leaves the open questions: the
maintainer chose @cantoo/pdf-lib, and the shared vectors assert a cut
document by its pages. Both entries stay Open. The threads and the session
log follow.

Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
acn-ericlaw added a commit to Accenture/mercury-python that referenced this pull request Nov 24, 2026
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