Click or drag to resize

AIAgent Class

Stateful AI agent that owns a conversation history and delegates to an IAIProvider for all model calls. Initialise once per session or per conversation; call Chat(String, ICancelOperation, ReportExecutionLog, ReportExecutionLog, Int32, ActionString) for each user turn.
Inheritance Hierarchy
SystemObject
  Seal.AIAIAgent

Namespace: Seal.AI
Assembly: SealLibrary (in SealLibrary.dll) Version: 10.0.1.0+a44cd3a7f03c2bf3cdbd971a878c679e40bed08a
Syntax
C#
public class AIAgent

The AIAgent type exposes the following members.

Constructors
 NameDescription
Public methodAIAgent(AIAgentConfiguration) Creates an AIAgent directly from an existing AIAgentConfiguration instance.
Public methodAIAgent(String) Creates an AIAgent from a named AIAgentConfiguration. Injects the configuration's EffectiveSystemPrompt as the first message in the conversation when it is not empty.
Top
Properties
 NameDescription
Public propertyConfiguration The configuration used to build this agent.
Public propertyEffectiveTitleTitle when set, otherwise the first user message truncated to 100 characters.
Public propertyLastChatUsage Token and call usage of the last Chat(String, ICancelOperation, ReportExecutionLog, ReportExecutionLog, Int32, ActionString) exchange (summed over all model round-trips of the tool loop).
Public propertyMessageCount Number of messages currently in the conversation (including the system prompt when present).
Public propertyMessages Full conversation history, including the system prompt (if any), all user turns, and all agent replies. Exposed so callers can inspect or serialise it.
Public propertyTotalUsage Cumulative token and call usage of the whole conversation, including title generation. Reset by Clear.
Top
Methods
 NameDescription
Public methodChat Appends a user message to the conversation history, calls the AI using the tools scoped to this agent (via GetToolConfigurations) plus a built-in load_skill tool when the agent has skills (via GetSkillConfigurations), executes any tool calls the AI requests, and repeats until a plain reply is produced or maxIterations is reached. Falls back to a plain HandleChat(ListChatMessage) call when no tools and no skills are configured.
Public methodChatHtml Same as Chat(String, ICancelOperation, ReportExecutionLog, ReportExecutionLog, Int32, ActionString) but returns the reply sanitized as safe HTML.
Public methodChatSimple Sends a plain user message to the AI without any tools and returns the reply. Useful when you want a simple single-turn exchange that bypasses the agentic tool loop.
Public methodClear Resets the conversation history, re-seeding it with the system prompt when one is configured.
Public methodEqualsDetermines whether the specified object is equal to the current object.
(Inherited from Object)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object)
Public methodGenerateTitle Asks the AI to summarise the current conversation as a short, friendly title (a few words). Uses the same provider/model as the conversation, without tools, and works on a copy of Messages so the persisted history is never modified. Returns null when no conversation exists yet or on any failure, so callers can fall back to their default naming.
Public methodGetHashCodeServes as the default hash function.
(Inherited from Object)
Public methodGetTypeGets the Type of the current instance.
(Inherited from Object)
Public methodStatic memberLoadFromFile Loads a conversation from a JSON file and returns both the agent and the embedded session metadata. The agent is built from the configuration whose Name matches the Name info key; falls back to the default configuration when not found.
Public methodLoadFromSessionFile Restores the conversation history from a ChatSessionFile. The current Messages list is cleared first.
Protected methodMemberwiseCloneCreates a shallow copy of the current Object.
(Inherited from Object)
Public methodOverrideSystemPrompt Replaces the leading system message in Messages with prompt. If prompt is null or whitespace the existing system message (if any) is simply removed. Call this before Chat(String, ICancelOperation, ReportExecutionLog, ReportExecutionLog, Int32, ActionString) to inject a parameter-driven system prompt that overrides the one from EffectiveSystemPrompt.
Public methodRewindToUserMessage Rewinds the conversation to just before the user turn at userMessageIndex (0-based, counting only user messages). Removes that user message and every message that followed it — including the assistant replies, tool calls and tool results — so the conversation returns to the state it had before that message was sent. Returns the text of the removed user message (so the caller can re-populate the input box), or null when the index is out of range.
Public methodSaveToFile Saves the current conversation to a JSON file.
Public methodToSessionFile Serialises the current conversation to a ChatSessionFile object.
Public methodToStringReturns a string that represents the current object.
(Inherited from Object)
Top
Fields
 NameDescription
Public fieldCulture Two-letter ISO culture code (e.g. "fr") used to translate the progress ("thinking") labels in the caller's locale. Set it per request from the session culture before calling Chat(String, ICancelOperation, ReportExecutionLog, ReportExecutionLog, Int32, ActionString); leave null to use the repository's current culture.
Public fieldStatic memberMaxToolResultLength Hard ceiling (in characters) for a single tool result appended to the conversation. A result larger than this (roughly 50k tokens) would risk exceeding the model's context window — and since the history is resent on every turn, it would brick the whole session.
Public fieldSecurityContext Current security user of the agent
Public fieldTitle Title of the conversation (the saved chat session name). Null until the chat is saved or loaded; see EffectiveTitle.
Top
See Also