This repository contains the following packages with Azure integrations with LangChain:
- langchain-azure-ai
- langchain-azure-compute
- langchain-azure-cosmosdb
- langchain-azure-dynamic-sessions
- langchain-sqlserver
- langchain-azure-postgresql
- langchain-azure-storage
Note: This repository will replace all Azure integrations currently present in the langchain-community package. Users are encouraged to migrate to this repository as soon as possible.
Build with Azure models using the LangChain and LangGraph development guide, or bring an existing compiled graph to Microsoft Foundry with the LangGraph hosting guide.
The hosted-agent samples cover local runs and deployment, including hosting an existing graph without changing its implementation.
For durable graph state, use FoundryCheckpointSaver backed by Foundry State Store in Foundry-hosted agents, or the Azure Cosmos DB checkpointer. Cosmos DB also provides a long-term memory store.
For durable execution of compiled LangGraph workflows and LangChain agents (per-step and per-tool fault isolation, automatic worker failover, and durable interrupt() / resume() waits), use langchain_azure_compute.graph backed by the Azure Durable Task Scheduler and explore the 10 runnable Durable Task LangGraph samples.
- SDK samples demonstrate SDK usage, including hosting, memory, and storage integrations.
- SDK notebooks cover Foundry models, Agent Service, Content Safety, and Content Understanding.
- Foundry deployment samples demonstrate platform configuration and deployment with LangGraph.
The langchain-azure-ai package uses the Microsoft Foundry family of SDKs and client libraries for Azure to provide first-class support of Microsoft Foundry capabilities in LangChain and LangGraph.
This package includes:
- Microsoft Agent Service
- Microsoft Foundry Models inference
- Microsoft Foundry Content Safety
- Microsoft Foundry Tools
- Azure AI Search
- Azure AI Services tools
Here's a quick start example to show you how to get started with a chat model. For more details and tutorials see Develop with LangChain and LangGraph and models from Azure AI Foundry.
pip install -U langchain-azure-aiUse any Foundry Model with OpenAI-compatible APIs:
We recommend the Responses API when your model and endpoint support it. Set use_responses_api=True as shown below. If you prefer Chat Completions and your model and endpoint support it, set use_responses_api=False instead.
from azure.identity import DefaultAzureCredential
from langchain_azure_ai.chat_models import AzureAIOpenAIApiChatModel
from langchain_core.messages import HumanMessage, SystemMessage
model = AzureAIOpenAIApiChatModel(
project_endpoint="https://{your-resource-name}.services.ai.azure.com/api/projects/{your-project}",
credential=DefaultAzureCredential(), # requires Azure AI Developer role. If using keys, use parameter `endpoint` instead of `project_endpoint`.
model="gpt-5", # your model deployment name
use_responses_api=True,
)
messages = [
SystemMessage(
content="Translate the following from English into Italian"
),
HumanMessage(content="hi!"),
]
model.invoke(messages).pretty_print()================================== Ai Message ==================================
Ciao!
Use the azure_ai provider with init_chat_model. Choose one of the
following authentication options.
Option A: Project endpoint with Microsoft Entra ID
Set AZURE_AI_PROJECT_ENDPOINT and sign in with az login for local
development:
import os
from langchain.chat_models import init_chat_model
os.environ["AZURE_AI_PROJECT_ENDPOINT"] = "https://{your-resource-name}.services.ai.azure.com/api/projects/<project>"
model = init_chat_model("azure_ai:gpt-5-mini")
model.invoke("Hello!").pretty_print()Option B: OpenAI-compatible endpoint with an API key
Set OPENAI_API_BASE and OPENAI_API_KEY. Leave AZURE_AI_PROJECT_ENDPOINT
unset when using this option:
import os
from langchain.chat_models import init_chat_model
os.environ["OPENAI_API_BASE"] = "https://{your-resource-name}.services.ai.azure.com/openai/v1"
os.environ["OPENAI_API_KEY"] = "{your-key}"
model = init_chat_model("azure_ai:gpt-5-mini")
model.invoke("Hello!").pretty_print()Use AgentServiceFactory to create a managed Foundry agent and add it as a
node in a LangGraph graph.
For local development, install the required extra and sign in:
pip install -U "langchain-azure-ai[opentelemetry]"
az loginSet your project endpoint and model deployment name. This creates a version
of my-echo-agent in your project:
from azure.identity import DefaultAzureCredential
from langchain_core.messages import HumanMessage
from langgraph.graph import END, START, StateGraph
from langchain_azure_ai.agents import AgentServiceAgentState, AgentServiceFactory
from langchain_azure_ai.utils.agents import pretty_print
factory = AgentServiceFactory(
project_endpoint="https://{your-resource-name}.services.ai.azure.com/api/projects/{your-project}",
credential=DefaultAzureCredential()
)
echo_node = factory.create_prompt_agent_node(
name="my-echo-agent",
model="gpt-4.1", # your model deployment name
instructions="Always reply with the opposite of what the user says.",
)Agent Service nodes run in Microsoft Foundry but can be added to any graph:
graph = StateGraph(AgentServiceAgentState)
graph.add_node("expert_node", echo_node)
graph.add_edge(START, "expert_node")
graph.add_edge("expert_node", END)Use the graph as usual:
agent = graph.compile()
messages = [HumanMessage(content="I'm a genius and I love programming!")]
response = agent.invoke({"messages": messages})
pretty_print(response)================================ Human Message =================================
I'm a genius and I love programming!
================================== Ai Message ==================================
Name: my-echo-agent
You're not a genius and you don't love programming!
We welcome contributions! Please see CONTRIBUTING.md for guidelines on how to contribute to this project.