include/entropic/core/stream_think_filter.h

← API

include/entropic/core/stream_think_filter.h

Types

using entropic::TokenCallback = typedef void (*)(const char*, size_t, void*) hook point

Token callback type matching the C API signature.

entropic::StreamThinkFilter

Streaming filter that removes <think> blocks from output.

entropic::StreamThinkFilter::StreamThinkFilter(TokenCallback cb, void *ud)

Construct with consumer callback.

Parameters
  • cb — Consumer token callback (receives filtered output).
  • ud — Consumer user_data.
  • cb — Consumer callback.

entropic::StreamThinkFilter::StreamThinkFilter(TokenCallback cb, void *ud, std::string open_marker, std::string close_marker)

Construct with family-specific reasoning delimiters (gh#108).

Thinking format is a property of the chat template, not the transport: Qwen/Nemotron use <think>…</think>, Gemma-4 QAT uses <|channel>…<channel|>. Before v2.10.3 this filter hardcoded the <think> pair, so a gemma4 stream passed raw reasoning straight to the consumer — and on the agent-loop streaming path this filter is the ONLY defense, because ResponseGenerator::generate_streaming builds content from its own token accumulator rather than the parsed result. Markers come from ChatAdapter::thinking_markers(); they are passed as plain strings so that core does not depend on inference.

Parameters
  • cb — Consumer token callback (receives filtered output).
  • ud — Consumer user_data.
  • open_marker — Reasoning-block opening delimiter.
  • close_marker — Reasoning-block closing delimiter.
  • cb — Consumer callback.
  • open_marker — Opening delimiter.
  • close_marker — Closing delimiter.

void entropic::StreamThinkFilter::set_raw_callback(TokenCallback cb, void *ud)

Set optional raw callback (receives ALL tokens unfiltered).

Set raw (unfiltered) callback.

Parameters
  • cb — Raw callback.
  • ud — Raw user_data.

void entropic::StreamThinkFilter::on_token(const char *chunk, size_t len)

Process a chunk of tokens.

Process an incoming token through the think-tag filter.

Parameters
  • chunk — Token data.
  • len — Token byte length.
  • chunk — Token byte data.
  • len — Byte length of chunk.

void entropic::StreamThinkFilter::flush()

Flush any buffered partial tag content.

Flush buffered partial tag and UTF-8 content. Call at end of generation to ensure no content is lost in the tag accumulator.