Table of Contents

Interface IMultiTurnConversation

Namespace
LMKit.TextGeneration
Assembly
LM-Kit.NET.dll

Represents a multi-turn conversation interface that extends IConversation with tool-calling, skills, long-term memory, session persistence, and chat history management.

public interface IMultiTurnConversation : IConversation
Inherited Members

Examples

Multi-turn conversation with tools and chat history:

using LMKit.Model;
using LMKit.TextGeneration;
using LMKit.Agents.Tools;
using LMKit.Agents.Tools.BuiltIn;

LM model = LM.LoadFromModelID("gemma3:4b"); var chat = new MultiTurnConversation(model);

chat.SystemPrompt = "You are a research assistant."; chat.Tools.Register(BuiltInTools.WebSearch); chat.Tools.Register(BuiltInTools.Calculator);

chat.BeforeToolInvocation += (sender, e) => Console.WriteLine($"Calling tool: {e.ToolCall.Name}");

chat.AfterToolInvocation += (sender, e) => Console.WriteLine($"Tool result: {e.ToolCallResult.ResultJson}");

var result1 = chat.Submit("What is the square root of 144?"); var result2 = chat.Submit("Now multiply that by 3.");

Console.WriteLine($"Messages: {chat.ChatHistory.MessageCount}"); Console.WriteLine($"Context remaining: {chat.ContextRemainingSpace} tokens");

Long-term memory with AgentMemory:

using LMKit.Model;
using LMKit.TextGeneration;
using LMKit.Agents;

LM model = LM.LoadFromModelID("gemma3:4b"); var chat = new MultiTurnConversation(model);

chat.Memory = new AgentMemory(model); chat.MaximumRecallTokens = 512;

chat.MemoryRecall += (sender, e) => { Console.WriteLine($"Recalled from '{e.MemoryCollection}': {e.MemoryText}"); };

var result = chat.Submit("Summarize what we discussed yesterday."); Console.WriteLine(result.Completion);

Properties

ChatHistory

The full chat history of this conversation (system, user, assistant, and tool messages).

ContextRemainingSpace

Remaining token budget currently available in the context window.

ContextSize

Total token context size for this conversation.

MaximumRecallTokens

Maximum number of tokens recalled from Memory per turn.

Defaults to ContextSize / 4. The effective value is automatically capped to at most ContextSize / 2.

Memory

Long-term memory store used to recall relevant context across turns.

Assign an AgentMemory implementation to enable retrieval of relevant text partitions. Retrieved snippets are injected as hidden context up to MaximumRecallTokens.

Skills

Registry of Agent Skills available to this conversation.

Skills provide modular capabilities with specialized knowledge and workflows, following the Agent Skills specification.

ToolPolicy

Per-turn tool-calling policy used by the conversation runtime.

Controls whether tools are allowed, required, disabled, or whether a specific tool must be used on the current turn.

Tools

Registry of model-callable tools available to this conversation.

Register tools before the first user turn so they are advertised to the model. Tool invocation requires a model that supports tool calls.

Methods

ClearHistory()

Clear the entire conversation: removes all messages and resets internal state.

Events

AfterToolInvocation

Fired after a tool invocation finishes (or when it was cancelled/errored).

BeforeToolInvocation

Fired before a tool invocation. Handlers may cancel the call.

MemoryRecall

Fired when one or more memory partitions are recalled for this turn.

Subscribers may inspect the recalled content and optionally cancel injection by setting Cancel to true.

ToolApprovalRequired

Fired when a tool invocation requires user approval before execution.

Share