Skip to content

feat: the LLM helper app - llm.chat, llm.stream and llm.health on the Anthropic SDK - #38

Merged
acn-ericlaw merged 1 commit into
mainfrom
feat/llm-helper-app
Oct 1, 2026
Merged

acn-ericlaw merged 1 commit into
mainfrom
feat/llm-helper-app

Conversation

@acn-ericlaw

Copy link
Copy Markdown
Collaborator

What

  • examples/llm-helper/: a dedicated function host that gives a Mercury engine an LLM, on the official Anthropic SDK. llm.chat answers once (optional JSON-schema structured output, returned parsed as data), llm.stream relays the model's token batches over the multi-shot reply contract (each batch forwarded the moment it arrives, never gathered), and llm.health is a credential check with no network traffic. Default model claude-opus-5-5; refusal fallbacks on by default (llm.fallbacks=off to disable); request_id, usage and trace annotations on every call; no prompt or completion text in a log. A Backend seam is documented for AWS Bedrock through IAM (planned, not built).
  • One shared contract, 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 of examples/demo_app.py with its resources and a README, and loses its LLM code. The Gemini provider (google-genai) is removed, because the helper serves Claude only.
  • A pack report, the docs nav entry and the CHANGELOG notes (the two READ items below).

Why

The two packs carried two different LLM implementations embedded in their demos (Python in demo_app.py; Node in demo-app.mjs and llm-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's graph.task or 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 of llm.stream, so a test fails if a token batch is held back.

Verification

  • ruff check, basedpyright (0 errors), pytest (187 passed), mkdocs build --strict.
  • Certified live with real Claude calls through the Java and Rust engines, both packs, three layers (a Layer 1 streaming service, an Event Script flow, two graphs); the pack view is 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

  • 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 (the demo forwarded any key), a schema on llm.stream is a 400, and a reply with nothing usable is a 422, never an empty success.
  • examples/demo_app.py and examples/resources/application.yml moved to examples/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

… 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
acn-ericlaw merged commit c6cda5a into main Oct 1, 2026
5 checks passed
@acn-ericlaw
acn-ericlaw deleted the feat/llm-helper-app branch October 1, 2026 23:50
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>
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