Skip to main content
A hosted agent is a container that fulfills a specific runtime contract with the Microsoft Foundry platform. This reference describes what the platform expects from your container and how the SDK adapter packages help you meet those requirements. The SDK adapter packages implement the entire contract for you. If you use azure-ai-agentserver-responses or azure-ai-agentserver-invocations, you implement only your handler logic.

Contract requirements

Your container must:

Protocol endpoints

A protocol defines the HTTP contract between Foundry and your agent container. Your container implements at least one protocol endpoint.

Responses protocol

The responses protocol implements the OpenAI Responses API. The platform sends requests to POST /responses and expects either a JSON response or a Server-Sent Events (SSE) stream. Use the responses protocol as the standard choice. It’s compatible with the OpenAI API ecosystem.

Invocations protocol

The invocations protocol is a minimal pass-through protocol. You define the payload structure, and the platform passes it through without interpretation. Use the invocations protocol when you need full control over the request and response payloads.

SDK adapter packages

The adapter packages are protocol-specific and framework-agnostic. They work with any agent framework, including Microsoft Agent Framework, LangGraph, and custom code. The adapter handles the following parts of the contract for you:
  • HTTP server setup on port 8088.
  • The health probe endpoint (GET /readiness).
  • Protocol-specific request parsing and response formatting.
  • Conversation history hydration (responses protocol).
  • SSE streaming infrastructure.
  • OpenTelemetry instrumentation.
  • Graceful shutdown on SIGTERM.
  • Platform environment variable consumption.
You implement a handler function that receives parsed requests and returns responses.

Handler examples

The complete bring-your-own samples for both protocols and both languages are in the foundry-samples repository.

Responses protocol example

This minimal handler forwards user input to a model from the Foundry model catalog through the Responses API. The SDK adapter hydrates conversation history automatically through context.get_history() (Python) or context.GetHistoryAsync() (C#), so the agent maintains context across turns.
From bring-your-own/responses/hello-world/main.py:
Reference: ResponsesAgentServerHost, AIProjectClient, DefaultAzureCredential

Invocations protocol example

With the invocations protocol, your handler receives whatever JSON the caller posts and returns whatever JSON your code chooses. There’s no built-in conversation history.
Pattern from bring-your-own/invocations/hello-world:
The full samples also include conversation-history hydration, error handling, telemetry, toolbox integration, and Dockerfile and azure.yaml setup.

Health probe

The platform sends GET /readiness to determine whether your container is ready to serve traffic. Return 200 OK when the container is ready, or a non-200 status to signal that the platform should restart the instance. The SDK adapters register this endpoint automatically.

Network and transport

Graceful shutdown

When the platform sends SIGTERM, your container stops accepting new requests, finishes in-flight requests, flushes pending writes to $HOME (the session filesystem), and exits cleanly. The SDK adapters handle this sequence automatically.

Platform environment variables

The platform injects environment variables into your container at startup. Your code can read the following key variables:

Platform request headers (container protocol 2.0.0)

These headers apply only to hosted agents on container protocol version 2.0.0. On protocol 2.0.0, the platform injects them on every request to your protocol endpoints, for both the Responses and Invocations protocols. They aren’t sent to infrastructure endpoints such as the health probe. Treat their values as opaque, and read but don’t override them. Both headers are trustworthy - the platform generates them from verified identity - and neither is guaranteed when you run locally, so handle missing values gracefully. The AgentServer SDK exposes these as constants on PlatformHeaders and reads them for you - through FoundryAgentRequestContext.Current in .NET or get_request_context() in Python. For the complete platform header list, including response headers the runtime adds such as x-agent-session-id, x-platform-server, and x-platform-error-source, see the Azure AI Agent Server Core library reference. For how protocol 2.0.0 changes identity propagation, see Migrate hosted agents.

Example: partition stored data per session

When your container persists user-owned data, key it by the session (and, for shared sessions, the user) so one caller can’t read another’s data. The note-taking agent sample does this by deriving a per-session file path under $HOME, where files are also reachable through the Session Files API:
When more than one user can share a session, add x-agent-user-id to the key. See Multiplex multiple users in one hosted agent session.

Forward custom request headers to your container

The previous section covers headers the platform injects. Separately, the gateway forwards only a fixed set of caller-supplied request headers to your container. Any caller header outside that set is dropped at the gateway before the request reaches your container, which keeps credentials and internal headers out of your container by default. To pass your own contextual data to your container, use the pass-through client header prefix, x-client-. The platform forwards every header that starts with x-client- unchanged, so you can send values like a tenant ID or a feature flag without changing the request body, then read them in your handler like any other request header. The AgentServer SDK defines this prefix as PlatformHeaders.ClientHeaderPrefix; for the full platform header list, see the Azure AI Agent Server Core library reference. The gateway forwards these caller headers to the Responses and Invocations protocol endpoints: The gateway never forwards credential headers such as Authorization, or Host, Cookie, and x-forwarded-*. Any header that doesn’t match the allowlist is dropped, so don’t rely on custom headers outside the x-client-* prefix reaching your container.