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çade.
  • Uses internal services for conversations, tool calls, and audio I/O.
  • Acts as the main entry point for runtime chat / tool workflows.
public sealed class Agent : IResponsesApiListener, IRealtimeApiListener, IChatApiListenerBase, IListener, IToolContext, IConversationContext, IAudioContext, IErrorHandler
Inheritance
object
Agent
Implements

Remarks

Warning: Do not attempt to change ConversationManager once Agent is created.

Constructors

Agent(AgentSettings, IAgentBehaviour, List<Tool>, List<ToolDefinitionBase>, AgentHooks, AgentServices, McpAccessTokenService, IUniTaskStore<AgentPrefs>, ILogger)

public Agent(AgentSettings settings, IAgentBehaviour behaviour, List<Tool> initialTools = null, List<ToolDefinitionBase> toolDefinitions = null, AgentHooks hooks = null, AgentServices services = null, McpAccessTokenService tokenService = null, IUniTaskStore<AgentPrefs> prefsStore = null, ILogger logger = null)

Parameters

settings AgentSettings
behaviour IAgentBehaviour
initialTools List<Tool>
toolDefinitions List<ToolDefinitionBase>
hooks AgentHooks
services AgentServices
tokenService McpAccessTokenService
prefsStore IUniTaskStore<AgentPrefs>
logger ILogger

Fields

audioController

public readonly AudioController audioController

Field Value

AudioController

conversationController

public readonly ConversationController conversationController

Field Value

ConversationController

imageController

public readonly ImageController imageController

Field Value

ImageController

mcpController

public readonly McpController mcpController

Field Value

McpController

toolCallController

public readonly ToolCallController toolCallController

Field Value

ToolCallController

Properties

ChatServiceApi

public ChatService ChatServiceApi { get; }

Property Value

ChatService

Conversation

public Conversation Conversation { get; }

Property Value

Conversation

ConversationId

public string ConversationId { get; set; }

Property Value

string

ConversationStoreType

public ConversationStoreType ConversationStoreType { get; }

Property Value

ConversationStoreType

CurrentResponse

Current response being generated by the agent.

public Response CurrentResponse { get; }

Property Value

Response

HasInputAudio

public bool HasInputAudio { get; }

Property Value

bool

HasMcpTool

public bool HasMcpTool { get; set; }

Property Value

bool

HasOutputAudio

public bool HasOutputAudio { get; }

Property Value

bool

HasOutputImage

public bool HasOutputImage { get; }

Property Value

bool

Id

public string Id { get; }

Property Value

string

ImageModel

public Model ImageModel { get; set; }

Property Value

Model

InputAudioLanguage

public SystemLanguage InputAudioLanguage { get; set; }

Property Value

SystemLanguage

Instructions

public string Instructions { get; }

Property Value

string

IsInitialized

True when agent and (if used) the conversation controller are fully initialized.

public bool IsInitialized { get; }

Property Value

bool

Items

public List<ConversationItem> Items { get; }

Property Value

List<ConversationItem>

LastMessage

public Message LastMessage { get; }

Property Value

Message

LogLevel

public TraceLevel LogLevel { get; }

Property Value

TraceLevel

MaxTokens

public int? MaxTokens { get; }

Property Value

int?

Messages

public List<Message> Messages { get; }

Property Value

List<Message>

Model

public Model Model { get; set; }

Property Value

Model

Name

public string Name { get; set; }

Property Value

string

OutputAudioVolume

public float OutputAudioVolume { get; set; }

Property Value

float

Settings

public AgentSettings Settings { get; }

Property Value

AgentSettings

SpeechModel

public Model SpeechModel { get; set; }

Property Value

Model

Status

Current lifecycle state.

public AgentStatus Status { get; }

Property Value

AgentStatus

Stream

public bool Stream { get; }

Property Value

bool

SubmitToolOutputTimeoutSeconds

Timeout in seconds for MCP approval requests.

public int SubmitToolOutputTimeoutSeconds { get; }

Property Value

int

Temperature

public float? Temperature { get; }

Property Value

float?

ToolChoice

public ToolChoice ToolChoice { get; set; }

Property Value

ToolChoice

Tools

public List<Tool> Tools { get; }

Property Value

List<Tool>

TranscriptionModel

public Model TranscriptionModel { get; set; }

Property Value

Model

UnhandledToolCallBehaviour

Policy for handling unhandled tool calls.

public UnhandledToolCallBehaviour UnhandledToolCallBehaviour { get; }

Property Value

UnhandledToolCallBehaviour

Voice

public Voice Voice { get; set; }

Property Value

Voice

WaitForToolCallsCompletion

Timeout for submitting tool output when using the SubmitToolOutput policy. Only applicable if UnhandledToolCallBehaviour is set to SubmitToolOutput. This will be ignored if it's less than or equal to zero.

public bool WaitForToolCallsCompletion { get; }

Property Value

bool

Methods

CancelRequest()

public void CancelRequest()

CommitParametersUpdateAsync(CancellationToken)

public UniTask CommitParametersUpdateAsync(CancellationToken ct = default)

Parameters

ct CancellationToken

Returns

UniTask

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

GenerateResponseAsync(ConversationItem, int, CancellationToken)

public UniTask<Response> GenerateResponseAsync(ConversationItem inputItem, int index = -1, CancellationToken ct = default)

Parameters

inputItem ConversationItem
index int
ct CancellationToken

Returns

UniTask<Response>

GenerateResponseAsync(Message, int, CancellationToken)

public UniTask<Response> GenerateResponseAsync(Message message, int index = -1, CancellationToken ct = default)

Parameters

message Message
index int
ct CancellationToken

Returns

UniTask<Response>

GenerateResponseAsync(string, int, CancellationToken)

public UniTask<Response> GenerateResponseAsync(string text, int index = -1, CancellationToken ct = default)

Parameters

text string
index int
ct CancellationToken

Returns

UniTask<Response>

HandleError(Exception)

public void HandleError(Exception error)

Parameters

error Exception

HandleUsage(UsageMetadata)

public void HandleUsage(UsageMetadata usage)

Parameters

usage UsageMetadata

InitializeAsync()

public UniTask InitializeAsync()

Returns

UniTask

OnAudioDelta(AudioDelta)

public void OnAudioDelta(AudioDelta delta)

Parameters

delta AudioDelta

OnInputAudioBuffer(InputAudioBufferEvent)

public void OnInputAudioBuffer(InputAudioBufferEvent evt)

Parameters

evt InputAudioBufferEvent

OnMcpApprovalRequested(McpApprovalRequestEvent)

public void OnMcpApprovalRequested(McpApprovalRequestEvent e)

Parameters

e McpApprovalRequestEvent

OnRateLimitsUpdated(RealtimeRateLimit[])

public void OnRateLimitsUpdated(RealtimeRateLimit[] rateLimits)

Parameters

rateLimits RealtimeRateLimit[]

OnRealtimeSession(RealtimeSessionStatusEvent)

public void OnRealtimeSession(RealtimeSessionStatusEvent evt)

Parameters

evt RealtimeSessionStatusEvent

OnResponse(ResponseStatus, Response)

public void OnResponse(ResponseStatus status, Response response)

Parameters

status ResponseStatus
response Response

OnTextDelta(TextDelta)

public void OnTextDelta(TextDelta e)

Parameters

e TextDelta

OnTextSpans(TextSpansEvent)

public void OnTextSpans(TextSpansEvent e)

Parameters

e TextSpansEvent

OnToolCall(ToolCallEvent)

public void OnToolCall(ToolCallEvent e)

Parameters

e ToolCallEvent

OnToolCallDelta(ToolCallArgs)

public void OnToolCallDelta(ToolCallArgs e)

Parameters

e ToolCallArgs

OnToolOutput(ToolOutputEvent)

public void OnToolOutput(ToolOutputEvent e)

Parameters

e ToolOutputEvent

OnToolStatus(ToolStatusEvent)

public void OnToolStatus(ToolStatusEvent e)

Parameters

e ToolStatusEvent

SubmitToolOutputAsync(ToolOutput, CancellationToken)

Submit tool output to the agent to continue the conversation.

public UniTask<Response> SubmitToolOutputAsync(ToolOutput toolOutput, CancellationToken ct = default)

Parameters

toolOutput ToolOutput
ct CancellationToken

Returns

UniTask<Response>

Events

onUnhandledToolCall

Event raised when a tool call cannot be handled internally.

  • Allows external code to intercept and handle unbound tool calls.
  • Only fired when UnhandledToolCallBehaviour is configured accordingly.
public event Action<ToolCall> onUnhandledToolCall

Event Type

Action<ToolCall>