Skip to content
2 min read · 404 words

Interface: RawGenerationObservation

Defined in: src/batteries/llm/chat_common/types.ts:346

One observation of a battery's raw model output for a single completed generation, fired the instant the full text is in hand — AFTER envelope-token stripping + reasoning/tool-call parsing, but BEFORE the parsed result is persisted. The whole point is to expose the gap between what the model literally emitted (rawText) and what the battery managed to extract (cleanedText / toolCalls / reasoning): when a small on-device model emits a tool call in a shape no parser matches, the call silently leaks into cleanedText as prose, and this is the ONLY seam where that is visible.

Remarks

This is a pure observability tap — it returns void, never mutates the result, and never throws into the generation path (the adapter swallows callback errors). It fires once per terminal generation (one per non-streamed turn; one per stream at stream end), for BOTH the transformers.js and LiteRT-LM on-device batteries, at the identical point in each. Use it for parser bring-up against a new model, live debugging ("why did the agent abstain?"), or capturing ground-truth fixtures — exactly the job that previously required patching a temporary hook into the adapter.

Properties

PropertyTypeDescriptionDefined in
cleanedTextstringThe residual prose after reasoning + tool-call extraction — what becomes the assistant message content. If a tool call failed to parse, its source text is still here (the leak).src/batteries/llm/chat_common/types.ts:357
rawTextstringThe model's complete decoded output for this generation, with non-semantic envelope/turn-boundary special tokens already stripped (the same text handed to the parsers) — i.e. what the parsers actually saw. This is the field to inspect when a tool call did not parse.src/batteries/llm/chat_common/types.ts:352
reasoningreadonly string[]The reasoning/thinking traces the reasoning parser extracted (empty when none / not applicable).src/batteries/llm/chat_common/types.ts:359
streamedbooleanWhether this generation streamed its prose to the consumer (vs. a single batch decode).src/batteries/llm/chat_common/types.ts:363
streamIdstringThe adapter's stream/message id for this generation, for correlating with other telemetry.src/batteries/llm/chat_common/types.ts:365
toolCallsreadonly ParsedToolCall[]The tool calls the tool-call parser extracted (empty when the model emitted none, or none parsed).src/batteries/llm/chat_common/types.ts:361