include/entropic/inference/adapters/adapter_base.h

← API

include/entropic/inference/adapters/adapter_base.h

entropic::ChatAdapter

Concrete base class for chat format adapters (80% logic).

Derived by entropic::Gemma4Adapter, entropic::GenericAdapter, entropic::Nemotron3Adapter, entropic::Qwen35Adapter, entropic::Qwen36Adapter.

entropic::ChatAdapter::ChatAdapter(std::string tier_name, std::string identity_prompt)

Construct adapter with tier identity.

Parameters
  • tier_name — Identity tier (e.g. "eng", "lead").
  • identity_prompt — Assembled identity prompt.
  • tier_name — Identity tier name.

virtual entropic::ChatAdapter::~ChatAdapter()=default

virtual ThinkMarkers entropic::ChatAdapter::thinking_markers() const

This family's reasoning-block delimiters (gh#108).

Default is the <think> pair used by Qwen and Nemotron. Override in a family that wraps reasoning differently — Gemma-4 QAT does. The single declaration point per family: both consumers read it — the buffered strip (strip_think_blocks) and the live StreamThinkFilter that wraps on_token in generate_streaming. Before v2.10.3 these were two independent hardcoded literals and gemma4 matched neither.

Returns
Marker pair; empty for a family that declares none, which makes both consumers no-ops.

std::string entropic::ChatAdapter::strip_think_blocks(const std::string &content) const

Strip this family's reasoning blocks from content (gh#108).

Uses thinking_markers(), so an adapter declares its markers once and both the buffered strip and the live StreamThinkFilter agree. Matching is plain substring, not regex — <|channel> contains a regex metacharacter and would need escaping. An unclosed opening marker (generation hit its token budget mid-reasoning) erases to end of content and WARNs: no answer was ever produced, so returning the reasoning would be worse than nothing. PUBLIC since v2.10.3 — was protected. The shared parse rule (response_parse.h) runs it on both the template and adapter branches, so it is an inference-layer concern now, not a subclass helper. Widening only; non-virtual, so no ABI change for existing consumers. Driven by thinking_markers() so an adapter declares its delimiters once. Plain substring matching, not regex: gemma4's <|channel> contains a regex metacharacter and the previous std::regex form would have needed escaping to stay correct. An opening marker with no close means the budget ran out mid-reasoning: the span is erased to end of content and a WARN is logged, because no answer was ever produced and returning the reasoning would be worse than nothing.

Parameters
  • content — Model output.
Returns
  • Content with reasoning blocks removed and trimmed.
  • Content with this family's reasoning blocks removed and trimmed; unchanged when the family declares no markers.

virtual ParseResult entropic::ChatAdapter::parse_tool_calls(const std::string &content) const =0

Message entropic::ChatAdapter::format_tool_result(const ToolCall &tool_call, const std::string &result) const

Format a tool result as a user message.

Format tool result as user message (default).

Parameters
  • tool_call — The tool call that was executed.
  • result — Tool execution result text.
  • tool_call — The executed tool call.
  • result — Execution result text.
Returns
  • Formatted message.
  • Formatted user message.

std::string ChatAdapter::format_tools(const std::vector< std::string > &tool_jsons) const

Format tool definitions for injection into system prompt.

Default tool formatting: markdown headings + JSON schema.

Parameters
  • tool_jsons — Tool definition JSON strings.
  • tool_jsons — Tool definitions as JSON strings.
Returns
  • Adapter-formatted tool prompt string.
  • Formatted tool section string.

bool entropic::ChatAdapter::is_response_complete(const std::string &content, const std::vector< ToolCall > &tool_calls) const

Check if response represents task completion.

Think-aware: think-only content without tool calls = still working.

Parameters
  • content — Response content.
  • tool_calls — Parsed tool calls.
Returns
true if complete.

virtual std::string entropic::ChatAdapter::chat_format() const =0

Chat format identifier (e.g.

"chatml").

Returns
Format string, or empty for GGUF-embedded template.

std::string ChatAdapter::format_system_with_vision(const std::string &base_system, bool has_vision) const

Format system prompt with optional vision context.

Default: return system prompt unchanged regardless of vision. Default implementation returns base_system unchanged. Vision-capable adapters override to append vision instructions.

Parameters
  • base_system — Base system prompt text.
  • has_vision — Whether the model has vision capability.
  • has_vision — Whether vision is available.
Returns
  • Formatted system prompt.
  • base_system unchanged.

std::string ChatAdapter::format_content_parts(const std::vector< ContentPart > &parts) const

Convert multimodal content parts to adapter-specific format.

Default: OpenAI-format content array JSON. Default: OpenAI-format content array. Adapters override if the model expects a different image reference format.

Parameters
  • parts — Content parts from a message.
Returns
  • JSON string in the format expected by the model's chat template.
  • JSON array string with text/image objects.

entropic::ParseResult

Parsed tool call result: cleaned content + extracted calls.

std::string entropic::ParseResult::cleaned_content

Content with tool calls removed.

std::vector<ToolCall> entropic::ParseResult::tool_calls

Extracted tool calls.

entropic::ThinkMarkers

The reasoning-block delimiters a model family emits (gh#108).

std::string entropic::ThinkMarkers::open

Opening delimiter.

std::string entropic::ThinkMarkers::close

Closing delimiter.