Host a compiled LangGraph graph inside Azure AI Foundry's Agent Service.
Agent Service can host agents created in LangChain/LangGraph and serve them with the same platform guarantees Foundry provides.
You can serve and hook your agent using either the OpenAI Responses API or the Invocations API. When using the Responses API, Microsoft Foundry handles state automatically and securely stores it within the service. The Invocations API is a more generic approach that lets you use input and output schemas of your choice.
Responses hosts require the hosting extra::
pip install langchain-azure-ai[hosting]
To run your agent in Foundry, use either InvocationsHostServer or
ResponsesHostServer depending on the API you want to use.
Quick start (Responses API)::
import os
from langchain.agents import create_agent
from langchain_openai import ChatOpenAI
from langchain_azure_ai.agents.hosting import ResponsesHostServer
model = ChatOpenAI(
model=os.environ.get("AZURE_AI_MODEL_DEPLOYMENT_NAME", "gpt-4o"),
)
graph = create_agent(model, tools=[])
if __name__ == "__main__":
ResponsesHostServer(graph).run(port=int(os.environ.get("PORT", "8088")))
Quick start (Invocations API with session continuity)::
import os
from langchain.agents import create_agent
from langchain_openai import ChatOpenAI
from langgraph.checkpoint.memory import MemorySaver
from langchain_azure_ai.agents.hosting import (
InvocationsHostServer,
ResponsesServerOptions,
)
model = ChatOpenAI(
model=os.environ.get("AZURE_AI_MODEL_DEPLOYMENT_NAME", "gpt-4o"),
)
graph = create_agent(model, tools=[], checkpointer=MemorySaver())
if __name__ == "__main__":
InvocationsHostServer(
graph,
options=ResponsesServerOptions(
resilient_background=True,
steerable_conversations=True,
),
).run(port=int(os.environ.get("PORT", "8088")))
Then call the local host from another process::
curl -N -X POST http://127.0.0.1:8088/responses -H 'Content-Type: application/json' -d '{"input":"Hello!","stream":true}'
curl -i -X POST http://127.0.0.1:8088/invocations -H 'Content-Type: application/json' -d '{"message":"My name is Alice."}'
curl -X POST 'http://127.0.0.1:8088/invocations?agent_session_id=<id>' -H 'Content-Type: application/json' -d '{"message":"What is my name?"}'
See the samples/hosting/langgraph-hosted-agents directory for complete
Foundry-backed examples, Dockerfiles, and deployment manifests.
For multi-protocol or custom-route scenarios, pass a compatible
ResponsesAgentServerHost or InvocationAgentServerHost object as
app and write your own @response_handler / @invoke_handler.
These host and option types are re-exported from this package so
applications do not need to import Azure SDK modules directly.