Search Results for

    Show / Hide Table of Contents

    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.
    Inheritance
    object
    Agent
    Implements
    IDisposable
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.ReferenceEquals(object, object)
    object.ToString()
    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 Source

    Agent(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 Source

    conversationController

    Manages conversation state, history, and message persistence.

    Declaration
    public readonly ConversationController conversationController
    Field Value
    Type Description
    ConversationController
    | Edit this page View Source

    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 Source

    AgentName

    Gets or sets the agent's display name.

    Declaration
    public string AgentName { get; set; }
    Property Value
    Type Description
    string
    | Edit this page View Source

    ChatApiType

    Gets the chat service API type being used (Default, RealtimeApi, Assistants).

    Declaration
    public ChatApi ChatApiType { get; }
    Property Value
    Type Description
    ChatApi
    | Edit this page View Source

    Conversation

    Gets the current conversation context.

    Declaration
    public Conversation Conversation { get; }
    Property Value
    Type Description
    Conversation
    | Edit this page View Source

    ConversationId

    Gets or sets the conversation ID for maintaining conversation context.

    Declaration
    public string ConversationId { get; set; }
    Property Value
    Type Description
    string
    | Edit this page View Source

    ConversationSettings

    Declaration
    public IMemorySettings ConversationSettings { get; }
    Property Value
    Type Description
    IMemorySettings
    | Edit this page View Source

    HasInputAudio

    Gets whether the agent supports input audio (microphone/speech recognition).

    Declaration
    public bool HasInputAudio { get; }
    Property Value
    Type Description
    bool
    | Edit this page View Source

    HasOutputAudio

    Gets whether the agent supports output audio (text-to-speech).

    Declaration
    public bool HasOutputAudio { get; }
    Property Value
    Type Description
    bool
    | Edit this page View Source

    HasOutputImage

    Gets whether the agent supports image generation output.

    Declaration
    public bool HasOutputImage { get; }
    Property Value
    Type Description
    bool
    | Edit this page View Source

    Id

    Gets the unique identifier for this agent.

    Declaration
    public string Id { get; }
    Property Value
    Type Description
    string
    | Edit this page View Source

    ImageModel

    Gets or sets the image generation model used for creating images.

    Declaration
    public Model ImageModel { get; set; }
    Property Value
    Type Description
    Model
    | Edit this page View Source

    InputAudioLanguage

    Gets or sets the language locale for input audio transcription.

    Declaration
    public Locale InputAudioLanguage { get; set; }
    Property Value
    Type Description
    Locale
    | Edit this page View Source

    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
    | Edit this page View Source

    IsDisposed

    Gets whether the agent has been disposed and is no longer usable.

    Declaration
    public bool IsDisposed { get; }
    Property Value
    Type Description
    bool
    | Edit this page View Source

    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
    | Edit this page View Source

    Items

    Gets all conversation items (messages and tool outputs).

    Declaration
    public List<ConversationItem> Items { get; }
    Property Value
    Type Description
    List<ConversationItem>
    | Edit this page View Source

    LastMessage

    Gets the most recent message in the conversation.

    Declaration
    public Message LastMessage { get; }
    Property Value
    Type Description
    Message
    | Edit this page View Source

    LogLevel

    Gets the logging level for agent operations (Off, Error, Warning, Info, Verbose).

    Declaration
    public TraceLevel LogLevel { get; }
    Property Value
    Type Description
    TraceLevel
    | Edit this page View Source

    MaxTokens

    Gets the maximum number of tokens the agent can generate.

    Declaration
    public int? MaxTokens { get; }
    Property Value
    Type Description
    int?
    | Edit this page View Source

    Messages

    Gets all messages in the conversation.

    Declaration
    public List<Message> Messages { get; }
    Property Value
    Type Description
    List<Message>
    | Edit this page View Source

    Model

    Gets or sets the language model used for text generation.

    Declaration
    public Model Model { get; set; }
    Property Value
    Type Description
    Model
    | Edit this page View Source

    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
    | Edit this page View Source

    Settings

    Gets the agent's configuration settings (models, tools, instructions, etc.).

    Declaration
    public IAgentSettings Settings { get; }
    Property Value
    Type Description
    IAgentSettings
    | Edit this page View Source

    SpeechModel

    Gets or sets the speech generation model used for text-to-speech.

    Declaration
    public Model SpeechModel { get; set; }
    Property Value
    Type Description
    Model
    | Edit this page View Source

    Status

    Gets the current lifecycle status of the agent (None, Initializing, Ready, GeneratingResponse, etc.).

    Declaration
    public AgentStatus Status { get; }
    Property Value
    Type Description
    AgentStatus
    | Edit this page View Source

    Stream

    Gets whether streaming is enabled for responses.

    Declaration
    public bool Stream { get; }
    Property Value
    Type Description
    bool
    | Edit this page View Source

    Temperature

    Gets the temperature setting for response generation (0.0 = deterministic, higher = more creative).

    Declaration
    public float? Temperature { get; }
    Property Value
    Type Description
    float?
    | Edit this page View Source

    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
    | Edit this page View Source

    Tools

    Gets or sets the list of tools available to the agent.

    Declaration
    public List<Tool> Tools { get; }
    Property Value
    Type Description
    List<Tool>
    | Edit this page View Source

    TranscriptionModel

    Gets or sets the transcription model used for speech-to-text.

    Declaration
    public Model TranscriptionModel { get; set; }
    Property Value
    Type Description
    Model
    | Edit this page View Source

    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
    | Edit this page View Source

    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 Source

    CancelRequest()

    Cancels all ongoing requests including chat, image generation, speech, transcription, and MCP operations.

    Declaration
    public void CancelRequest()
    | Edit this page View Source

    Dispose()

    Disposes the agent and releases all resources including active requests and services.

    Declaration
    public void Dispose()
    | Edit this page View Source

    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.

    | Edit this page View Source

    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

    | Edit this page View Source

    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
    | Edit this page View Source

    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

    | Edit this page View Source

    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

    | Edit this page View Source

    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

    | Edit this page View Source

    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

    | Edit this page View Source

    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

    | Edit this page View Source

    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

    | Edit this page View Source

    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

    | Edit this page View Source

    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

    | Edit this page View Source

    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

    | Edit this page View Source

    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

    | Edit this page View Source

    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 null to disable.

    | Edit this page View Source

    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 null to disable.

    | Edit this page View Source

    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.

    | Edit this page View Source

    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.

    | Edit this page View Source

    SubmitMcpApprovalRequest(McpApprovalRequest)

    Declaration
    public void SubmitMcpApprovalRequest(McpApprovalRequest approvalRequest)
    Parameters
    Type Name Description
    McpApprovalRequest approvalRequest
    | Edit this page View Source

    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

    | Edit this page View Source

    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

    | Edit this page View Source

    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
    | Edit this page View Source

    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

    | Edit this page View Source

    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

    | Edit this page View Source

    UnregisterTool(Tool)

    Unregisters a single tool.

    Declaration
    public void UnregisterTool(Tool tool)
    Parameters
    Type Name Description
    Tool tool

    The tool to unregister

    | Edit this page View Source

    UnregisterToolDefinition(HostedToolDefinitionBase)

    Unregisters a tool definition.

    Declaration
    public void UnregisterToolDefinition(HostedToolDefinitionBase toolDef)
    Parameters
    Type Name Description
    HostedToolDefinitionBase toolDef

    The tool definition to unregister

    | Edit this page View Source

    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

    | Edit this page View Source

    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

    | Edit this page View Source

    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

    Implements

    IDisposable

    Extension Methods

    ArrayExtensions.ToArrayOrEmpty<T>(T)
    ArrayExtensions.ToArrayOrNull<T>(T)
    EventExtensions.ToDelta<T>(T, string, int, string, bool)
    EventExtensions.ToDone<T>(T, string, int, string)
    EventExtensions.ToEvent<T>(T)
    EventExtensions.UpcastDelta<T1, T2>(T1, string, int, string, bool)
    FallbackExtensions.IsOr<TParent, TChild>(TParent, TChild)
    ResponseCastingExtensions.GetResult<T>(T)
    SystemExtensions.TryDispose(IDisposable)
    SystemExtensions.GetName(object)
    • Edit this page
    • View Source
    In this article
    Back to top AI DevKit Documentation