Class DefaultInstructionsUpdater
LLM-driven dynamic instructions updater with embedding-based topic shift detection.
No rules need to be defined manually. The updater uses embeddings to detect topic shifts and only calls the LLM to regenerate system instructions when a shift is detected.
How it works:
- Every turn: embed the user message (cheap)
- Compare cosine similarity against the cached embedding
- If similarity < TopicShiftThreshold, regenerate instructions via LLM (expensive)
- Otherwise reuse the cached instructions (returns null)
var updater = new DefaultInstructionsUpdater(embeddingModel, generationModel)
.SetMetaInstructions("This agent helps customers with our SaaS product.")
.SetTopicShiftThreshold(0.80f)
.SetMaxTokens(300);
agent.SetInstructionsUpdater(updater);
Inheritance
Implements
Inherited Members
Namespace: Glitch9.AIDevKit.Agents
Assembly: Glitch9.AIDevKit.dll
Syntax
public sealed class DefaultInstructionsUpdater : InstructionsUpdaterBase<IDefaultInstructionsUpdaterSettings>, IInstructionsUpdater
Constructors
| Edit this page View SourceDefaultInstructionsUpdater(IDefaultInstructionsUpdaterSettings, ILogger)
Declaration
public DefaultInstructionsUpdater(IDefaultInstructionsUpdaterSettings settings, ILogger logger)
Parameters
| Type | Name | Description |
|---|---|---|
| IDefaultInstructionsUpdaterSettings | settings | Optional skip filter settings. Uses InstructionsSettings.Default when null. |
| ILogger | logger | Optional logger. |
Methods
| Edit this page View SourceInvalidate()
Clears the cache, forcing the LLM to be called again on the next turn.
Declaration
public void Invalidate()
ShouldSkip(string)
Returns true if the message is trivially short or meaningless and should skip instruction update. Override in subclasses to add additional skip conditions; call base.ShouldSkip() first.
Declaration
public override bool ShouldSkip(string lastUserMessage)
Parameters
| Type | Name | Description |
|---|---|---|
| string | lastUserMessage |
Returns
| Type | Description |
|---|---|
| bool |
Overrides
| Edit this page View SourceUpdateInstructionsAsync(string, CancellationToken)
Returns updated system instructions for the next request.
Called automatically before every SendAsync(string, int, CancellationToken) call.
Return null to keep the current instructions unchanged.
Declaration
public override UniTask<string> UpdateInstructionsAsync(string lastUserMessage, CancellationToken ct = default)
Parameters
| Type | Name | Description |
|---|---|---|
| string | lastUserMessage | The user's message that triggered this request. |
| CancellationToken | ct | Cancellation token. |
Returns
| Type | Description |
|---|---|
| UniTask<string> |