EN 中文
Back to Overview

LiteRtLm_CreateConversationWithConfig

Advanced Session creation with presets. Allows injecting system prompts, multi-turn history messages, and Tools architecture definitions during initialization.

01. Preset Injection Flow

graph TD JSON[Json Preface String] -->|Parse| Parser[Internal JSON Parser] Parser -->|Apply| System[System Prompt] Parser -->|Fill| History[Messages History] Parser -->|Register| Tools[Function Tools Definition] subgraph State_Machine [Initial Session State Machine] System History Tools end State_Machine --> Result[void* Configured Conv Handle]
Application Scenario: Used for quickly "resurrecting" historical Sessions, or injecting personality settings (System Prompt) and callable action interfaces (Tools) during the NPC initialization phase.

02. Parameter Definitions

void* LiteRtLm_CreateConversationWithConfig(
    void* engine_ptr, 
    const char* json_preface_str,
    int bEnableConstrainedDecoding
);
ParameterResponsibility
json_preface_str JSON formatted preset string.
Contains "messages" array and "tools" definitions. Must comply with a subset of the OpenAI API format standard.
bEnableConstrainedDecoding Constrained decoding switch.
When set to 1, the engine will automatically enable JSON strong constraints based on tools definitions, ensuring that the AI must output tool calls in the specified format.

03. JsonPreface Standard Format Example

{
  "messages": [
    {"role": "system", "content": "You are a helpful companion."},
    {"role": "user", "content": "Hello!"}
  ],
  "tools": [
    {
      "type": "function",
      "function": {
        "name": "get_weather",
        "parameters": { "type": "object", "properties": {...} }
      }
    }
  ]
}