InvocationWebSocketHandler.HandleWebSocketAsync Method

Definition

Handles a /invocations_ws WebSocket connection. Required.

public abstract System.Threading.Tasks.Task HandleWebSocketAsync(System.Net.WebSockets.WebSocket webSocket, Azure.AI.AgentServer.Invocations.InvocationContext context, System.Threading.CancellationToken cancellationToken);
abstract member HandleWebSocketAsync : System.Net.WebSockets.WebSocket * Azure.AI.AgentServer.Invocations.InvocationContext * System.Threading.CancellationToken -> System.Threading.Tasks.Task
Public MustOverride Function HandleWebSocketAsync (webSocket As WebSocket, context As InvocationContext, cancellationToken As CancellationToken) As Task

Parameters

webSocket
WebSocket

The accepted WebSocket. The SDK has already called AcceptWebSocketAsync; the handler owns the full-duplex lifecycle from this point. On clean return the SDK closes the connection with RFC 6455 code 1000 (NormalClosure); an unhandled exception is mapped to code 1011 (InternalServerError); a handler-initiated CloseAsync is preserved unchanged.

context
InvocationContext

Per-connection context. The session ID honours FOUNDRY_AGENT_SESSION_ID (matching the HTTP POST /invocations precedence, minus the query-param override which has no ergonomic equivalent on a long-lived WS connection). The invocation ID is a generated UUID — WebSocket has no per-message invocation ID.

cancellationToken
CancellationToken

Cancelled when the connection is aborted (client disconnect, server shutdown, request aborted, etc.).

Returns

A task representing the async lifetime of the connection.

Applies to