Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Ggml org Llama cpp Jinja Caps

From Leeroopedia
Knowledge Sources
Domains Template_Engine, Chat
Last Updated 2026-02-15 00:00 GMT

Overview

Implements capability detection for Jinja chat templates by trial-executing them with various input configurations to determine what features the template supports.

Description

This module uses `caps_try_execute` to run a compiled Jinja program with test inputs including messages with typed content, tool definitions, tool calls, system roles, and reasoning content. It analyzes which values were accessed and which operations were performed by inspecting `stats.ops` and `stats.used` on tracked values to infer capabilities like `supports_tools`, `supports_typed_content`, `supports_parallel_tool_calls`, `supports_system_role`, and `supports_preserve_reasoning`. The `caps` struct provides `to_map()` and `to_string()` methods for serialization and debugging.

Usage

Use this module when the server needs to automatically detect what features a given model's chat template supports without manual configuration. This drives adaptive behavior for tool calling, content types, and system messages.

Code Reference

Source Location

Signature

namespace jinja {

std::map<std::string, bool> caps::to_map() const;
std::string caps::to_string() const;
caps caps_get(jinja::program & prog);

} // namespace jinja

Import

#include "jinja/caps.h"

I/O Contract

Inputs

Name Type Required Description
prog jinja::program & Yes A compiled Jinja template program to analyze for capabilities

Outputs

Name Type Description
caps_get return caps Struct with boolean flags for each detected capability
to_map return std::map<std::string, bool> Map of capability names to boolean values for serialization
to_string return std::string Human-readable string representation of capabilities for debugging

Usage Examples

#include "jinja/caps.h"
#include "jinja/runtime.h"

// Compile a Jinja chat template
auto prog = jinja::compile(template_string);

// Detect template capabilities
jinja::caps capabilities = jinja::caps_get(prog);

// Check specific capabilities
if (capabilities.supports_tools) {
    // Enable tool calling support
}
if (capabilities.supports_typed_content) {
    // Enable typed content (e.g., image messages)
}

// Serialize capabilities for API response
auto cap_map = capabilities.to_map();

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment