FoundryAgentRequestContext Class
Platform-supplied, request-scoped identity context.
Populated by the protocol endpoint from inbound platform headers on every
request. All fields are None when the corresponding header was absent
(e.g. local development, or call_id under protocol version 1.0.0).
Constructor
FoundryAgentRequestContext(*, call_id: str | None = None, user_id: str | None = None, session_id: str | None = None, original_subject: FoundryOriginalSubject | None = None)
Keyword-Only Parameters
| Name | Description |
|---|---|
|
call_id
|
Default value: None
|
|
user_id
|
Default value: None
|
|
session_id
|
Default value: None
|
|
original_subject
|
Default value: None
|
Variables
| Name | Description |
|---|---|
|
call_id
|
Opaque per-request call identifier from |
|
user_id
|
Global, cross-agent per-user identity from |
|
session_id
|
The resolved session ID for the request, when available. |
|
original_subject
|
Optional invocation-local attribution assertions. |
Methods
| model_attribution_headers |
Note This is an experimental method, and may change at any time. Build draft headers for an explicitly supported model integration. Pass the result as per-call headers, never shared client defaults. Only use this for a model endpoint whose owner has enabled this contract. Do not send these assertions to external/BYO endpoints, storage, tools, or arbitrary URLs. No client is patched automatically. Existing headers and unrelated baggage are copied, not mutated. Reserved subject assertions are replaced case-insensitively, or removed when the invocation has no subject. The full quoted dictionary is emitted only in one baggage member, percent-encoded once. Standalone subject headers are inbound platform metadata and are not forwarded to the model. Partial, empty, HTTP-unsafe, or oversized tuples raise instead of silently becoming an unattributed model call. The quoted tuple is limited to 256 characters and merged baggage to 1024 when a subject is supplied. Values, including non-user/unknown classifications, are not normalized here. Durable restore and detached work have no attribution support in this draft. |
| platform_headers |
Build the platform identity headers to forward on outbound 1P calls. Only |
model_attribution_headers
Note
This is an experimental method, and may change at any time.
Build draft headers for an explicitly supported model integration.
Pass the result as per-call headers, never shared client defaults. Only use this for a model endpoint whose owner has enabled this contract. Do not send these assertions to external/BYO endpoints, storage, tools, or arbitrary URLs. No client is patched automatically.
Existing headers and unrelated baggage are copied, not mutated. Reserved subject assertions are replaced case-insensitively, or removed when the invocation has no subject. The full quoted dictionary is emitted only in one baggage member, percent-encoded once. Standalone subject headers are inbound platform metadata and are not forwarded to the model.
Partial, empty, HTTP-unsafe, or oversized tuples raise instead of silently becoming an unattributed model call. The quoted tuple is limited to 256 characters and merged baggage to 1024 when a subject is supplied. Values, including non-user/unknown classifications, are not normalized here. Durable restore and detached work have no attribution support in this draft.
model_attribution_headers(headers: Mapping[str, str] | None = None) -> dict[str, str]
Parameters
| Name | Description |
|---|---|
|
headers
|
Optional existing per-call headers, including Foundry baggage. Default value: None
|
Returns
| Type | Description |
|---|---|
|
A fresh per-call header mapping; model credentials are unchanged. |
Exceptions
| Type | Description |
|---|---|
|
The supplied tuple is incomplete, HTTP-unsafe, or exceeds the subject or merged baggage transport limit. |
platform_headers
Build the platform identity headers to forward on outbound 1P calls.
Only x-agent-foundry-call-id is forwarded: 1P services resolve the
caller context server-side from the opaque call ID. x-agent-user-id
is not forwarded — it is not accepted/trusted by 1P services and is
only consumed container-side for per-user state partitioning. The call ID
is included only when present (non-None). The managed-identity
Authorization header is unaffected — this is an additional header
for caller-identity context.
platform_headers() -> dict[str, str]
Returns
| Type | Description |
|---|---|
|
A mapping of header name to value, suitable for merging into an outbound request's headers. |