InvocationWebSocketHandler Class

Definition

Base class for handlers that opt in to the invocations_ws (WebSocket) transport at /invocations_ws, optionally alongside the HTTP POST /invocations transport.

public abstract class InvocationWebSocketHandler : Azure.AI.AgentServer.Invocations.InvocationHandler
type InvocationWebSocketHandler = class
    inherit InvocationHandler
Public MustInherit Class InvocationWebSocketHandler
Inherits InvocationHandler
Inheritance
InvocationWebSocketHandler

Remarks

Override HandleWebSocketAsync(WebSocket, InvocationContext, CancellationToken) to serve a WebSocket connection. The library calls AcceptWebSocketAsync for you, maps a clean handler return to RFC 6455 close code 1000 (NormalClosure) and an uncaught handler exception to 1011 (InternalServerError), preserves handler-initiated close codes unchanged, and emits a structured close-event log line carrying azure.ai.agentserver.invocations_ws.session_id, azure.ai.agentserver.invocations_ws.close_code, and azure.ai.agentserver.invocations_ws.duration_ms.

The inherited HandleAsync(HttpRequest, HttpResponse, InvocationContext, CancellationToken) (HTTP POST /invocations) returns 404 Not Found by default — a WS-only handler does not need to override it. Multi-protocol handlers override both HandleAsync(HttpRequest, HttpResponse, InvocationContext, CancellationToken) and HandleWebSocketAsync(WebSocket, InvocationContext, CancellationToken); both methods see the same session when FOUNDRY_AGENT_SESSION_ID is set so HTTP and WebSocket turns correlate.

No framework-level OpenTelemetry span is created for the connection; ASP.NET Core auto-propagates the inbound W3C trace context to the request Activity, so any spans the handler starts are parented correctly. Session / invocation / x-request-id baggage is propagated onto the current Activity before the handler runs.

Constructors

Name Description
InvocationWebSocketHandler()

Methods

Name Description
CancelAsync(String, HttpRequest, HttpResponse, InvocationContext, CancellationToken)

Handles POST /invocations/{invocationId}/cancel. Returns 404 by default. Override to support cancellation.

(Inherited from InvocationHandler)
GetAsync(String, HttpRequest, HttpResponse, InvocationContext, CancellationToken)

Handles GET /invocations/{invocationId}. Returns 404 by default. Override to support polling for async/LRO invocations.

(Inherited from InvocationHandler)
GetOpenApiAsync(HttpRequest, HttpResponse, CancellationToken)

Handles GET /invocations/docs/openapi.json. Returns 404 by default. Override to return an OpenAPI spec for the agent's contract.

(Inherited from InvocationHandler)
HandleAsync(HttpRequest, HttpResponse, InvocationContext, CancellationToken)

Handles a POST /invocations request. Returns 404 Not Found by default — override to add HTTP support alongside the WebSocket endpoint.

HandleWebSocketAsync(WebSocket, InvocationContext, CancellationToken)

Handles a /invocations_ws WebSocket connection. Required.

Applies to