Skip to content

The assistant route speaks OpenUI Lang: result events, binding rules, prompt caching, stop reasons #1532

Backlog

Description

@athvin

Part of #1528. Needs #1530. Can run in parallel with #1531, coordinating on frontend/src/lib/genui/library.ts.

Why

The route is where the model learns the library, and where tool results reach the browser.

How

  1. System prompt. It is made of three parts:
    • the existing grounding rules (systemPrompt() in frontend/src/lib/assistant/tools.ts, with the V9 branch unchanged);
    • library.prompt({ preamble, additionalRules, examples });
    • the binding rules: data comes only from this conversation's tool results, so reference them, and never restate a row or a number.
  2. A new SSE event, result.
    • Its payload is { id: tool_use_id, name, result }, emitted after each tool runs.
    • It carries exactly what the model receives, including the same 40 KB cap.
    • The browser keeps the results per turn. The tool event stays as the citation.
  3. A flag: ERWEB_ASSISTANT_GENUI_ENABLED. With it off, the prompt and behaviour are unchanged byte for byte, and the existing assistant tests in tests/functional/grow.spec.ts pass untouched.
  4. Harden the loop (claude-api skill).
    • max_tokens. Raise it from 1500, which cannot hold a program with a table and a chart. The route already streams.
    • Prompt caching. Tools and system are stable per (role, flag). Put a cache_control breakpoint after the system prompt. Verify that usage.cache_read_input_tokens > 0 from the second round on, and record it in the PR.
    • Stop reasons.
      • max_tokens: emit done with a truncation flag the UI shows.
      • refusal: show a plain message rather than an empty turn.
    • Effort. Set output_config.effort explicitly; Live eval set for generated answers: parse rate, grounding, correctness, cost per answer #1536 picks the level.
    • Tool definitions. Set strict: true, and validate inputs before executeTool.
  5. Metering. tokensFrom() in frontend/src/lib/usage/record.ts sums only input_tokens + output_tokens. With caching on, most of the prompt moves to cache_read_input_tokens and cache_creation_input_tokens, so metered usage would quietly fall.
    • Decide how cached tokens are metered: counted in full, or as their own figure.
    • Change tokensFrom to match, with a unit test that fails on the current behaviour.
  6. Model. Its default does not change here. Live eval set for generated answers: parse rate, grounding, correctness, cost per answer #1536's eval decides whether the default for ERWEB_ASSISTANT_MODEL (claude-opus-5 today) moves.

Acceptance criteria

  • Unit: prompt assembly gives the same bytes for the same role and flag. That is the precondition for caching.
  • Unit: result events carry exactly what the model saw, including truncation.
  • Unit: tokensFrom counts cached tokens per the decision above.
  • Functional, scripted in tests/mock-erserver/server.mjs:
    • an OpenUI Lang answer with a bound table streams through;
    • a max_tokens stop and a refusal each produce their message.
  • With the flag off, the existing assistant specs pass unchanged.
  • The PR body shows cache-read tokens observed against the real API in dev.
  • make frontend passes.

Activity

  1. added
    post-mvp
    on Dec 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    post-mvp

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions