EN 中文
Back to Overview

LiteRtLm_AppendAssistantMessage

Appends an assistant (AI) message. Used to synchronize the Session state to the "Replied" state, typically for restoring historical dialogues.

01. History Restoration Logic

graph LR DB[(External DB/Archive)] -->|Restore| Conv[Conversation] Conv -->|1. AppendUser| History[History List] Conv -->|2. AppendAssistant| History History -->|Ready| NewPrompt[Next User Input]

This interface ensures the integrity of the conversation's historical chain. If a new User message is appended directly without appending the Assistant's reply, the AI might generate redundant responses due to context breakage.

02. Parameter Definitions

void LiteRtLm_AppendAssistantMessage(void* conv_ptr, const char* text);
ParameterResponsibility
conv_ptr Valid Session handle.
text The AI response plain text content to append.

03. Archive Restoration Code Example

// Restore previous conversation turns
LiteRtLm_AppendUserMessage(Conv, "Hello");
LiteRtLm_AppendAssistantMessage(Conv, "Hello! I am your AI assistant.");

// The Session is now in the "Replied" state, waiting for the next user message
LiteRtLm_AppendUserMessage(Conv, "Help me write some C++ code");