Entropic 2.3.8
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
59public:
66 ChatAdapter(std::string tier_name, std::string identity_prompt);
67 virtual ~ChatAdapter() = default;
68
69 /* ── System prompt assembly ──────────────────────────── */
70
78 std::string format_system_prompt(
79 const std::string& base_prompt,
80 const std::vector<std::string>& tool_jsons) const;
81
82 /* ── Tool call parsing (subclass overrides) ──────────── */
83
91 const std::string& content) const = 0;
92
93 /* ── Tool result formatting ──────────────────────────── */
94
103 const ToolCall& tool_call,
104 const std::string& result) const;
105
106 /* ── Tool formatting (subclass can override) ─────────── */
107
114 virtual std::string format_tools(
115 const std::vector<std::string>& tool_jsons) const;
116
117 /* ── Response completeness ───────────────────────────── */
118
127 const std::string& content,
128 const std::vector<ToolCall>& tool_calls) const;
129
135 virtual std::string chat_format() const = 0;
136
137protected:
138 /* ── Shared parsing primitives ───────────────────────── */
139
144 std::vector<ToolCall> parse_tagged_tool_calls(
145 const std::string& content) const;
146
151 std::vector<ToolCall> parse_bare_json_tool_calls(
152 const std::string& content) const;
153
158 std::string extract_thinking(const std::string& content) const;
159
164 std::string strip_think_blocks(const std::string& content) const;
165
170 std::optional<ToolCall> try_recover_json(
171 const std::string& json_str) const;
172
179 std::optional<ToolCall> parse_single_tool_call(
180 const std::string& json_str) const;
181
182 std::string tier_name_;
183 std::string identity_prompt_;
184 mutable std::unordered_set<std::string> tool_prefixes_;
185
186public:
187 /* ── Vision / multimodal (v1.9.11) ────────────────────── */
188
199 virtual std::string format_system_with_vision(
200 const std::string& base_system,
201 bool has_vision) const;
202
212 virtual std::string format_content_parts(
213 const std::vector<ContentPart>& parts) const;
214};
215
216} // namespace entropic
Concrete base class for chat format adapters (80% logic).
std::string format_system_prompt(const std::string &base_prompt, const std::vector< std::string > &tool_jsons) const
Assemble system prompt: identity + context + tools.
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.
std::vector< ToolCall > parse_bare_json_tool_calls(const std::string &content) const
Parse bare JSON lines containing "name" key.
virtual std::string format_tools(const std::vector< std::string > &tool_jsons) const
Format tool definitions for injection into system prompt.
virtual ParseResult parse_tool_calls(const std::string &content) const =0
Parse tool calls from model output.
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 all <think>...</think> blocks from content.
std::string identity_prompt_
Assembled identity prompt.
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.
std::string extract_thinking(const std::string &content) const
Extract <think>...</think> content.
Message struct for conversation history.
Activate model on GPU (WARM → ACTIVE).
A message in a conversation.
Definition message.h:35
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.
A tool call request parsed from model output.
Definition tool_call.h:31
Tool call and tool result types.