Entropic 2.3.8
Local-first agentic inference engine
Loading...
Searching...
No Matches
entropic::ChatAdapter Class Referenceabstract

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

#include <entropic/inference/adapters/adapter_base.h>

Inheritance diagram for entropic::ChatAdapter:

Public Member Functions

 ChatAdapter (std::string tier_name, std::string identity_prompt)
 Construct adapter with tier identity.
 
std::string format_system_prompt (const std::string &base_prompt, const std::vector< std::string > &tool_jsons) const
 Assemble system prompt: identity + context + tools.
 
virtual ParseResult parse_tool_calls (const std::string &content) const =0
 Parse tool calls from model output.
 
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< ToolCallparse_tagged_tool_calls (const std::string &content) const
 Parse <tool_call>JSON</tool_call> tagged blocks.
 
std::vector< ToolCallparse_bare_json_tool_calls (const std::string &content) const
 Parse bare JSON lines containing "name" key.
 
std::string extract_thinking (const std::string &content) const
 Extract <think>...</think> content.
 
std::string strip_think_blocks (const std::string &content) const
 Strip all <think>...</think> blocks from content.
 
std::optional< ToolCalltry_recover_json (const std::string &json_str) const
 Attempt JSON recovery on malformed tool call string.
 
std::optional< ToolCallparse_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.
 

Detailed Description

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().

Version
1.8.2

Definition at line 58 of file adapter_base.h.

Constructor & Destructor Documentation

◆ ChatAdapter()

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

Construct adapter with tier identity.

Parameters
tier_nameIdentity tier (e.g. "eng", "lead").
identity_promptAssembled identity prompt.
Version
1.8.2
Parameters
tier_nameIdentity tier name.
identity_promptAssembled identity prompt.
Version
1.8.2

Definition at line 102 of file adapter_base.cpp.

Member Function Documentation

◆ chat_format()

virtual std::string entropic::ChatAdapter::chat_format ( ) const
pure virtual

Chat format identifier (e.g.

"chatml").

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

Implemented in entropic::Gemma4Adapter, entropic::GenericAdapter, entropic::Nemotron3Adapter, entropic::Qwen35Adapter, and entropic::Qwen36Adapter.

◆ extract_thinking()

std::string entropic::ChatAdapter::extract_thinking ( const std::string &  content) const
protected

Extract <think>...</think> content.

Extract content from <think>...</think> blocks.

Version
1.8.2
Parameters
contentModel output.
Returns
Concatenated thinking content, or empty string.

Definition at line 325 of file adapter_base.cpp.

◆ format_content_parts()

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

Convert multimodal content parts to adapter-specific format.

Default: OpenAI-format content array JSON.

Parameters
partsContent parts from a message.
Returns
JSON string in the format expected by the model's chat template.
Version
1.9.11

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

Parameters
partsContent parts from a message.
Returns
JSON array string with text/image objects.

Reimplemented in entropic::Qwen35Adapter, and entropic::Qwen36Adapter.

Definition at line 497 of file adapter_base.cpp.

◆ format_system_prompt()

std::string entropic::ChatAdapter::format_system_prompt ( const std::string &  base_prompt,
const std::vector< std::string > &  tool_jsons 
) const

Assemble system prompt: identity + context + tools.

Parameters
base_promptApplication context.
tool_jsonsTool definitions as JSON strings.
Returns
Assembled system prompt.
Version
1.8.2
Parameters
base_promptApplication context.
tool_jsonsTool definitions as JSON strings.
Returns
Assembled system prompt string.

Definition at line 118 of file adapter_base.cpp.

◆ format_system_with_vision()

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

Format system prompt with optional vision context.

Default: return system prompt unchanged regardless of vision.

Parameters
base_systemBase system prompt text.
has_visionWhether the model has vision capability.
Returns
Formatted system prompt.
Version
1.9.11

Default implementation returns base_system unchanged. Vision-capable adapters override to append vision instructions.

Parameters
base_systemBase system prompt text.
has_visionWhether vision is available.
Returns
base_system unchanged.

Reimplemented in entropic::Qwen35Adapter, and entropic::Qwen36Adapter.

Definition at line 484 of file adapter_base.cpp.

◆ format_tool_result()

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

Format a tool result as a user message.

Format tool result as user message (default).

Parameters
tool_callThe tool call that was executed.
resultTool execution result text.
Returns
Formatted message.
Version
1.8.2
Parameters
tool_callThe executed tool call.
resultExecution result text.
Returns
Formatted user message.

Reimplemented in entropic::Nemotron3Adapter, entropic::Qwen35Adapter, and entropic::Qwen36Adapter.

Definition at line 158 of file adapter_base.cpp.

◆ format_tools()

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

Format tool definitions for injection into system prompt.

Default tool formatting: markdown headings + JSON schema.

Parameters
tool_jsonsTool definition JSON strings.
Returns
Adapter-formatted tool prompt string.
Version
2.0.4
Parameters
tool_jsonsTool definitions as JSON strings.
Returns
Formatted tool section string.

Reimplemented in entropic::Nemotron3Adapter, entropic::Qwen35Adapter, and entropic::Qwen36Adapter.

Definition at line 428 of file adapter_base.cpp.

◆ is_response_complete()

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

Check if response represents task completion.

Parameters
contentResponse content.
tool_callsParsed tool calls.
Returns
true if complete.
Version
1.8.2

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

Parameters
contentResponse content.
tool_callsParsed tool calls.
Returns
true if complete.

Definition at line 182 of file adapter_base.cpp.

◆ parse_bare_json_tool_calls()

std::vector< ToolCall > entropic::ChatAdapter::parse_bare_json_tool_calls ( const std::string &  content) const
protected

Parse bare JSON lines containing "name" key.

Parse bare JSON tool calls from lines.

Version
1.8.2
Parameters
contentModel output.
Returns
Vector of tool calls from bare JSON lines.

Definition at line 284 of file adapter_base.cpp.

◆ parse_single_tool_call()

std::optional< ToolCall > ChatAdapter::parse_single_tool_call ( const std::string &  json_str) const
protected

Parse a single JSON tool call string.

Parameters
json_strJSON from tagged block.
Returns
Parsed ToolCall or nullopt.
Version
1.8.2
Parameters
json_strJSON string from tagged block.
Returns
Parsed ToolCall or nullopt.

Definition at line 460 of file adapter_base.cpp.

◆ parse_tagged_tool_calls()

std::vector< ToolCall > entropic::ChatAdapter::parse_tagged_tool_calls ( const std::string &  content) const
protected

Parse <tool_call>JSON</tool_call> tagged blocks.

Version
1.8.2
Parameters
contentModel output content.
Returns
Vector of parsed tool calls.

Definition at line 212 of file adapter_base.cpp.

◆ parse_tool_calls()

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

Parse tool calls from model output.

Parameters
contentRaw model output.
Returns
ParseResult with cleaned content and tool calls.
Version
1.8.2

Implemented in entropic::Gemma4Adapter, entropic::GenericAdapter, entropic::Nemotron3Adapter, entropic::Qwen35Adapter, and entropic::Qwen36Adapter.

◆ strip_think_blocks()

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

Strip all <think>...</think> blocks from content.

Version
1.8.2
Parameters
contentModel output.
Returns
Content with think blocks removed.

Definition at line 346 of file adapter_base.cpp.

◆ try_recover_json()

std::optional< ToolCall > entropic::ChatAdapter::try_recover_json ( const std::string &  json_str) const
protected

Attempt JSON recovery on malformed tool call string.

Version
1.8.2

Member Data Documentation

◆ identity_prompt_

std::string entropic::ChatAdapter::identity_prompt_
protected

Assembled identity prompt.

Definition at line 183 of file adapter_base.h.

◆ tier_name_

std::string entropic::ChatAdapter::tier_name_
protected

Identity tier name.

Definition at line 182 of file adapter_base.h.

◆ tool_prefixes_

std::unordered_set<std::string> entropic::ChatAdapter::tool_prefixes_
mutableprotected

Known tool prefixes.

Definition at line 184 of file adapter_base.h.


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