Entropic 2.11.1
Local-first agentic inference engine
Loading...
Searching...
No Matches
entropic::StreamThinkFilter Class Reference

Streaming filter that removes <think> blocks from output. More...

#include <entropic/core/stream_think_filter.h>

Public Member Functions

 StreamThinkFilter (TokenCallback cb, void *ud)
 Construct with consumer callback.
 
 StreamThinkFilter (TokenCallback cb, void *ud, std::string open_marker, std::string close_marker)
 Construct with family-specific reasoning delimiters (gh#108).
 
void set_raw_callback (TokenCallback cb, void *ud)
 Set optional raw callback (receives ALL tokens unfiltered).
 
void on_token (const char *chunk, size_t len)
 Process a chunk of tokens.
 
void flush ()
 Flush any buffered partial tag content.
 

Detailed Description

Streaming filter that removes <think> blocks from output.

Processes tokens character-by-character. Content inside <think>...</think> tags is suppressed from the consumer callback but always forwarded to the raw callback (if set).

Version
2.0.1

Definition at line 36 of file stream_think_filter.h.

Constructor & Destructor Documentation

◆ StreamThinkFilter() [1/2]

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

Construct with consumer callback.

Parameters
cbConsumer token callback (receives filtered output).
udConsumer user_data. @req REQ-LOOP-008
Version
2.0.1
Parameters
cbConsumer callback.
udConsumer user_data. @req REQ-LOOP-008
Version
2.0.1

Definition at line 22 of file stream_think_filter.cpp.

◆ StreamThinkFilter() [2/2]

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
cbConsumer token callback (receives filtered output).
udConsumer user_data.
open_markerReasoning-block opening delimiter.
close_markerReasoning-block closing delimiter. @req REQ-LOOP-008
Version
2.10.3
Parameters
cbConsumer callback.
udConsumer user_data.
open_markerOpening delimiter.
close_markerClosing delimiter. @req REQ-LOOP-008
Version
2.10.3

Definition at line 34 of file stream_think_filter.cpp.

Member Function Documentation

◆ flush()

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.

@req REQ-LOOP-008

Version
2.0.1

@req REQ-LOOP-008

Version
2.0.2

Definition at line 182 of file stream_think_filter.cpp.

◆ on_token()

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
chunkToken data.
lenToken byte length. @req REQ-LOOP-008
Version
2.0.1
Parameters
chunkToken byte data.
lenByte length of chunk. @req REQ-LOOP-008
Version
2.0.2

Definition at line 168 of file stream_think_filter.cpp.

◆ set_raw_callback()

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

Set optional raw callback (receives ALL tokens unfiltered).

Set raw (unfiltered) callback.

Parameters
cbRaw callback.
udRaw user_data. @req REQ-LOOP-008
Version
2.0.1

Definition at line 49 of file stream_think_filter.cpp.


The documentation for this class was generated from the following files: