Dynamic context scripting API
Reference for the Convai Unity SDK dynamic context scripting interface, including every method, the respond mode enum, and the attention object API.
ConvaiCharacter.DynamicContext returns the IConvaiDynamicContext interface — the scripting surface for tracked state, chronological events, attention-object updates, and raw context sends. This page documents every interface member, the ConvaiRespondMode enum that controls whether an update triggers a spoken reply, and the ConvaiDynamicContextUpdate type used by Apply.
using Convai.Runtime.Components;
using Convai.Runtime.DynamicContext;
IConvaiDynamicContext context = character.DynamicContext;DynamicContext is available on every ConvaiCharacter instance and requires no additional setup. Every method below takes a ConvaiRespondMode value to control whether the update triggers a spoken reply.
Method reference
Every tracked method below stages its change in the local tracker; Convai receives the update in the next dynamic context batch — a background flush that fires after ConvaiCharacter.DynamicContextBatchDelaySeconds (0.5 seconds by default) or immediately when Flush() is called, capped at an internal maximum delay so staged changes are never held indefinitely. When more than one reaction is requested before a batch flushes, the strongest value wins for the whole batch, ranked Silent < Auto < MustRespond. See Sync behavior and timing for the exact batch window and message content.
SetState
void SetState(string name, string value,
ConvaiRespondMode reaction = ConvaiRespondMode.Silent)Sets or updates one tracked state entry. If name has not been set before, Convai adds it to the canonical context in the order it was first set. If value is identical to the current value, the call is a no-op — nothing is staged.
name
string
—
State identifier. Must be non-empty and non-whitespace. Case-sensitive.
value
string
—
State value. May be an empty string. Cannot be null.
reaction
ConvaiRespondMode
Silent
Requested reaction for this change.
SetStates
void SetStates(IReadOnlyDictionary<string, string> states,
ConvaiRespondMode reaction = ConvaiRespondMode.Silent)Sets or updates multiple tracked state entries in one call, each staged with the same reaction value. Prefer SetStates over sequential SetState calls when several values change at the same moment.
states
IReadOnlyDictionary<string, string>
—
Map of state names to values. Must have at least one entry.
reaction
ConvaiRespondMode
Silent
Requested reaction applied to every entry in this call.
If states is null or empty, Convai logs a warning (Cannot set empty dynamic context states) and the call returns without staging anything. Individual invalid entries (empty name, null value) are skipped; the remaining valid entries in the same call still stage.
AddEvent
Appends a chronological event entry. Events accumulate after all states in the canonical context and are never replaced by a later call.
text
string
—
Event description. Must be non-empty and non-whitespace.
reaction
ConvaiRespondMode
Auto
Requested reaction. Note the default differs from SetState and SetStates, which default to Silent.
Calling AddEvent with identical text more than once before the pending batch flushes stages only one entry. The dedup window resets after each flush — the same text staged in a later batch is added again.
RemoveState
Removes a tracked state by name and stages an updated canonical context for the next batch. If name is not currently tracked, the call is a no-op — nothing is staged and no warning is logged.
name
string
Name of the state to remove. Must be non-empty; an empty or whitespace value logs a warning (Dynamic context state name cannot be empty) and the call returns immediately.
RemoveState has no reaction parameter. The staged change always carries ConvaiRespondMode.Silent — removing a state never triggers an immediate reply on its own.
Reset
Clears every tracked state and event and stages a Reset message for Convai.
removeStatic
bool
false
When true, the reset also asks Convai to remove the character's static initial dynamic context for the current session. When false, only the runtime tracker is cleared.
Reset has no reaction parameter — the staged Reset message always carries ConvaiRespondMode.Silent. See Static context at connection time for how the static initial dynamic context is set.
SetCurrentAttentionObject
Stages the object Convai should treat as the character's current focus for reference grounding — resolving vague player language such as "pick that up" to a specific registered target.
currentAttentionObject
object
—
Accepts a string object name or a ConvaiActionObjectDefinition reference. Any other type, or null, is rejected.
reaction
ConvaiRespondMode
Silent
Requested reaction for the focus change.
See Attention and reference grounding for the full grounding model, silent-failure conditions, and usage examples.
ClearCurrentAttentionObject
Stages a clear for the current attention object. Convai treats the character as having no specific focus until the next SetCurrentAttentionObject call.
reaction
ConvaiRespondMode
Silent
Requested reaction for the clear.
Flush
Sends any staged dynamic context (and pending scene-metadata) changes immediately, without waiting for the batch window. Flush is a no-op when the character is not in an active conversation — staged data remains pending and is included in the batch sent automatically once the character becomes ready.
TryGetStateValue
Reads the current value of a tracked state from the local tracker. No network call is made.
name
string
State name to look up.
value
out string
Set to the current value if found; null if not found.
Returns: true if the state exists in the local tracker; false if it was never set, has been removed, or was sent through Apply (which bypasses the tracker).
Apply
Sends a raw typed update directly to the transport layer, bypassing the local tracker and the batch queue. Use for advanced cases that construct context text externally, or that combine a context update with a runtime action-config patch or attention-object change in one message — see ConvaiActionConfigPatch in the character actions scripting reference.
update is null
Warning: Raw dynamic context update cannot be null. Call returns without sending.
update.Mode is not Reset, and Text, ActionConfig, and CurrentAttentionObject are all null
Warning: Raw dynamic context updates require text, action_config, current_attention_object, or Reset mode. Call returns without sending.
Character is not in an active conversation
Warning: Cannot apply raw dynamic context update: not in conversation. Update discarded.
ConvaiDynamicContextUpdate
Convai.Runtime.DynamicContext — sealed class
Advanced typed request used by Apply to send raw dynamic context updates without exposing transport strings.
text
string
—
Context text to send. At least one of text, actionConfig, or currentAttentionObject must be set, or mode must be Reset.
mode
ConvaiContextUpdateMode
Append
How Convai applies the text.
reaction
ConvaiRespondMode
Auto
Whether the update triggers a spoken reply.
removeStatic
bool
false
When mode is Reset and this is true, also asks Convai to remove the character's static initial dynamic context for the session.
currentAttentionObject
object
null
Attention object to set alongside this update. Accepts a string object name or a ConvaiActionObjectDefinition reference.
updateId
string
null
Correlates this update with its backend acknowledgement. Auto-generated when omitted.
actionConfig
ConvaiActionConfigPatch
null
Runtime action-config patch to apply alongside this context update. See Character actions scripting reference.
ConvaiContextUpdateMode
Used by Apply and ConvaiDynamicContextUpdate.
Append
Adds the text to the existing Dynamic Context without replacing prior content.
Replace
Replaces the entire Dynamic Context with the provided text.
Reset
Clears all Dynamic Context. The text parameter is ignored when mode is Reset.
ConvaiRespondMode
Convai.Runtime — the single respond-mode vocabulary shared by dynamic context and dynamic vision.
Silent
silent
Absorbed into the character's awareness; never triggers a spoken reply on its own.
Auto
auto
Convai decides whether the update warrants a spoken reply.
MustRespond
must_respond
Always triggers a spoken reply after the update.
Default reaction mode reference
SetState
Silent
SetStates
Silent
AddEvent
Auto
RemoveState
(no reaction parameter; always Silent)
Reset
(no reaction parameter; always Silent)
SetCurrentAttentionObject
Silent
ClearCurrentAttentionObject
Silent
Apply / ConvaiDynamicContextUpdate
Auto
Next steps
Sync behavior and timingRelay component referenceHow action target resolution worksTroubleshoot dynamic contextLast updated
Was this helpful?