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

Show on the map →

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
lines 507–507◇ if (!calls.empty())lines 507–507return;lines 508–508auto fb = try_fenced_json_call(raw);lines 509–509◇ if (fb.empty() && llama != nullptr)lines 510–510fb = try_fenced_args_object_call(raw, llama->active_tools_json());lines 512–512◇ if (!fb.empty())lines 512–512calls = std::move(fb);

Requirements

REQ-INFER-010

destroy_orchestrator_interface

void entropic::destroy_orchestrator_interface(InterfaceContext *context)

Free a context returned by build_orchestrator_interface() .

src/inference/interface_factory.cpp:647

Show on the map →

Called by SCENARIO, TEST_CASE, entropic_destroy, ~InterfaceFixture

Tested by

1 teststestRunEnded

Calls none

Source · 3 lines
void destroy_orchestrator_interface(InterfaceContext* context) {
    delete context;
}
Activity · 1 steps
lines 648–648delete context;

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

Show on the map →

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;
}
Activity · 13 steps
lines 575–575auto* ctx = static_cast<InterfaceContext*>(user_data);lines 576–576std::string raw_str = raw ? raw : "";lines 577–577auto tier = ctx->orchestrator->last_used_tier();lines 578–578◇ if (tier.empty())lines 578–578tier = ctx->default_tier;lines 579–580auto* llama = dynamic_cast<LlamaCppBackend*>( ctx->orchestrator->get_backend(tier));lines 585–586auto parsed = parse_model_response( llama, ctx->orchestrator->get_adapter(tier), raw_str);lines 587–587std::string cleaned_str = std::move(parsed.content);lines 588–588std::vector<ToolCall> calls = std::move(parsed.tool_calls);lines 590–590apply_fenced_fallbacks(raw_str, llama, calls);lines 592–592*cleaned = dup(cleaned_str);lines 593–593*tool_calls_json = dup(serialize_tool_calls(calls));lines 594–594return 0;

Requirements

REQ-INFER-010