Entropic 2.11.1
Local-first agentic inference engine
Loading...
Searching...
No Matches
adapter_base.h
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
27#pragma once
28
31
32#include <optional>
33#include <string>
34#include <string_view>
35#include <unordered_set>
36#include <vector>
37
38namespace entropic {
39
45 std::string cleaned_content;
46 std::vector<ToolCall> tool_calls;
47};
48
62 std::string open = "<think>";
63 std::string close = "</think>";
64};
65
81std::vector<ToolCall> recover_action_envelope_calls(const std::string& raw);
82
96void apply_action_envelope_recovery(std::vector<ToolCall>& calls,
97 const std::string& raw);
98
117void coerce_string_typed_args(std::vector<ToolCall>& calls,
118 const std::string& tools_json);
119
130public:
137 ChatAdapter(std::string tier_name, std::string identity_prompt);
138 virtual ~ChatAdapter() = default;
139
140 /* ── System prompt assembly ──────────────────────────── */
141
142
143 /* ── Tool call parsing (subclass overrides) ──────────── */
144
167 virtual ThinkMarkers thinking_markers() const { return {}; }
168
190 std::string strip_think_blocks(const std::string& content) const;
191
192 virtual ParseResult parse_tool_calls(
193 const std::string& content) const = 0;
194
195 /* ── Tool result formatting ──────────────────────────── */
196
205 const ToolCall& tool_call,
206 const std::string& result) const;
207
208 /* ── Tool formatting (subclass can override) ─────────── */
209
216 virtual std::string format_tools(
217 const std::vector<std::string>& tool_jsons) const;
218
219 /* ── Response completeness ───────────────────────────── */
220
229 const std::string& content,
230 const std::vector<ToolCall>& tool_calls) const;
231
237 virtual std::string chat_format() const = 0;
238
239protected:
240 /* ── Shared parsing primitives ───────────────────────── */
241
246 std::vector<ToolCall> parse_tagged_tool_calls(
247 const std::string& content) const;
248
249
250
251
256 std::optional<ToolCall> try_recover_json(
257 const std::string& json_str) const;
258
265 std::optional<ToolCall> parse_single_tool_call(
266 const std::string& json_str) const;
267
268 std::string tier_name_;
269 std::string identity_prompt_;
270 mutable std::unordered_set<std::string> tool_prefixes_;
271
272public:
273 /* ── Vision / multimodal (v1.9.11) ────────────────────── */
274
285 virtual std::string format_system_with_vision(
286 const std::string& base_system,
287 bool has_vision) const;
288
298 virtual std::string format_content_parts(
299 const std::vector<ContentPart>& parts) const;
300};
301
302} // namespace entropic
Concrete base class for chat format adapters (80% logic).
std::unordered_set< std::string > tool_prefixes_
Known tool prefixes.
std::optional< ToolCall > try_recover_json(const std::string &json_str) const
Attempt JSON recovery on malformed tool call string.
virtual std::string format_content_parts(const std::vector< ContentPart > &parts) const
Convert multimodal content parts to adapter-specific format.
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 chat_format() const =0
Chat format identifier (e.g.
std::optional< ToolCall > parse_single_tool_call(const std::string &json_str) const
Parse a single JSON tool call string.
std::vector< ToolCall > parse_tagged_tool_calls(const std::string &content) const
Parse <tool_call>JSON</tool_call> tagged blocks.
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.
std::string strip_think_blocks(const std::string &content) const
Strip this family's reasoning blocks from content (gh#108).
std::string identity_prompt_
Assembled identity prompt.
virtual ThinkMarkers thinking_markers() const
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.
std::string tier_name_
Identity tier name.
Message struct for conversation history.
Activate model on GPU (WARM → ACTIVE).
void coerce_string_typed_args(std::vector< ToolCall > &calls, const std::string &tools_json)
gh#90: coerce numeric scalars back to strings for string-typed tool parameters.
std::vector< ToolCall > recover_action_envelope_calls(const std::string &raw)
gh#88: recover tool calls a gemma model parroted as bare-JSON.
void apply_action_envelope_recovery(std::vector< ToolCall > &calls, const std::string &raw)
gh#88: substitute recovered bare-JSON calls when a reliable (PEG_GEMMA4 / gemma) parse produced none;...
@ tool_call
Render-derived (COMMON_GRAMMAR_TYPE_TOOL_CALLS, needs prefill)
A message in a conversation.
Definition message.h:36
Parsed tool call result: cleaned content + extracted calls.
std::string cleaned_content
Content with tool calls removed.
std::vector< ToolCall > tool_calls
Extracted tool calls.
The reasoning-block delimiters a model family emits (gh#108).
std::string close
Closing delimiter.
std::string open
Opening delimiter.
A tool call request parsed from model output.
Definition tool_call.h:31
Tool call and tool result types.