Prerequisites
- An Azure subscription. Create one for free.
- A Foundry project.
- A deployed chat model, such as
gpt-4.1orgpt-4o. - The Foundry Project Manager role on the project to deploy a hosted agent. For details, see Deploy a hosted agent.
- Azure CLI signed in (
az login) soDefaultAzureCredentialcan authenticate.
Install the packages
Choose a hosting protocol
Hosted agents can expose one or more protocols. Start with Responses for most conversational agents.
For background on protocol behavior and sessions, see Hosted agents and Manage hosted agent sessions.
Configure environment variables
Set the project endpoint and model deployment name for local development:FOUNDRY_PROJECT_ENDPOINT and AZURE_AI_MODEL_DEPLOYMENT_NAME at runtime.
Responses protocol
Use the Responses protocol when you want an OpenAI-compatible chat endpoint with streaming, response history, and conversation threading.Create a Responses host
Test the Responses endpoint
Send a non-streaming Responses request to the local server. Bash:stream to true. The host emits
Responses API server-sent events, such as response.created,
response.output_text.delta, and response.completed.
Multi-turn conversations
To continue a conversation, pass the previous response ID in theprevious_response_id field of the next request:
agent_session_id or use a conversation ID. For details, see
Manage hosted agent sessions.
Invocations protocol
Use the Invocations protocol when your callers can’t use the Responses API request shape or when your scenario isn’t a chat conversation. The Invocations host manages session state through anagent_session_id query parameter and
response header.
Create an Invocations host
Test the Invocations endpoint
Send a request to the local server:agent_session_id value from the
response header as the agent_session_id query parameter on the next request:
agent_session_id query parameter to route later calls to the same
hosted sandbox.
Deploy
Deploy by using the Azure Developer CLI (azd). The flow uses sample manifests
and Docker to build the agent container image and roll it out to the Foundry
hosted agent runtime.
Hosted agent deployment requires the Foundry Project Manager role on the
project. For details, see Deploy a hosted agent.
Install the Azure Developer CLI extension
Install the AI agent extension and sign in before you initialize a sample:azd ai agent run builds the container
image declared in the sample’s Dockerfile. For command details, see the
Azure Developer CLI reference.
Initialize from a sample manifest
Create a new folder and initialize it from a sample manifest. Replace the manifest URL with the sample you want to use. Follow the prompts fromazd ai agent init. If you don’t already have a Foundry
project and model deployment, the initialization flow can guide you through
creating them.
Provision Azure resources
If the initialized project uses a new Foundry project and model deployment, provision the Azure resources first:Run the container locally
Run the agent host locally throughazd:
http://localhost:8088. In another terminal, invoke the
local protocol endpoint:
curl:
Deploy to Foundry
Deploy the agent:FOUNDRY_PROJECT_ENDPOINT: The endpoint URL for the Foundry project where the agent is deployed.AZURE_AI_MODEL_DEPLOYMENT_NAME: The model deployment name selected duringazd ai agent init.APPLICATIONINSIGHTS_CONNECTION_STRING: The connection string for the project’s Application Insights instance.
Troubleshooting
Use this checklist to diagnose common issues while developing hosted agents with Agent Framework.The model can’t be reached in the hosted container
Confirm that the hosted agent version includesAZURE_AI_MODEL_DEPLOYMENT_NAME,
and that the agent identity has permission to call the Foundry project. The
platform sets FOUNDRY_PROJECT_ENDPOINT; your code should read that variable
when running in Foundry.
Conversation state doesn’t continue
For the Responses protocol, passprevious_response_id or a conversation ID
on later turns.
For the Invocations protocol, the platform doesn’t store conversation history.
Use an agent_session_id query parameter to route later calls to the same
hosted sandbox.