interface_factory.cpp¶
src/inference/interface_factory.cpp
@file interface_factory.cpp @brief InferenceInterface factory — bridges orchestrator to C callbacks.
Owners: @tvanfossen
apply_fenced_fallbacks
static void entropic::apply_fenced_fallbacks(const std::string &raw, LlamaCppBackend *llama, std::vector< ToolCall > &calls)
Apply fenced-json and fenced-args-only fallback parsers (gh#122, gh#127).
src/inference/interface_factory.cpp:504
Called by iface_parse_tool_calls
Calls active_tools_json, try_fenced_args_object_call, try_fenced_json_call
Source · 10 lines
static void apply_fenced_fallbacks(const std::string& raw,
LlamaCppBackend* llama,
std::vector<ToolCall>& calls) {
if (!calls.empty()) { return; }
auto fb = try_fenced_json_call(raw);
if (fb.empty() && llama != nullptr) {
fb = try_fenced_args_object_call(raw, llama->active_tools_json());
}
if (!fb.empty()) { calls = std::move(fb); }
}Activity · 7 steps
Requirements
destroy_orchestrator_interface
void entropic::destroy_orchestrator_interface(InterfaceContext *context)
Free a context returned by build_orchestrator_interface() .
src/inference/interface_factory.cpp:647
Called by SCENARIO, TEST_CASE, entropic_destroy, ~InterfaceFixture
Tested by 1 tests
testRunEnded
Calls none
Source · 3 lines
void destroy_orchestrator_interface(InterfaceContext* context) {
delete context;
}Activity · 1 steps
Flows
iface_parse_tool_calls
static int entropic::iface_parse_tool_calls(const char *raw, char **cleaned, char **tool_calls_json, void *user_data)
Parse tool calls from raw model output (gh#87 3b).
src/inference/interface_factory.cpp:571
Called by build_orchestrator_interface
Calls apply_fenced_fallbacks, dup, get_adapter, get_backend, last_used_tier, parse_model_response, serialize_tool_calls
Source · 25 lines
static int iface_parse_tool_calls(const char* raw,
char** cleaned,
char** tool_calls_json,
void* user_data) {
auto* ctx = static_cast<InterfaceContext*>(user_data);
std::string raw_str = raw ? raw : "";
auto tier = ctx->orchestrator->last_used_tier();
if (tier.empty()) { tier = ctx->default_tier; }
auto* llama = dynamic_cast<LlamaCppBackend*>(
ctx->orchestrator->get_backend(tier));
// gh#108 (v2.10.3): same rule as the orchestrator's buffered parse —
// this used to be a byte-for-byte duplicate of that branch, which is how
// a fix could land on one path and miss the other.
auto parsed = parse_model_response(
llama, ctx->orchestrator->get_adapter(tier), raw_str);
std::string cleaned_str = std::move(parsed.content);
std::vector<ToolCall> calls = std::move(parsed.tool_calls);
apply_fenced_fallbacks(raw_str, llama, calls); // gh#122, gh#127
*cleaned = dup(cleaned_str);
*tool_calls_json = dup(serialize_tool_calls(calls));
return 0;
}