Module parser

Module parser 

Source
Expand description

The ToolCallParser trait and its companion ParserOutput.

A parser consumes raw text or reasoning chunks from an LLM stream and produces a normalized ParserOutput containing:

  • forward_text — bytes that should appear in the downstream LlmStreamEvent::TextDelta.
  • forward_reasoning — bytes that should appear in the downstream LlmStreamEvent::ReasoningDelta.
  • tool_calls — fully-assembled tool calls extracted from dialect markup (e.g. Qwen XML).
  • errors — non-fatal normalization failures.

Parsers are stream-stateful: the caller (the NormalizingStream adapter) constructs one parser per stream and drives it with chunk-by-chunk input. Parsers must therefore be chunk-safe — they buffer ambiguous trailing bytes internally and flush them on the next call or at ToolCallParser::finish.

§Adding a new parser

  1. Implement ToolCallParser in a new file under super::parsers.
  2. Add a single match arm to super::registry::get_parser keyed on a new format:* tag (see super::tags).

No other crate participates in the dispatch decision.

Structs§

ParserOutput
Result of feeding one chunk of input to a parser.

Traits§

ToolCallParser
Stream-stateful parser that normalizes a single LLM dialect into canonical ParserOutput fragments.