Class Agent
AI Agent that can generate responses using various models and manage conversations.
- Wraps model, tools, audio, and conversation management in a single fa�?��de.
- Uses internal services for conversations, tool calls, and audio I/O.
- Acts as the main entry point for runtime chat / tool workflows.
Implements
Inherited Members
Namespace: Glitch9.AIDevKit.Agents
Assembly: Glitch9.AIDevKit.dll
Syntax
public sealed class Agent : IDisposable
Remarks
Warning: Do not attempt to change ConversationManager once Agent is created.
Constructors
| Edit this page View SourceAgent(IAgentBehaviour, IAgentSettings, IMemorySettings, AgentDependencies, IUniTaskStore<AgentSaveData>, ILogger)
Creates a new AI Agent with the specified configuration.
Declaration
public Agent(IAgentBehaviour agentConfig, IAgentSettings agentSettings, IMemorySettings conversationSettings, AgentDependencies dependencies = null, IUniTaskStore<AgentSaveData> saveDataStore = null, ILogger logger = null)
Parameters
| Type | Name | Description |
|---|---|---|
| IAgentBehaviour | agentConfig | Required agent behavior settings (streaming, logging, etc.) |
| IAgentSettings | agentSettings | Required agent configuration (model, instructions, etc.) |
| IMemorySettings | conversationSettings | |
| AgentDependencies | dependencies | Optional custom service implementations |
| IUniTaskStore<AgentSaveData> | saveDataStore | Optional preferences storage implementation |
| ILogger | logger | Optional custom logger |
Fields
| Edit this page View SourceconversationController
Manages conversation state, history, and message persistence.
Declaration
public readonly ConversationController conversationController
Field Value
| Type | Description |
|---|---|
| ConversationController |
mediaController
Manages all media generation including speech-to-text, text-to-speech, and image generation.
Declaration
public readonly MediaController mediaController
Field Value
| Type | Description |
|---|---|
| MediaController |
Properties
| Edit this page View SourceAgentName
Gets or sets the agent's display name.
Declaration
public string AgentName { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
ChatApiType
Gets the chat service API type being used (Default, RealtimeApi, Assistants).
Declaration
public ChatApi ChatApiType { get; }
Property Value
| Type | Description |
|---|---|
| ChatApi |
Conversation
Gets the current conversation context.
Declaration
public Conversation Conversation { get; }
Property Value
| Type | Description |
|---|---|
| Conversation |
ConversationId
Gets or sets the conversation ID for maintaining conversation context.
Declaration
public string ConversationId { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
ConversationSettings
Declaration
public IMemorySettings ConversationSettings { get; }
Property Value
| Type | Description |
|---|---|
| IMemorySettings |
HasInputAudio
Gets whether the agent supports input audio (microphone/speech recognition).
Declaration
public bool HasInputAudio { get; }
Property Value
| Type | Description |
|---|---|
| bool |
HasOutputAudio
Gets whether the agent supports output audio (text-to-speech).
Declaration
public bool HasOutputAudio { get; }
Property Value
| Type | Description |
|---|---|
| bool |
HasOutputImage
Gets whether the agent supports image generation output.
Declaration
public bool HasOutputImage { get; }
Property Value
| Type | Description |
|---|---|
| bool |
Id
Gets the unique identifier for this agent.
Declaration
public string Id { get; }
Property Value
| Type | Description |
|---|---|
| string |
ImageModel
Gets or sets the image generation model used for creating images.
Declaration
public Model ImageModel { get; set; }
Property Value
| Type | Description |
|---|---|
| Model |
InputAudioLanguage
Gets or sets the language locale for input audio transcription.
Declaration
public Locale InputAudioLanguage { get; set; }
Property Value
| Type | Description |
|---|---|
| Locale |
Instructions
Gets or sets the system instructions that define the agent's behavior and context.
Declaration
public string Instructions { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
IsDisposed
Gets whether the agent has been disposed and is no longer usable.
Declaration
public bool IsDisposed { get; }
Property Value
| Type | Description |
|---|---|
| bool |
IsInitialized
Gets whether the agent and all its controllers are fully initialized and ready to use.
Declaration
public bool IsInitialized { get; }
Property Value
| Type | Description |
|---|---|
| bool |
Items
Gets all conversation items (messages and tool outputs).
Declaration
public List<ConversationItem> Items { get; }
Property Value
| Type | Description |
|---|---|
| List<ConversationItem> |
LastMessage
Gets the most recent message in the conversation.
Declaration
public Message LastMessage { get; }
Property Value
| Type | Description |
|---|---|
| Message |
LogLevel
Gets the logging level for agent operations (Off, Error, Warning, Info, Verbose).
Declaration
public TraceLevel LogLevel { get; }
Property Value
| Type | Description |
|---|---|
| TraceLevel |
MaxTokens
Gets the maximum number of tokens the agent can generate.
Declaration
public int? MaxTokens { get; }
Property Value
| Type | Description |
|---|---|
| int? |
Messages
Gets all messages in the conversation.
Declaration
public List<Message> Messages { get; }
Property Value
| Type | Description |
|---|---|
| List<Message> |
Model
Gets or sets the language model used for text generation.
Declaration
public Model Model { get; set; }
Property Value
| Type | Description |
|---|---|
| Model |
OutputAudioVolume
Gets or sets the volume level for output audio playback (0.0 to 1.0).
Declaration
public float OutputAudioVolume { get; set; }
Property Value
| Type | Description |
|---|---|
| float |
Settings
Gets the agent's configuration settings (models, tools, instructions, etc.).
Declaration
public IAgentSettings Settings { get; }
Property Value
| Type | Description |
|---|---|
| IAgentSettings |
SpeechModel
Gets or sets the speech generation model used for text-to-speech.
Declaration
public Model SpeechModel { get; set; }
Property Value
| Type | Description |
|---|---|
| Model |
Status
Gets the current lifecycle status of the agent (None, Initializing, Ready, GeneratingResponse, etc.).
Declaration
public AgentStatus Status { get; }
Property Value
| Type | Description |
|---|---|
| AgentStatus |
Stream
Gets whether streaming is enabled for responses.
Declaration
public bool Stream { get; }
Property Value
| Type | Description |
|---|---|
| bool |
Temperature
Gets the temperature setting for response generation (0.0 = deterministic, higher = more creative).
Declaration
public float? Temperature { get; }
Property Value
| Type | Description |
|---|---|
| float? |
ToolChoice
Gets or sets the tool choice strategy (auto, required, none, or specific tool).
Declaration
public ToolChoice ToolChoice { get; set; }
Property Value
| Type | Description |
|---|---|
| ToolChoice |
Tools
Gets or sets the list of tools available to the agent.
Declaration
public List<Tool> Tools { get; }
Property Value
| Type | Description |
|---|---|
| List<Tool> |
TranscriptionModel
Gets or sets the transcription model used for speech-to-text.
Declaration
public Model TranscriptionModel { get; set; }
Property Value
| Type | Description |
|---|---|
| Model |
UserName
The name this agent uses when referring to the user (e.g., in conversations or logs). It does not affect authentication or API calls, and is purely for display and contextual purposes
Declaration
public string UserName { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
Voice
Gets or sets the voice used for speech generation.
Declaration
public Voice Voice { get; set; }
Property Value
| Type | Description |
|---|---|
| Voice |
Methods
| Edit this page View SourceCancelRequest()
Cancels all ongoing requests including chat, image generation, speech, transcription, and MCP operations.
Declaration
public void CancelRequest()
Dispose()
Disposes the agent and releases all resources including active requests and services.
Declaration
public void Dispose()
InitializeAsync()
Initializes the agent asynchronously. Loads saved parameters, conversation history, and services. Must be called before using the agent unless AutoInit is enabled.
Declaration
public UniTask InitializeAsync()
Returns
| Type | Description |
|---|---|
| UniTask |
Remarks
Safe to call multiple times - will skip if already initialized.
RegisterCallback<T>(Action<T>)
Registers an event handler for agent events.
Declaration
public IDisposable RegisterCallback<T>(Action<T> handler) where T : IEvent
Parameters
| Type | Name | Description |
|---|---|---|
| Action<T> | handler | The event handler callback |
Returns
| Type | Description |
|---|---|
| IDisposable |
Type Parameters
| Name | Description |
|---|---|
| T | The event payload type |
RegisterEvent<T>(Action<T>)
Declaration
[Obsolete("Use RegisterCallback instead. This method will be removed in future versions.")]
public IDisposable RegisterEvent<T>(Action<T> handler) where T : IEvent
Parameters
| Type | Name | Description |
|---|---|---|
| Action<T> | handler |
Returns
| Type | Description |
|---|---|
| IDisposable |
Type Parameters
| Name | Description |
|---|---|
| T |
RegisterMcpApprovalHandler(string, IMcpApprovalHandler)
Registers an MCP approval handler for a specific server.
Declaration
public void RegisterMcpApprovalHandler(string serverLabel, IMcpApprovalHandler handler)
Parameters
| Type | Name | Description |
|---|---|---|
| string | serverLabel | The MCP server identifier |
| IMcpApprovalHandler | handler | The approval handler implementation |
RegisterOAuthTokenProvider(string, IOAuthTokenProvider)
Registers an OAuth token provider for MCP server authentication.
Declaration
public void RegisterOAuthTokenProvider(string serverLabel, IOAuthTokenProvider provider)
Parameters
| Type | Name | Description |
|---|---|---|
| string | serverLabel | The MCP server identifier |
| IOAuthTokenProvider | provider | The OAuth token provider |
RegisterTool(Tool)
Registers a single tool for agent use.
Declaration
public void RegisterTool(Tool tool)
Parameters
| Type | Name | Description |
|---|---|---|
| Tool | tool | The tool to register |
RegisterToolDefinition(HostedToolDefinitionBase)
Registers a tool definition that will be automatically instantiated.
Declaration
public void RegisterToolDefinition(HostedToolDefinitionBase toolDef)
Parameters
| Type | Name | Description |
|---|---|---|
| HostedToolDefinitionBase | toolDef | The tool definition to register |
RegisterToolDefinitions(IEnumerable<HostedToolDefinitionBase>)
Registers multiple tool definitions at once.
Declaration
public void RegisterToolDefinitions(IEnumerable<HostedToolDefinitionBase> toolDefs)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<HostedToolDefinitionBase> | toolDefs | The tool definitions to register |
RegisterToolExecutor<TCall, TOutput>(IToolCallExecutor<TCall, TOutput>)
Registers a custom tool executor for handling specific tool call types.
Declaration
public void RegisterToolExecutor<TCall, TOutput>(IToolCallExecutor<TCall, TOutput> executor) where TCall : ToolCall where TOutput : ToolOutput
Parameters
| Type | Name | Description |
|---|---|---|
| IToolCallExecutor<TCall, TOutput> | executor | The executor implementation |
Type Parameters
| Name | Description |
|---|---|
| TCall | The tool call type |
| TOutput | The tool output type |
RegisterTools(IEnumerable<Tool>)
Registers multiple tools at once.
Declaration
public void RegisterTools(IEnumerable<Tool> tools)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<Tool> | tools | The tools to register |
SendAsync(ConversationItem, int, CancellationToken)
Sends a conversation item (message or tool output) to the agent and returns the response.
Declaration
public UniTask<Generated<ConversationItem>> SendAsync(ConversationItem inputItem, int index = -1, CancellationToken ct = default)
Parameters
| Type | Name | Description |
|---|---|---|
| ConversationItem | inputItem | The conversation item to send |
| int | index | Optional conversation index (-1 for append to end) |
| CancellationToken | ct | Cancellation token |
Returns
| Type | Description |
|---|---|
| UniTask<Generated<ConversationItem>> | Agent's response including text, tool calls, or audio |
SendAsync(Message, int, CancellationToken)
Sends a message object to the agent and returns the response.
Declaration
public UniTask<Generated<ConversationItem>> SendAsync(Message message, int index = -1, CancellationToken ct = default)
Parameters
| Type | Name | Description |
|---|---|---|
| Message | message | The message to send |
| int | index | Optional conversation index (-1 for append to end) |
| CancellationToken | ct | Cancellation token |
Returns
| Type | Description |
|---|---|
| UniTask<Generated<ConversationItem>> | Agent's response including text, tool calls, or audio |
SendAsync(string, int, CancellationToken)
Sends a text message to the agent and returns the response.
Declaration
public UniTask<Generated<ConversationItem>> SendAsync(string text, int index = -1, CancellationToken ct = default)
Parameters
| Type | Name | Description |
|---|---|---|
| string | text | The message text to send |
| int | index | Optional conversation index (-1 for append to end) |
| CancellationToken | ct | Cancellation token |
Returns
| Type | Description |
|---|---|
| UniTask<Generated<ConversationItem>> | Agent's response including text, tool calls, or audio |
SetInstructionsUpdater(IInstructionsUpdater)
Replaces the active instructions updater at runtime.
Pass null to stop dynamic updates (instructions remain as last set).
Declaration
public void SetInstructionsUpdater(IInstructionsUpdater updater)
Parameters
| Type | Name | Description |
|---|---|---|
| IInstructionsUpdater | updater | The updater implementation to use, or |
SetToolRouter(IToolRouter)
Replaces the active tool router at runtime.
Pass null to disable routing (all tools forwarded to the LLM).
Declaration
public void SetToolRouter(IToolRouter router)
Parameters
| Type | Name | Description |
|---|---|---|
| IToolRouter | router | The router implementation to use, or |
StartTranscription()
Starts recording audio input for transcription, if supported.
Declaration
public void StartTranscription()
Remarks
This call proxies StartTranscription() and uses the configured Glitch9.AIDevKit.Agents.Agent.InputAudioRecorder when available.
StopTranscription()
Stops recording audio input and submits the captured audio for transcription.
Declaration
public void StopTranscription()
Remarks
This call proxies StopTranscription() and will only have an effect if audio recording was previously started.
SubmitMcpApprovalRequest(McpApprovalRequest)
Declaration
public void SubmitMcpApprovalRequest(McpApprovalRequest approvalRequest)
Parameters
| Type | Name | Description |
|---|---|---|
| McpApprovalRequest | approvalRequest |
SubmitToolOutput(string, ToolOutput)
Manually submits a tool output for unhandled tool calls. Used when UnhandledToolCallBehaviour is set to SubmitToolOutput. The tool output will be cached and batch-submitted with other outputs when the response is complete.
Declaration
public void SubmitToolOutput(string responseId, ToolOutput toolOutput)
Parameters
| Type | Name | Description |
|---|---|---|
| string | responseId | The response ID that contains the tool call |
| ToolOutput | toolOutput | The tool execution result to submit |
UnregisterCallback<T>(Action<T>)
Unregisters an event handler.
Declaration
public void UnregisterCallback<T>(Action<T> handler) where T : IEvent
Parameters
| Type | Name | Description |
|---|---|---|
| Action<T> | handler | The event handler to remove |
Type Parameters
| Name | Description |
|---|---|
| T | The event payload type |
UnregisterEvent<T>(Action<T>)
Declaration
[Obsolete("Use UnregisterCallback instead. This method will be removed in future versions.")]
public void UnregisterEvent<T>(Action<T> handler) where T : IEvent
Parameters
| Type | Name | Description |
|---|---|---|
| Action<T> | handler |
Type Parameters
| Name | Description |
|---|---|
| T |
UnregisterMcpApprovalHandler(string)
Unregisters an MCP approval handler for a specific server.
Declaration
public bool UnregisterMcpApprovalHandler(string serverLabel)
Parameters
| Type | Name | Description |
|---|---|---|
| string | serverLabel | The MCP server identifier |
Returns
| Type | Description |
|---|---|
| bool | True if successfully unregistered, false otherwise |
UnregisterOAuthTokenProvider(string)
Unregisters an OAuth token provider for a specific server.
Declaration
public bool UnregisterOAuthTokenProvider(string serverLabel)
Parameters
| Type | Name | Description |
|---|---|---|
| string | serverLabel | The MCP server identifier |
Returns
| Type | Description |
|---|---|
| bool | True if successfully unregistered, false otherwise |
UnregisterTool(Tool)
Unregisters a single tool.
Declaration
public void UnregisterTool(Tool tool)
Parameters
| Type | Name | Description |
|---|---|---|
| Tool | tool | The tool to unregister |
UnregisterToolDefinition(HostedToolDefinitionBase)
Unregisters a tool definition.
Declaration
public void UnregisterToolDefinition(HostedToolDefinitionBase toolDef)
Parameters
| Type | Name | Description |
|---|---|---|
| HostedToolDefinitionBase | toolDef | The tool definition to unregister |
UnregisterToolDefinitions(IEnumerable<HostedToolDefinitionBase>)
Unregisters multiple tool definitions at once.
Declaration
public void UnregisterToolDefinitions(IEnumerable<HostedToolDefinitionBase> toolDefs)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<HostedToolDefinitionBase> | toolDefs | The tool definitions to unregister |
UnregisterToolExecutor<TCall, TOutput>(IToolCallExecutor<TCall, TOutput>)
Unregisters a previously registered tool executor.
Declaration
public bool UnregisterToolExecutor<TCall, TOutput>(IToolCallExecutor<TCall, TOutput> executor) where TCall : ToolCall where TOutput : ToolOutput
Parameters
| Type | Name | Description |
|---|---|---|
| IToolCallExecutor<TCall, TOutput> | executor | The executor to unregister |
Returns
| Type | Description |
|---|---|
| bool | True if successfully unregistered, false otherwise |
Type Parameters
| Name | Description |
|---|---|
| TCall | The tool call type |
| TOutput | The tool output type |
UnregisterTools(IEnumerable<Tool>)
Unregisters multiple tools at once.
Declaration
public void UnregisterTools(IEnumerable<Tool> tools)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<Tool> | tools | The tools to unregister |