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 1) - #82

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
Collaborator

What

RFC-0016 in mercury-composable (Accenture/mercury-composable#668), build plan step 1, Python first (the Node twin follows in lockstep). Part of #78. Stacked on the pull request for RFC-0015 (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, off the event loop and inside the call's deadline (params.timeout_ms), 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 (pypdf, the documents extra).
  • 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 extra is a 503 that names it. attachments on llm.stream or a loop turn is a 400.
  • 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. A new shared file, tests/vectors/llm-attachments-vectors.json (48 cases), over eight fixture files in tests/fixtures/attachments (marked -text in .gitattributes, since their digests are pinned), and six tests: an image's limit by backend, the helper without the PDF library, the deadline over the read and the worker thread, the log, the start with a folder that is not one. 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 request behind #78 was reviewed and amended: one folder instead of several, the provider's limits by backend, the read inside the deadline, the hash taken at the read, and the folder stated as readable through the model by every caller of the helper.

The maintainer's direction, recorded in the thread: the shared folder is configured in the helper and filled before a graph runs; a later iteration downloads from an object store into it. The helper reads the file and sends its bytes; the model reads nothing on the host.

Defaults set without a ruling (each is an open question of RFC-0016): one root; the byte bound on source files; no page limit of the helper's own; not on llm.stream; the documents extra; hidden entries refused with no switch.

Checked: pytest -q 862 passed, 76 skipped; ruff check . clean; basedpyright 0 errors. Thirty-one 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 the measurement of a PDF cut beside a running stream.

After the first pull request is squashed, this branch is rebased onto main (git rebase --onto main feat/llm-chat-single-call-audit feat/llm-chat-attachments) and its base set to main.

🤖 Generated with Claude Code

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

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 off the event loop 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 new shared file tests/vectors/llm-attachments-vectors.json (48 cases)
over eight fixture files and six tests pin it; thirty-one mutations of the
code, the file and a fixture were each caught by a test. Part of #78.

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 06:10
@acn-ericlaw
acn-ericlaw merged commit c367951 into main Nov 24, 2026
5 checks passed
@acn-ericlaw
acn-ericlaw deleted the feat/llm-chat-attachments branch November 24, 2026 06:10
acn-ericlaw added a commit that referenced this pull request Nov 24, 2026
…ts on main

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
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