feat: the LLM helper app - llm.chat, llm.stream and llm.health on the Anthropic SDK - #38
Merged
Merged
Conversation
… Anthropic SDK The dedicated function host that gives a Mercury engine an LLM: examples/llm-helper/ (llm_helper.py, README, resources) serves llm.chat (one answer, with optional JSON-schema structured output), llm.stream (the model's token batches, each forwarded the moment it arrives and never gathered) and llm.health (a credential check with no network traffic) on the official Anthropic SDK. The default model is claude-opus-5-5, refusal fallbacks are on by default, and a Backend seam is documented for AWS Bedrock through IAM (planned, not built). One shared contract file, tests/vectors/llm-helper-vectors.json (byte-identical in mercury-nodejs), runs 63 cases against a fake of the SDK. tests/test_llm_helper.py adds the tests a vector cannot express, 86 in all: token batches are never held back, no prompt text reaches a log, the deadline cancels the call, trace annotations, the backend seam. The demo is a plain demo again: examples/demo_app.py moves to examples/demo-app/ with its resources and a README, and loses its LLM code. The Gemini provider (google-genai) is gone, because the helper serves Claude only. READ: the contract is stricter than the demo nodes were. A params key outside provider, model, max_tokens, timeout_ms, effort and stop_sequences is a 400, a schema on llm.stream is a 400, and a reply with nothing usable is a 422, never an empty success. Each example now lives in a folder of its own: examples/demo_app.py and examples/resources/ moved. Certified live through the Java and Rust engines (docs/test-reports/llm-helper-certification.md). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
acn-ericlaw
added a commit
that referenced
this pull request
Oct 2, 2026
…the Bedrock and release-catch-up threads Records the LLM helper app that merged in PR #38: the llm-helper-app decision (the contract, never-buffered progressive rendering, Opus 5.5 default with the 2000-token demo budgets and the Haiku alternative, the shared vector file with the Node pack, the live certification), the one-folder-per-example convention, and two open threads (AWS Bedrock through IAM as the second backend; the next pack release catching up to the Java number). The llm extra is now anthropic only in the stack fact, and instructions.md names the new example paths. Co-Authored-By: Claude Sonnet 5.5 <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
examples/llm-helper/: a dedicated function host that gives a Mercury engine an LLM, on the official Anthropic SDK.llm.chatanswers once (optional JSON-schema structured output, returned parsed asdata),llm.streamrelays the model's token batches over the multi-shot reply contract (each batch forwarded the moment it arrives, never gathered), andllm.healthis a credential check with no network traffic. Default modelclaude-opus-5-5; refusal fallbacks on by default (llm.fallbacks=offto disable);request_id, usage and trace annotations on every call; no prompt or completion text in a log. ABackendseam is documented for AWS Bedrock through IAM (planned, not built).tests/vectors/llm-helper-vectors.json, byte-identical in mercury-nodejs: 63 cases run against a fake of the SDK in each pack, so the two helpers cannot drift apart.tests/test_llm_helper.py(86 tests in all) adds what a vector cannot express: batches are never held back, no prompt text in a log, the deadline cancels the call, trace annotations, the backend seam. No token is spent and no credential is needed.examples/demo-app/: the demo moves out ofexamples/demo_app.pywith its resources and a README, and loses its LLM code. The Gemini provider (google-genai) is removed, because the helper serves Claude only.Why
The two packs carried two different LLM implementations embedded in their demos (Python in
demo_app.py; Node indemo-app.mjsandllm-nodes.mjs), and the earlier real-provider drives were against Gemini. The engines stay LLM-free by design: an AI node is a plain function on a polyglot host that a graph'sgraph.taskor a flow task reaches over Event-over-HTTP, and the certified graph decides control flow while the model advises within it. One bounded helper with one contract, proven against both engines with real calls, makes that reusable. Progressive rendering is the point ofllm.stream, so a test fails if a token batch is held back.Verification
ruff check,basedpyright(0 errors),pytest(187 passed),mkdocs build --strict.docs/test-reports/llm-helper-certification.md, the full report is in the two engine PRs. Every token batch the helper forwarded reached the engine edge as its own frame, the error contract holds on the real SDK, and every trace rebuilds as one tree.READ
paramskey outsideprovider,model,max_tokens,timeout_ms,effortandstop_sequencesis a 400 (the demo forwarded any key), aschemaonllm.streamis a 400, and a reply with nothing usable is a 422, never an empty success.examples/demo_app.pyandexamples/resources/application.ymlmoved toexamples/demo-app/; the routes and the default port (8086) are unchanged.Not here: the Bedrock/IAM backend, and a release (the pack is at 4.12.15 and ships this with its next catch-up to the Java number). The engine docs that name the new
examples/demo-app/path are in the engine PRs, so merge this one first or together with them.Co-Authored-By: Claude Sonnet 5.5 noreply@anthropic.com
🤖 Generated with Claude Code