Integrations for Microsoft Foundry (formerly Azure AI) — models, agents, tools, and observability.
This page contains reference documentation for Microsoft Foundry. See the docs for conceptual guides, tutorials, and examples.
Base class for connecting to services from Azure AI Foundry projects.
Azure AI embeddings model using the OpenAI-compatible API.
This class wraps :class:langchain_openai.OpenAIEmbeddings and adds
support for the project-endpoint pattern available in Azure AI Foundr
Toolkit for Azure AI Services.
Load tools from an Azure AI Foundry Toolbox and use them via MCP.
Azure AI Foundry Toolbox is a managed multi-MCP server that aggregates multiple configured tools behind a single MCP endpoint. This c
Input schema for the image generation tool.
Tool that generates images using an OpenAI-compatible image generation API.
This tool connects to model deployments in Azure AI Foundry or Azure OpenAI that expose an OpenAI-compatible ``/images/gene
Input schema for the speech-to-text tool.
Transcribes audio to text using an OpenAI-compatible speech-to-text API.
This tool connects to model deployments in Azure AI Foundry or Azure OpenAI that expose an OpenAI-compatible ``/audio/transcri
Input schema for AzureAIMemoryRetrieverTool.
Tool that retrieves relevant memories from Azure AI Foundry Memory.
This tool is designed to be used in conjunction with the
:class:AzureAIMemoryMiddleware to enable agents to store and retrieve
lo
A tool that interacts with Azure Logic Apps.
Base class for server-side built-in tools.
Inherits from :class:dict so instances can be passed directly to
model.bind_tools() without additional conversion. Subclasses build
the underlying :m
A tool that runs Python code server-side to help generate a response.
The model can write and execute Python code within a sandboxed container and include the results in its response.
Wraps :class:`
A tool that searches the internet for sources related to the prompt.
Wraps :class:openai.types.responses.WebSearchToolParam.
Example::
from langchain_azure_ai.tools.builtin import WebSearchTo
A tool that searches for relevant content from uploaded vector stores.
Wraps :class:openai.types.responses.FileSearchToolParam.
Example::
from langchain_azure_ai.tools.builtin import FileSear
A tool that generates or edits images using GPT image models.
Wraps :class:openai.types.responses.tool_param.ImageGeneration.
When model_deployment is specified the tool automatically injects
A tool that gives the model access to an external MCP server.
Allows the model to call tools exposed by a remote Model Context Protocol (MCP) server within a single conversational turn.
Wraps :class
Load documents, images, audio, and video using Azure Content Understanding.
Produces LangChain Document objects with extracted markdown content and rich metadata (fields, confidence scores, source in
Azure AI Search service retriever.
Setup:
See here for more detail: https://python.langchain.com/docs/integrations/retrievers/azure_ai_search/
We will need to install the below dependencies a
Azure Cognitive Search service retriever.
This version of the retriever will soon be depreciated. Please switch to AzureAISearchRetriever.
LangChain retriever that queries Foundry Memory with multi-turn context.
This retriever is designed for close coupling with
AzureAIMemoryChatMessageHistory. When bound to a history instance via
`hi
Enumerator of the Distance strategies for calculating distances between vectors.
Azure Cognitive Search vector store.
Retriever that uses Azure Cognitive Search.
Cache that uses Cosmos DB Mongo vCore vector-store backend.
Fallback base class when opentelemetry instrumentation is unavailable.
OpenTelemetry instrumentor implementation for LangChain auto-tracing.
Semantic convention attribute names used throughout the tracer.
Attributes sourced from the OpenTelemetry GenAI semantic conventions SDK (``opentelemetry.semconv._incubating.attributes.gen_ai_attribu
LangChain callback handler that emits OpenTelemetry GenAI spans.
Middleware that periodically extracts memories from turns into Azure AI Memory.
This middleware collects messages from the agent's state after each turn and sends them to Azure AI Memory in batches.
Input extracted from an agent state for image content moderation.
This is the return type for a context_extractor callable passed to
:class:`~langchain_azure_ai.agents.middleware.content_safety.A
AgentMiddleware that screens image content with Azure AI Content Safety.
Use this middleware alongside :class:AzureContentModerationMiddleware when
your agent handles visual content. Because i
A prompt-injection evaluation.
Input extracted from an agent state for prompt shield evaluation.
This is the return type for a context_extractor callable passed to
:class:`~langchain_azure_ai.agents.middleware.content_safety.A
AgentMiddleware that detects prompt injection using Azure AI Content Safety.
Prompt shield protects agents from adversarial inputs designed to hijack the agent's behavior. Two types of injection are
Raised when content safety violations with exit_behavior='error'.
Base class for all content-safety violations.
A harm-category evaluation from text or image content analysis.
Value payload stored inside a NonStandardAnnotation for violations.
A blocklist-match evaluation from text content analysis.
Input extracted from an agent state for text content moderation.
This is the return type for a context_extractor callable passed to
:class:`~langchain_azure_ai.agents.middleware.content_safety.Az
AgentMiddleware that screens text messages with Azure AI Content Safety.
Pass this class (or multiple instances) in the middleware parameter of
any LangChain create_agent call:
A groundedness evaluation.
Inputs extracted from an agent state for groundedness evaluation.
This is the return type for a context_extractor callable passed to
:class:`~langchain_azure_ai.agents.middleware.content_safety.A
AgentMiddleware that evaluates groundedness of model outputs.
Groundedness detection analyses language model outputs to determine whether they are factually aligned with user-provided information or
A protected-material evaluation.
AgentMiddleware that detects protected material using Azure AI Content Safety.
Protected material detection checks whether text contains copyright-protected content such as song lyrics, news articles
Stable bit assignments for hosting features reported in telemetry.
Values are ORed into a compact user-agent comment such as
(features=1f). Existing assignments must not be changed or reused.
Store the latest public status envelope for an invocation.
Local file-backed invocation state with atomic envelope replacement.
Hosted invocation state backed by a Foundry state-store item.
Host a LangGraph CompiledStateGraph as the Azure AI Responses API.
Persist LangGraph checkpoints in Microsoft Foundry state stores.
Each LangGraph thread_id maps to one state store named
{store_name_prefix}/{thread_id}. Checkpoint namespaces and IDs are
enco
Host a LangChain Runnable as the Invocations API.
Wrap hosting-owned data stored in a LangGraph runnable config.
A LangGraph thread and checkpoint reference.
Manage LangGraph references persisted with one Responses task.
Get and set named dictionaries within a conversation chain.
Implementations must satisfy these requirements:
set succeeds, subsequent :meth:get calls with
the sameStore each conversation chain in a separate FoundryStateStore.
Store creation and reuse follow FoundryStateStore.get_or_create semantics.
user_isolation, item_ttl_seconds, ``descripti
Aggregate LangChain usage metadata into Responses API usage.
Convert one LangGraph invocation stream into Responses events.
One converter is created per Responses call. It caches transient conversion state, such as a partially built message or IDs used for ded
Extended AgentState that carries per-invocation agent context.
By storing conversation IDs and pending-call type in the graph state (rather than on the node instance), the node becomes thread-saf
A LangGraph node for an existing Azure AI Foundry agent (V2 Responses API).
This node wraps a prompt-based agent that has already been created in Azure AI Foundry. It handles building requests and pr
A tool that interacts with Azure AI Foundry Agent Service V2.
Use this class to wrap tools from Azure AI Foundry for use with PromptBasedAgentNodeV2.
Example:
from langchain_azure_ai.agent
A wrapper around the Foundry ImageGenTool for use in AgentServiceBaseToolV2.
This class exists to provide a consistent import path for users who want to use the ImageGenTool with AgentServiceBaseTool
A wrapper around the Foundry CodeInterpreterTool.
This class exists to provide a consistent import path for users who want to use the CodeInterpreterTool with AgentServiceBaseToolV2, without needing
A wrapper around the Foundry MCPTool for use in AgentServiceBaseToolV2.
This class exists to provide a consistent import path for users who want to use the MCPTool with AgentServiceBaseToolV2, withou
Builds agent nodes from agents running in Azure AI Foundry.
You can create or deploy agents in the Azure AI Foundry Agent Service and then reference agents from LangGraph to compose complex workflows
History wrapper that updates Azure AI Foundry Memory per chat turn.
This class decorates a LangChain BaseChatMessageHistory, preserving
short-term transcript storage while forwarding each turn to F
Result from a Foundry evaluation run.
Wrapper around a single Foundry agent evaluator.
Manages the lifecycle of creating an eval definition and running evaluations against it. Each instance corresponds to one evaluator type (e.g., TaskCo
Run multiple Foundry evaluators in sequence.
Convenience class that holds multiple FoundryEvaluator instances
and runs them all against the same input.
Azure AI chat model using the Anthropic Messages API.
Wraps :class:langchain_anthropic.ChatAnthropic so that Anthropic
Claude models hosted by Azure AI Foundry can be accessed through the
``/anthro
Azure AI chat model using the OpenAI-compatible API.
This class wraps :class:langchain_openai.ChatOpenAI and adds support
for the project-endpoint pattern available in Azure AI Foundry, in additi
Azure AI model inference for embeddings.
This class has been deprecated in favor of AzureAIOpenAIApiEmbeddingsModel.
Examples:
from langchain_azure_ai.embeddings import AzureAIEmbed
Factory to create and manage prompt-based agents in Azure AI Foundry.
To create a simple echo agent:
from langchain_azure_ai.agents import AgentServiceFactory
from langchain_core.messages
A tool that interacts with Azure AI Foundry Agent Service.
Use this class to wrap tools from Azure AI Foundry for use with DeclarativeChatAgentNode.
Example:
from langchain_azure_ai.agents
A LangGraph node that represents a prompt-based agent in Azure AI Foundry.
You can use this node to create complex graphs that involve interactions with an Azure AI Foundry agent.
You can also use `
Azure AI Chat Completions Model.
This class has been deprecated in favor of AzureAIOpenAIApiChatModel.
The Azure AI model inference API (https://aka.ms/azureai/modelinference) provides a common la
Register an extra UA prefix (idempotent).
Prefixes are emitted by :func:get_user_agent in insertion order,
space-separated, before :data:BASE_USER_AGENT. Subpackages should
use this from their ``
Register or replace a named UA prefix.
The key retains its insertion position when its value changes, allowing feature-bearing prefixes to evolve without leaving stale tokens behind. Callable prefixe
Return whether the current process is running inside Foundry hosting.
Return the combined User-Agent string.
Format: "<prefix1> <prefix2> ... langchain-azure-ai/<ver>" when
prefixes have been registered, otherwise just
"langchain-azure-ai/<ver>".
Returns an em
Return headers with our UA prepended to any existing User-Agent.
When headers is None and telemetry is enabled, a new dict is
returned containing only the User-Agent entry. When t
Clear the prefix registry and detection cache.
Tests that toggle env vars or simulate hosting detection should call this to keep state isolated.
Calculate maximal marginal relevance.
Filter out metadata types that are not supported for a vector store.
Raise a clear error when OTel instrumentation is not installed.
Enable auto-injection of Azure tracer into callback managers.
When called, every new BaseCallbackManager instance and every callback
manager created through LangGraph's helper factories will auto
Disable callback manager auto-tracing and restore original behavior.
Return whether auto-tracing monkey patch is currently enabled.
Determine the next node based on whether the AI message contains tool calls.
Extract content-safety annotation payloads from a message.
Inspects the message's content for non_standard_annotation
blocks whose value contains provider == "azure_content_safety".
Print a formatted summary of content-safety annotations on a message.
Useful for troubleshooting and inspecting middleware results in
notebooks or the console. Extracts all non_standard content
Return the hosting UA with its compact hexadecimal feature mask.
Return the process and current-request hosting features.
Select the same hosted/local durability split used by Responses.
Load the selected graph and run it with the requested protocol.
Yield the Responses API events that summarise a final graph state.
Walks every message appended after the last :class:HumanMessage so
intermediate tool calls and tool results are surfaced to the cl
Return the interrupts pending on the checkpointed state, if any.
StateSnapshot.interrupts accumulates every interrupt recorded on the
checkpoint and is not pruned as they are answered, so after
Pass through a graph stream while recording its active interrupts.
LangGraph's updates.__interrupt__ payload is the authoritative active
set for the current invocation. Unlike checkpoint task his
Render the {"interrupt_id", "value"} envelope as a JSON string.
The envelope is used as the arguments payload on both the
function_call and mcp_approval_request items emitted by
:func
Build portable Responses-style output items for pending interrupts.
Unlike :func:emit_interrupts, this helper does not require a Responses
event stream, so generic protocol adapters can expose the
Return the call_ids reserved by the HITL wire protocol.
An id is reserved when items carries a function_call named
:data:HITL_FUNCTION_NAME — the sentinel this host emits for a pending
in
Build a resume :class:Command from request input items, if present.
Two input shapes are accepted, both keyed by interrupt.id:
FunctionCallOutputItemParam matched by call_id. ItReturn a human-readable message if the client rejected an interrupt.
Scans for :class:MCPApprovalResponse items whose
approval_request_id matches a pending interrupt and whose
approve is ``
Yield Responses API events that surface pending interrupts.
Each interrupt produces two output items in the same response:
function_call item (name :data:HITL_FUNCTION_NAME,
``call_iIterate the graph stream and yield Responses API events.
Each invocation handles one Responses turn by consuming the complete stream from one LangGraph execution. A graph run may contain multiple sup
Return True when state_schema exposes a messages field.
LangGraph compiles graphs against a TypedDict (or dataclass-like) state schema. The default request/response converters only know how
Return the plain-text representation of a LangChain message content.
LangChain message content is either a string or a list of content
parts. String parts are concatenated; non-string parts (
Return the reasoning summary text fragments in a message content.
When a chat model is configured to stream reasoning summaries
(e.g. AzureChatOpenAI(reasoning={"summary": "auto"})), each
:cl
Return the text content of the last AIMessage in messages.
Used by the default Invocations and non-streaming Responses converters to surface the assistant's final answer after a graph run. When
Translate resolved Responses API items into LangChain messages.
Accepts the typed Item subtypes returned by
:meth:ResponseContext.get_input_items. Items that do not map cleanly
to a LangChain m
Build a {"messages": [...]} LangGraph input from resolved items.
Prepends a SystemMessage when instructions is non-empty. Empty
item lists yield an empty messages list — callers should typi
Build a {"messages": [...]} payload from a single user text string.
Convenience wrapper used by the Invocations converter when the body is already a plain string.
Determine the next node based on whether the AI message has tool calls.
Build a compiled evaluator-optimizer subgraph.
Creates a LangGraph StateGraph that implements the
evaluate→refine loop pattern. The returned compiled graph can
be used as a node in a parent graph
Build a compiled analyst subgraph with embedded eval-optimize loop.
Creates a LangGraph StateGraph for a specialist analyst:
research → write → eval-optimize (subgraph) → build_completed.
The ev
Convert a LangChain message sequence to Foundry evaluator input.
Splits the conversation into query (system + user messages up to
the last user message) and response (everything after, typica
Convert LangChain tool objects to Foundry tool_definitions format.
Converts a sequence of BaseMessage to ChatRequestMessage.
Convert an inference message dict to generic message.