Repository navigation
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
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.attachmentson a singlellm.chatcall: a non-empty list whose entries are a path insidellm.attachments.root, or{path, pages}for pages of a PDF (13,1-3,7). The request names a file and never carries one.params.timeout_ms), decides the kind by the first bytes, never by the name, and sends base64imageblocks (PNG, JPEG, GIF, WebP) anddocumentblocks (PDF) before the text of the last turn.pagessends a new PDF with only those pages, in the order named (pypdf, thedocumentsextra).llm.attachments.max.count(20), more bytes of files thanllm.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;pageswithout the extra is a 503 that names it.attachmentsonllm.streamor a loop turn is a 400.requestkeeps 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.llm_attachments,llm_attachment_bytes), never a path or a file's content.tests/vectors/llm-attachments-vectors.json(48 cases), over eight fixture files intests/fixtures/attachments(marked-textin.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.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; thedocumentsextra; hidden entries refused with no switch.Checked:
pytest -q862 passed, 76 skipped;ruff check .clean;basedpyright0 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 tomain.🤖 Generated with Claude Code