14#include <nlohmann/json.hpp>
32 const std::string& name,
35 std::vector<std::string> out;
36 auto tools = nlohmann::json::parse(
tools_json,
nullptr,
false);
37 if (!tools.is_array()) {
return out; }
38 for (
const auto&
t : tools) {
39 if (!
t.is_object() ||
t.value(
"name", std::string{}) != name) {
43 auto req =
t.value(
"inputSchema", nlohmann::json::object())
44 .
value(
"required", nlohmann::json::array());
45 for (
const auto&
r :
req) {
46 if (
r.is_string()) { out.push_back(
r.get<std::string>()); }
66 const std::vector<std::string>&
required,
69 if (!args.contains(key)) {
71 "Template parse of '{}' is missing required parameter '{}' — "
72 "common_chat's PEG autoparser extracts only the first "
73 "<parameter=>; falling back to the adapter parser.",
94 if (!known ||
required.empty()) {
return true; }
96 auto args = nlohmann::json::parse(
call.arguments_json,
nullptr,
false);
138 if (
llama ==
nullptr || !
llama->common_chat_parse_reliable()) {
174 const std::string&
raw) {
178 if (adapter !=
nullptr) {
179 auto parsed = adapter->parse_tool_calls(
raw);
192 if (adapter !=
nullptr) {
Concrete base class for chat format adapters (80% logic).
std::string strip_think_blocks(const std::string &content) const
Strip this family's reasoning blocks from content (gh#108).
LlamaCppBackend — common llama.cpp patterns (15% layer).
LlamaCppBackend — llama.cpp C API integration.
spdlog initialization and logger access.
ENTROPIC_EXPORT std::shared_ptr< spdlog::logger > get(const std::string &name)
Get or create a named logger.
Activate model on GPU (WARM → ACTIVE).
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;...
@ optional
optional: every escape asks the host's path approver
static bool has_all_required(const nlohmann::json &args, const std::vector< std::string > &required, const std::string &call_name)
Verify every required key is present, warning on the first absent one.
bool calls_satisfy_schema(const std::vector< ToolCall > &calls, const std::string &tools_json)
Check that every call's declared required parameters are present.
static bool try_template_parse(LlamaCppBackend *llama, const std::string &raw, ParsedModelResponse &out)
Tool calls from the template parser, when trustworthy.
ParsedModelResponse parse_model_response(LlamaCppBackend *llama, ChatAdapter *adapter, const std::string &raw)
Parse a raw emission: template first, adapter second.
static bool one_call_satisfies_schema(const ToolCall &call, const std::string &tools_json)
Check one call's declared required parameters are all present.
static std::vector< std::string > required_params(const std::string &tools_json, const std::string &name, bool &found)
Required parameter names declared by a tool's inputSchema.
One template-first / adapter-second parse rule for raw model output.
Content and tool calls extracted from one raw emission.
bool used_template
True when common_chat produced the calls.
std::vector< ToolCall > tool_calls
Extracted calls.
std::string content
Reasoning-stripped content.