Skip to content

Commit 1a68668

Browse files
acn-ericlawclaude
andcommitted
memory: the LLM helper app (PR #38) - session log, helper facts, and 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>
1 parent c6cda5a commit 1a68668

5 files changed

Lines changed: 91 additions & 3 deletions

File tree

‎memory/continuity.md‎

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@
3737
<!-- id: stack-python-hatchling | created: 2026-08-22 | last_used: 2026-09-23 | uses: 6 | tier: active | origin: 2026-08-22-171555 -->
3838
- Runtime deps: `aiohttp` >=3.10,<4 (Event API host), `msgpack` >=1,<2 (envelope codec),
3939
`PyYAML` >=6,<7 (config); dev: `pytest` >=8 + `pytest-asyncio` >=0.23 (`asyncio_mode=auto`);
40-
optional extras: `llm` = `anthropic` >=1,<2 + `google-genai` >=2,<3 (the AI-node provider
41-
SDKs — `pip install 'mercury-composable[llm]'`, added 2026-09-01)
40+
optional extra: `llm` = `anthropic` >=1,<2 only (the LLM helper app's SDK — `pip install 'mercury-composable[llm]'`;
41+
`google-genai` was removed 2026-10-01 with the Gemini provider, PR #38)
4242
<!-- id: stack-deps-aiohttp-msgpack | created: 2026-08-22 | last_used: 2026-09-22 | uses: 3 | tier: active | origin: 2026-08-22-171555 -->
4343
- Developer runner: `mercury-serve` console script (`mercury_composable.cli:main`);
4444
examples run via `mercury-serve app.py --port <n>` with `-D` overrides
@@ -98,6 +98,28 @@
9898
(the engines' connected-span-tree fix, mercury-composable/mercury `fix/connected-edge-spans`).
9999
<!-- id: otel-forwarder-python | created: 2026-09-22 | last_used: 2026-09-22 | uses: 2 | tier: active | origin: 2026-09-22-164128 -->
100100

101+
- **The LLM helper is a dedicated function host on the Anthropic SDK: the engines stay LLM-free, the AI node is a bounded
102+
function, and one contract is proven by a vector file shared with the Node pack (Eric's rulings, 2026-10-01; PR #38, merge
103+
`c6cda5ab`).** `examples/llm-helper/llm_helper.py` serves `llm.chat` (one answer, optional JSON-schema structured output
104+
returned as `data`), `llm.stream` (the model's token batches over the multi-shot reply contract) and `llm.health` (a credential
105+
check, no network traffic). Claude only: the Gemini provider and `google-genai` are gone (the contract stays provider-neutral
106+
through `params.provider`, which accepts only `anthropic`). Default model `claude-opus-5-5` (`llm.model`), server-side refusal
107+
fallbacks on (`llm.fallbacks=off`), and a `Backend` seam (`get_backend()`) for the planned AWS Bedrock route
108+
(`llm-helper-bedrock-iam`). **The contract:** a `params` allowlist (`provider`, `model`, `max_tokens`, `timeout_ms`, `effort`,
109+
`stop_sequences`; anything else is a 400 and no sampling parameter is forwarded), a schema on `llm.stream` is a 400, **a reply
110+
that carries nothing usable is a 422 and never an empty success**, and every failure is an `AppException` whose message the
111+
Node twin repeats. **Progressive rendering is never buffered** (Eric's requirement): each batch leaves as its own segment the
112+
moment it arrives, a test pins it (the fake model refuses batch k until the caller holds batches 0..k-1), and the certified
113+
drives showed the helper and both engines add nothing (batches equal frames, 4-10 ms offset). The cadence a viewer sees is the
114+
API's and depends on the model (Haiku 4.5 about 25 ms continuous, Sonnet 5.5 about 350 ms bursts, Opus 5.5 about 600 ms
115+
bursts). **Opus 5.5 thinks first and thinking tokens count against `max_tokens`:** a few hundred can end with no text (the
116+
422), so the engines' demos ask for 2000, the helper's default is 16000, and Haiku (`llm.model: claude-haiku-4-5`) is the
117+
documented choice for smooth rendering; the default STAYS Opus (Eric, 2026-10-01). **Proof:** `tests/vectors/llm-helper-vectors.json`
118+
(byte-identical in mercury-nodejs, 63 cases against SDK fakes) plus `tests/test_llm_helper.py` (86 tests), and a live
119+
certification through the Java and Rust engines (`docs/test-reports/llm-helper-certification.md`: 124 model calls, every batch
120+
its own frame, every trace one tree). No prompt or completion text reaches a log; usage rides the trace record.
121+
<!-- id: llm-helper-app | created: 2026-10-01 | last_used: 2026-10-01 | uses: 1 | tier: working | origin: 2026-10-02-001146 -->
122+
101123
## Conventions
102124

103125
- **Quality gates (adopted 2026-08-23, Eric's IDE review round): ruff + basedpyright +
@@ -113,6 +135,13 @@
113135
`instructions.md`); GitHub flow with tests + a CHANGELOG entry per change
114136
(CONTRIBUTING.md).
115137
<!-- id: conv-github-flow-changelog | created: 2026-08-22 | last_used: 2026-09-22 | uses: 3 | tier: active | origin: 2026-08-22-171555 -->
138+
- **Each example app lives in a folder of its own, with a README and its own `resources/` (Eric, 2026-10-01; PR #38).**
139+
`examples/demo-app/` (the minimal polyglot app: `hello.python`, `hello.declarative`, `hello.chain`, `hello.sync.chain`,
140+
`hello.tokens`, the private `demo.suffix.helper` and `demo.health`) and `examples/llm-helper/`; run one as
141+
`mercury-serve examples/<app>/<file>.py` (the sample config is read from the `resources` folder next to the app file). The
142+
Node pack mirrors the layout. The demo and the helper share the default port 8086, so give one of them another with
143+
`-Drest.server.port` to run both. The demo stays provider-free and credential-free: no LLM code goes into it.
144+
<!-- id: examples-one-folder-per-app | created: 2026-10-01 | last_used: 2026-10-01 | uses: 1 | tier: working | origin: 2026-10-02-001146 -->
116145

117146
## Open Threads
118147

‎memory/instructions.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ the engines by design. The legacy pre-composable language pack lives in git hist
2727
`cli.py` (`mercury-serve`); `py.typed` ships type information.
2828
- `tests/` — pytest suite; `tests/vectors/vectors.json` holds the **golden conformance
2929
vectors shared with the Java and Rust engines** (the wire-compatibility proof).
30-
- `examples/demo_app.py` — minimal runnable function app.
30+
- `examples/demo-app/demo_app.py` — the minimal runnable function app (README and `resources/` beside it);
31+
`examples/llm-helper/llm_helper.py` — the LLM helper app (`llm.chat`, `llm.stream`, `llm.health` on the Anthropic SDK).
3132
- Root `README.md` — the consumer-facing guide (quick start, function contract,
3233
configuration, wire compatibility); the root `AGENTS.md` fork routes consumers there.
3334

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
- [ ] **AWS Bedrock through IAM as the LLM helper's second backend.** The helper's `Backend` seam is documented, not built:
2+
build the SDK's Bedrock client in `get_backend()` (it signs with the default AWS credential chain and takes a region, so
3+
there is no API key), give the `Backend` a `provider_model` that prefixes the model id (`anthropic.claude-opus-5-5`), report
4+
`supports_fallbacks=False` (server-side fallbacks are not offered on Bedrock), describe a missing AWS credential in
5+
`credential_problem()`, and select it with `llm.backend: 'bedrock'`. The routes, the contract and the vector file stay as they
6+
are, and the Node twin does the same in `defaultBackend()`. Needs Eric's AWS account for the live drive, with a negative
7+
control first (a bad credential must fail by name).
8+
→ serves: vision-mercury-python
9+
<!-- id: llm-helper-bedrock-iam | created: 2026-10-01 | last_used: 2026-10-01 | uses: 1 | tier: working | origin: 2026-10-02-001146 -->
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
- [ ] **Next pack release: catch up to the Java number and carry the LLM helper.** The pack is published at 4.12.15 while the
2+
engines shipped 4.12.20. `main` holds, unreleased, the LLM helper app (`examples/llm-helper`, PR #38), the demo-app move and the
3+
stricter `llm.chat` / `llm.stream` contract (two READ items in the CHANGELOG's Unreleased section). The release is tagged at the
4+
Java number it catches up to, never an intermediate one; Eric decides when, and tag and publish are his steps.
5+
→ serves: vision-mercury-python
6+
<!-- id: pack-catch-up-release | created: 2026-10-01 | last_used: 2026-10-01 | uses: 1 | tier: working | origin: 2026-10-02-001146 -->
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Session (2026-10-02T00:11:46.000Z)
2+
3+
**Agent:** Claude Code
4+
**User:** Eric - design and implement an LLM helper app in both language packs, certify it end to end from the Java and Rust engines, and standardize the examples folders.
5+
6+
## What We Did
7+
8+
Built the LLM helper app (`examples/llm-helper/llm_helper.py`, its README and `resources/`) on the official Anthropic SDK, with the Node twin
9+
built from the same shared contract file (`tests/vectors/llm-helper-vectors.json`, 63 cases, byte-identical in mercury-nodejs; a latent
10+
`{"messages": "hello"}` 500 found while building the twin was fixed with two vectors). Certified it live with real Claude calls through the
11+
Java and Rust engines (a Layer 1 streaming service, a Layer 2 flow, two Layer 3 graphs): 124 model calls, every token batch reached the engine
12+
edge as its own frame, the error contract held on the real SDK, every trace one tree. Moved the demo to `examples/demo-app/` with its resources
13+
and a README (the LLM code and the Gemini provider are gone), and removed `google-genai`. Review rounds from Eric's IDE screenshots tightened
14+
`llm_helper.py` and the tests (basedpyright and PyCharm narrow differently, so explicit `Any` annotations and explicit lookups). Merged as
15+
PR #38 (merge commit `c6cda5ab`, 2026-10-01 23:50Z); the engines' certification report and playground wording went in separate PRs.
16+
17+
## Decisions Made
18+
19+
- Claude-only helper; the contract stays provider-neutral through `params.provider`. Default model stays `claude-opus-5-5` (Eric kept it after
20+
seeing Haiku's smoother cadence), documented with the Haiku alternative; the demos ask for 2000 tokens because Opus thinks before it answers
21+
and thinking tokens count against `max_tokens` (a 48-call live probe found no empty result at the old budgets either).
22+
- Progressive rendering is never buffered: each batch is its own segment, pinned by a test.
23+
- A reply with nothing usable is a 422, never an empty success; the contract is stricter than the demo nodes were (a `params` allowlist, a
24+
schema on `llm.stream` is a 400); both are READ items in the CHANGELOG.
25+
- AWS Bedrock through IAM is the planned second backend: the `Backend` seam is documented, not built.
26+
- Each example app lives in a folder of its own with a README and `resources/`; the Node pack mirrors it.
27+
28+
## Context for Next Session
29+
30+
- `main` holds the helper unreleased: the pack is published at 4.12.15, the engines are at 4.12.20; the release catches up to the Java number
31+
(thread `pack-catch-up-release`), Eric's call.
32+
- Open: `llm-helper-bedrock-iam` (needs Eric's AWS account). The engines' memory records the certification and the playground wiring.
33+
- Gates at merge: ruff, basedpyright (0 errors), pytest 187 passed, `mkdocs build --strict`.
34+
- The post-commit hook's auto-stub session log was deleted on the feature branch each time, never committed; this is the real log.
35+
36+
## Memory References
37+
38+
- Referenced: stack-deps-aiohttp-msgpack (the `llm` extra is `anthropic` only; text updated), engine-consistent-conventions (the helper's config keys and
39+
the demo's `resources/` follow the engines), scope-wrapper-no-orchestration (the helper is a function, not an orchestrator), conv-python-quality-gates
40+
(ruff, basedpyright, pytest gates; the IDE-narrowing fixes), otel-forwarder-python (trace annotations and the connected tree in the certification),
41+
bp-publish-interop-gate (the helper certification is interop evidence)
42+
- Created: llm-helper-app, examples-one-folder-per-app, llm-helper-bedrock-iam, pack-catch-up-release
43+
- Superseded: (none)

0 commit comments

Comments
 (0)