|
Entropic 2.11.1
Local-first agentic inference engine
|
Concrete base class for chat format adapters (80% logic). More...
#include <entropic/inference/adapters/adapter_base.h>

Public Member Functions | |
| ChatAdapter (std::string tier_name, std::string identity_prompt) | |
| Construct adapter with tier identity. | |
| virtual ThinkMarkers | thinking_markers () const |
| Parse tool calls from model output. | |
| std::string | strip_think_blocks (const std::string &content) const |
| Strip this family's reasoning blocks from content (gh#108). | |
| virtual ParseResult | parse_tool_calls (const std::string &content) const =0 |
| virtual Message | format_tool_result (const ToolCall &tool_call, const std::string &result) const |
| Format a tool result as a user message. | |
| virtual std::string | format_tools (const std::vector< std::string > &tool_jsons) const |
| Format tool definitions for injection into system prompt. | |
| bool | is_response_complete (const std::string &content, const std::vector< ToolCall > &tool_calls) const |
| Check if response represents task completion. | |
| virtual std::string | chat_format () const =0 |
| Chat format identifier (e.g. | |
| virtual std::string | format_system_with_vision (const std::string &base_system, bool has_vision) const |
| Format system prompt with optional vision context. | |
| virtual std::string | format_content_parts (const std::vector< ContentPart > &parts) const |
| Convert multimodal content parts to adapter-specific format. | |
Protected Member Functions | |
| std::vector< ToolCall > | parse_tagged_tool_calls (const std::string &content) const |
| Parse <tool_call>JSON</tool_call> tagged blocks. | |
| std::optional< ToolCall > | try_recover_json (const std::string &json_str) const |
| Attempt JSON recovery on malformed tool call string. | |
| std::optional< ToolCall > | parse_single_tool_call (const std::string &json_str) const |
| Parse a single JSON tool call string. | |
Protected Attributes | |
| std::string | tier_name_ |
| Identity tier name. | |
| std::string | identity_prompt_ |
| Assembled identity prompt. | |
| std::unordered_set< std::string > | tool_prefixes_ |
| Known tool prefixes. | |
Concrete base class for chat format adapters (80% logic).
Provides shared parsing primitives, think-block handling, JSON recovery, and system prompt assembly. Subclasses override parse_tool_calls() and optionally format_tools()/format_tool_result().
Definition at line 129 of file adapter_base.h.
| entropic::ChatAdapter::ChatAdapter | ( | std::string | tier_name, |
| std::string | identity_prompt | ||
| ) |
Construct adapter with tier identity.
| tier_name | Identity tier (e.g. "eng", "lead"). |
| identity_prompt | Assembled identity prompt. |
| tier_name | Identity tier name. |
| identity_prompt | Assembled identity prompt. |
Definition at line 103 of file adapter_base.cpp.
|
pure virtual |
Chat format identifier (e.g.
"chatml").
Implemented in entropic::Gemma4Adapter, entropic::GenericAdapter, entropic::Nemotron3Adapter, entropic::Qwen35Adapter, and entropic::Qwen36Adapter.
|
virtual |
Convert multimodal content parts to adapter-specific format.
Default: OpenAI-format content array JSON.
| parts | Content parts from a message. |
Default: OpenAI-format content array. Adapters override if the model expects a different image reference format.
| parts | Content parts from a message. |
Reimplemented in entropic::Qwen35Adapter, and entropic::Qwen36Adapter.
Definition at line 604 of file adapter_base.cpp.
|
virtual |
Format system prompt with optional vision context.
Default: return system prompt unchanged regardless of vision.
| base_system | Base system prompt text. |
| has_vision | Whether the model has vision capability. |
Default implementation returns base_system unchanged. Vision-capable adapters override to append vision instructions.
| base_system | Base system prompt text. |
| has_vision | Whether vision is available. |
Reimplemented in entropic::Qwen35Adapter, and entropic::Qwen36Adapter.
Definition at line 591 of file adapter_base.cpp.
|
virtual |
Format a tool result as a user message.
Format tool result as user message (default).
| tool_call | The tool call that was executed. |
| result | Tool execution result text. |
| tool_call | The executed tool call. |
| result | Execution result text. |
Reimplemented in entropic::Nemotron3Adapter, entropic::Qwen35Adapter, and entropic::Qwen36Adapter.
Definition at line 121 of file adapter_base.cpp.
|
virtual |
Format tool definitions for injection into system prompt.
Default tool formatting: markdown headings + JSON schema.
| tool_jsons | Tool definition JSON strings. |
| tool_jsons | Tool definitions as JSON strings. |
Reimplemented in entropic::Nemotron3Adapter, entropic::Qwen35Adapter, and entropic::Qwen36Adapter.
Definition at line 535 of file adapter_base.cpp.
| bool entropic::ChatAdapter::is_response_complete | ( | const std::string & | content, |
| const std::vector< ToolCall > & | tool_calls | ||
| ) | const |
Check if response represents task completion.
| content | Response content. |
| tool_calls | Parsed tool calls. |
Think-aware: think-only content without tool calls = still working.
| content | Response content. |
| tool_calls | Parsed tool calls. |
Definition at line 145 of file adapter_base.cpp.
|
protected |
Parse a single JSON tool call string.
| json_str | JSON from tagged block. |
| json_str | JSON string from tagged block. |
Definition at line 567 of file adapter_base.cpp.
|
protected |
Parse <tool_call>JSON</tool_call> tagged blocks.
Part of the ~80% the concrete base owns; concrete adapters override only their family specifics. Tolerates the asymmetric open tags real families emit (gemma4's pipe-prefixed <|tool_call> against a plain close).
| content | Model output content. |
Definition at line 180 of file adapter_base.cpp.
|
pure virtual |
| 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.
| content | Model output. |
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.
| content | Model output. |
Definition at line 426 of file adapter_base.cpp.
|
inlinevirtual |
Parse tool calls from model output.
| content | Raw model output. |
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.
Reimplemented in entropic::Gemma4Adapter.
Definition at line 167 of file adapter_base.h.
|
protected |
Attempt JSON recovery on malformed tool call string.
|
protected |
Assembled identity prompt.
Definition at line 269 of file adapter_base.h.
|
protected |
Identity tier name.
Definition at line 268 of file adapter_base.h.
|
mutableprotected |
Known tool prefixes.
Definition at line 270 of file adapter_base.h.