AIAgent Class |
public class AIAgent
The AIAgent type exposes the following members.
| Name | Description | |
|---|---|---|
| AIAgent(AIAgentConfiguration) | Creates an AIAgent directly from an existing AIAgentConfiguration instance. | |
| AIAgent(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. |
| Name | Description | |
|---|---|---|
| Configuration | The configuration used to build this agent. | |
| EffectiveTitle | Title when set, otherwise the first user message truncated to 100 characters. | |
| LastChatUsage | 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). | |
| MessageCount | Number of messages currently in the conversation (including the system prompt when present). | |
| Messages | Full conversation history, including the system prompt (if any), all user turns, and all agent replies. Exposed so callers can inspect or serialise it. | |
| TotalUsage | Cumulative token and call usage of the whole conversation, including title generation. Reset by Clear. |
| Name | Description | |
|---|---|---|
| Chat | 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. | |
| ChatHtml | Same as Chat(String, ICancelOperation, ReportExecutionLog, ReportExecutionLog, Int32, ActionString) but returns the reply sanitized as safe HTML. | |
| ChatSimple | 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. | |
| Clear | Resets the conversation history, re-seeding it with the system prompt when one is configured. | |
| Equals | Determines whether the specified object is equal to the current object. (Inherited from Object) | |
| Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object) | |
| GenerateTitle | 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. | |
| GetHashCode | Serves as the default hash function. (Inherited from Object) | |
| GetType | Gets the Type of the current instance. (Inherited from Object) | |
| LoadFromFile | 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. | |
| LoadFromSessionFile | Restores the conversation history from a ChatSessionFile. The current Messages list is cleared first. | |
| MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object) | |
| OverrideSystemPrompt | 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. | |
| RewindToUserMessage | 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. | |
| SaveToFile | Saves the current conversation to a JSON file. | |
| ToSessionFile | Serialises the current conversation to a ChatSessionFile object. | |
| ToString | Returns a string that represents the current object. (Inherited from Object) |
| Name | Description | |
|---|---|---|
| Culture | 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. | |
| MaxToolResultLength | 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. | |
| SecurityContext | Current security user of the agent | |
| Title | Title of the conversation (the saved chat session name). Null until the chat is saved or loaded; see EffectiveTitle. |