Skip to main content

Agent Chat Service

Description

The per-character dialogue agent. AgentChatService is the MonoBehaviour you place on an NPC; it resolves the agent's chat tree, owns the agent's mood and non-verbal eventing, and either owns or delegates the agent's identity, blackboard, and pause state.

For setup and authoring guidance, see Dialogue Agents.

Interface

Type
IListenerAwareDialogueAgentService
IBlackboardValueOwner

IListenerAwareDialogueAgentService extends IDialogueAgentService, which extends the shared IAgentService.

Inherits

Type
MonoBehaviour

Inspector Fields

NameTypeDescription
chatTreeChatTreeDataTree used for player conversations.
headlessChatTreeChatTreeDataTree used for agent-to-agent conversations.
localTreeSelectionOverridesDialogueTreeSelectionRule[]Per-agent conditional tree rules, checked first.
sharedTreeSelectionDialogueTreeSelectionRepositoryShared rule set, checked after the local overrides.
portraitSpritePortrait shown while this agent speaks.
moodRepositoryMoodRepositoryThe moods available to this agent.
blackboardValueTemplatesBlackboardValueTemplate[]Shared blackboard seed values, applied first.
blackboardValuesBlackboardValue[]Agent-specific blackboard seed values, applied second.

Public Methods

NameParametersReturn TypeDescription
InitializeN/AvoidPrepares the agent for use. Called automatically on start; safe to call again.
FetchChatTreeN/AChatTreeDataReturns the plain chat tree field.
FetchChatTreeDialogueParticipants participantsChatTreeDataRuns tree selection: local overrides, then shared rules, then repository fallback, then the plain field.
FetchHeadlessChatTreeN/AChatTreeDataReturns the headless tree field. Not rule-selected.
GetLocalTreeSelectionOverridesN/AIReadOnlyList<DialogueTreeSelectionRule>Every local rule, including ones that did not win selection.
GetSharedTreeSelectionN/ADialogueTreeSelectionRepositoryThe shared rule repository, if one is assigned.
GetMoodServiceN/AIDialogueMoodServiceThis agent's mood service, initializing first if needed.
GetNonVerbalEventingServiceN/ANonVerbalEventingServiceThis agent's non-verbal eventing, initializing first if needed.
GetPauseServiceN/AIPauseServiceThe shared agent's pause service, or its own.
GetBlackboardServiceN/AIBlackboardServiceThe shared agent's blackboard, or its own.
GetBlackboardValuesN/ABlackboardValue[]The agent-specific seed values.
GetBlackboardValueTemplatesN/ABlackboardValueTemplate[]The template assets assigned to this agent.
SetBlackboardValuesBlackboardValue[] valuesvoidReplaces the agent-specific values and re-applies them.
SetBlackboardValueTemplatesBlackboardValueTemplate[] templatesvoidReplaces the templates and re-applies them.
GetResolvedBlackboardValuesN/ABlackboardValue[]Template values followed by agent values, in application order.
GetPortraitN/ASpriteThe agent's portrait.
GetIDN/AstringThe shared agent's ID, or a GUID generated on first use.
GetDisplayNameN/AstringThe shared agent's display name, or null when standalone.

IDialogueAgentService

The interface the conversation runtime actually depends on. Implement it to supply a dialogue agent that is not an AgentChatService.

MemberReturn Type
FetchChatTree()ChatTreeData
FetchHeadlessChatTree()ChatTreeData
GetMoodService()IDialogueMoodService
GetNonVerbalEventingService()NonVerbalEventingService
GetPortrait()Sprite

Plus the shared IAgentService members: GetPauseService(), GetBlackboardService(), GetID(), GetDisplayName().

IListenerAwareDialogueAgentService

Adds the one method that lets tree choice depend on who is listening.

MemberReturn Type
FetchChatTree(DialogueParticipants participants)ChatTreeData

The runtime checks for this interface and falls back to FetchChatTree() when an agent does not implement it.

IDialogueTreeSelector

Decides which rule wins. Register an implementation to replace the default.

MemberReturn Type
SelectTree(IReadOnlyList<DialogueTreeSelectionRule> rules, DialogueParticipants participants)ChatTreeData

RequirementGatedDialogueTreeSelector is the built-in default: first matching rule wins, a rule with no tree is skipped, and a rule with no requirement collection always matches.

DialogueAgentResolver

Static helper used to find the agent behind a GameObject.

NameParametersReturn TypeDescription
ResolveSharedAgentGameObject targetIAgentServiceReturns a non-dialogue IAgentService on the object if there is one, otherwise a dialogue agent.
ResolveSharedAgentInParentsTransform targetIAgentServiceWalks up the hierarchy applying the same rule.

When a CivilAI agent and an AgentChatService share a GameObject, the CivilAI agent is returned -- it is the identity for that character.