FoundryAgentRequestContext Class

Definition

Request-scoped platform identity context, backed by an AsyncLocal<T> so it flows across await points and child tasks within a single request without being threaded through every call site. This is the .NET analogue of the Python SDK's get_request_context() / FoundryAgentRequestContext.

public sealed class FoundryAgentRequestContext
type FoundryAgentRequestContext = class
Public NotInheritable Class FoundryAgentRequestContext
Inheritance
FoundryAgentRequestContext

Remarks

On container protocol version 2.0.0 the platform stamps x-agent-foundry-call-id and x-agent-user-id on the inbound request. The SDK's request-context middleware captures them here before the handler runs; outbound Foundry-bound clients read Current and echo only the call id (e.g. via FoundryCallIdHandler).

x-agent-user-id is exposed purely as a convenience for the container's own per-user state isolation — it is never echoed on outbound calls (the receiver resolves user identity from the call id).

Current never returns null; outside a request (e.g. local development) it yields an empty context with all-null fields.

Constructors

Name Description
FoundryAgentRequestContext()

Properties

Name Description
CallId

The opaque per-request call identifier from x-agent-foundry-call-id (container protocol version 2.0.0). Echoed verbatim on outbound Foundry-bound calls; null when absent.

Current

Gets the platform identity context for the current request. Never returns null — an empty context is returned outside a request.

Empty

An empty context with all fields null, returned by Current when no request context has been established.

SessionId

The session ID sourced from the FOUNDRY_AGENT_SESSION_ID environment variable at process start (via SessionId). This is a process-level value that does not reflect per-request overrides (e.g. the agent_session_id query parameter); null when the variable is absent.

UserId

The global, cross-agent per-user identity from x-agent-user-id. A convenience for the container's own per-user state isolation; it is never echoed on outbound calls. null when absent.

Methods

Name Description
PlatformHeaders()

Builds the platform identity headers to echo on outbound Foundry-bound calls. Only x-agent-foundry-call-id is included; x-agent-user-id is never echoed. Mirrors the Python SDK's FoundryAgentRequestContext.platform_headers().

Applies to