An integration package to support Azure AI Foundry capabilities in LangChain/LangGraph ecosystem.
Project description
langchain-azure-ai
This package contains the LangChain integration for Azure AI Foundry. To learn more about how to use this package, see the LangChain documentation in Azure AI Foundry.
Installation
pip install -U langchain-azure-ai
For using tools, including Azure AI Document Intelligence, Azure AI Text Analytics for Health, or Azure LogicApps, please install the extras tools:
pip install -U langchain-azure-ai[tools]
For using tracing capabilities with OpenTelemetry, you need to add the extras opentelemetry:
pip install -U langchain-azure-ai[opentelemetry]
Quick Start with langchain-azure-ai
The langchain-azure-ai package uses the Azure AI Foundry family of SDKs and client libraries for Azure to provide first-class support of Azure AI Foundry capabilities in LangChain and LangGraph.
This package includes:
- Azure AI Agent Service
- Azure AI Foundry Models inference
- Azure AI Search
- Azure AI Services tools
- Cosmos DB
Here's a quick start example to show you how to get started with the Chat Completions model. For more details and tutorials see Develop with LangChain and LangGraph and models from Azure AI Foundry.
Azure AI Chat Completions Model with Azure OpenAI
from langchain_azure_ai.chat_models import AzureAIChatCompletionsModel
from langchain_core.messages import HumanMessage, SystemMessage
model = AzureAIChatCompletionsModel(
endpoint="https://{your-resource-name}.services.ai.azure.com/openai/v1",
credential="your-api-key", #if using Entra ID you can should use DefaultAzureCredential() instead
model="gpt-4o"
)
messages = [
SystemMessage(
content="Translate the following from English into Italian"
),
HumanMessage(content="hi!"),
]
model.invoke(messages)
AIMessage(content='Ciao!', additional_kwargs={}, response_metadata={'model': 'gpt-4o', 'token_usage': {'input_tokens': 20, 'output_tokens': 3, 'total_tokens': 23}, 'finish_reason': 'stop'}, id='run-0758e7ec-99cd-440b-bfa2-3a1078335133-0', usage_metadata={'input_tokens': 20, 'output_tokens': 3, 'total_tokens': 23})
Azure AI Chat Completions Model with DeepSeek-R1
from langchain_azure_ai.chat_models import AzureAIChatCompletionsModel
from langchain_core.messages import HumanMessage, SystemMessage
model = AzureAIChatCompletionsModel(
endpoint="https://{your-resource-name}.services.ai.azure.com/models",
credential="your-api-key", #if using Entra ID you can should use DefaultAzureCredential() instead
model="DeepSeek-R1",
)
messages = [
HumanMessage(content="Translate the following from English into Italian: \"hi!\"")
]
message_stream = model.stream(messages)
print(' '.join(chunk.content for chunk in message_stream))
<think>
Okay , the user just sent " hi !" and I need to translate that into Italian . Let me think . " Hi " is an informal greeting , so in Italian , the equivalent would be " C iao !" But wait , there are other options too . Sometimes people use " Sal ve ," which is a bit more neutral , but " C iao " is more common in casual settings . The user probably wants a straightforward translation , so " C iao !" is the safest bet here . Let me double -check to make sure there 's no nuance I 'm missing . N ope , " C iao " is definitely the right choice for translating " hi !" in an informal context . I 'll go with that .
</think>
C iao !
Changelog
-
1.0.4:
- We fixed an issue with dependencies resolution for
azure-ai-agentswhere the incorrect version was picked up. See [PR #221]. - We fixed an issue with
AzureAIOpenTelemetryTracerwhere spans context was not correctly propagated when called from another service. See [PR #217]. - We fixed an issue where
AzureAIOpenTelemetryTracerwhere context was deallocated incorrectly, preventing tools likelangdevto correctly emit traces. See [Issue #212]. - We introduced improvements in the order in which environment variables
AZURE_AI_*are read.
- We fixed an issue with dependencies resolution for
-
1.0.2:
- We updated the
AzureAIOpenTelemetryTracerto create a parent trace for multi agent scenarios. Previously, you were required to do this manually, which was unnecesary.
- We updated the
-
1.0.0:
- We introduce support for LangChain and LangGraph 1.0.
-
0.1.8:
- We fixed some issues with
AzureAIOpenTelemetryTracer, including compliant hierarchy, tool spans under chat, finish reason normalization, conversation id. See [PR #167] - We fixed an issue with taking image inputs for declarative agents created with Azure AI Foundry Agents service.
- We enhanced tool descriptions to improve tool call accuracy.
- We fixed some issues with
-
0.1.7:
- [NEW]: We introduce LangGraph support for declarative agents created in Azure AI Foundry. You can now compose complex graphs in LangGraph and add nodes that take advantage of Azure AI Agent Service. See
AgentServiceFactory - We fix an issue with the interface of
AzureAIEmbeddingsModel#158. - We improve the signatures of the tools
AzureAIDocumentIntelligenceTool,AzureAIImageAnalysisTool, andAzureAITextAnalyticsHealthToolPR #160.
- [NEW]: We introduce LangGraph support for declarative agents created in Azure AI Foundry. You can now compose complex graphs in LangGraph and add nodes that take advantage of Azure AI Agent Service. See
-
0.1.6:
- [Breaking change]: Using parameter
project_connection_stringto createAzureAIEmbeddingsModelandAzureAIChatCompletionsModelis not longer supported. Useproject_endpointinstead. - [Breaking change]: Class
AzureAIInferenceTracerhas been removed in favor ofAzureAIOpenTelemetryTracerwhich has a better support for OpenTelemetry and the new semantic conventions for GenAI. - Adding the following tools to the package:
AzureAIDocumentIntelligenceTool,AzureAIImageAnalysisTool, andAzureAITextAnalyticsHealthTool. You can also useAIServicesToolkitto have access to all the tools in Azure AI Services.
- [Breaking change]: Using parameter
-
0.1.4:
- Bug fix #91.
-
0.1.3:
- [Breaking change]: We renamed the parameter
model_nameinAzureAIEmbeddingsModelandAzureAIChatCompletionsModeltomodel, which is the parameter expected by the methodlangchain.chat_models.init_chat_model. - We fixed an issue with JSON mode in chat models #81.
- We fixed the dependencies for NumpPy #70.
- We fixed an issue when tracing Pyndantic objects in the inputs #65.
- We made
connection_stringparameter optional as suggested at #65.
- [Breaking change]: We renamed the parameter
-
0.1.2:
- Bug fix #35.
-
0.1.1:
- Adding
AzureCosmosDBNoSqlVectorSearchandAzureCosmosDBNoSqlSemanticCachefor vector search and full text search. - Adding
AzureCosmosDBMongoVCoreVectorSearchandAzureCosmosDBMongoVCoreSemanticCachefor vector search. - You can now create
AzureAIEmbeddingsModelandAzureAIChatCompletionsModelclients directly from your AI project's connection string using the parameterproject_connection_string. Your default Azure AI Services connection is used to find the model requested. This requires to haveazure-ai-projectspackage installed. - Support for native LLM structure outputs. Use
with_structured_output(method="json_schema")to use native structured schema support. Usewith_structured_output(method="json_mode")to use native JSON outputs capabilities. By default, LangChain usesmethod="function_calling"which uses tool calling capabilities to generate valid structure JSON payloads. This requires to haveazure-ai-inference >= 1.0.0b7. - Bug fix #18 and #31.
- Adding
-
0.1.0:
- Introduce
AzureAIEmbeddingsModelfor embedding generation andAzureAIChatCompletionsModelfor chat completions generation using the Azure AI Inference API. This client also supports GitHub Models endpoint. - Introduce
AzureAIOpenTelemetryTracerfor tracing with OpenTelemetry and Azure Application Insights.
- Introduce
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file langchain_azure_ai-1.0.4.tar.gz.
File metadata
- Download URL: langchain_azure_ai-1.0.4.tar.gz
- Upload date:
- Size: 84.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0dffa882f103baa211380086cb35b9cac56eb99f4315067b5aa25c9ed426829d
|
|
| MD5 |
b21f42ada8837b01c0456bcb6edabec4
|
|
| BLAKE2b-256 |
1d2cb58e890a0445c1d987570f56e19b077859e6019e44694e6847b3bd722113
|
File details
Details for the file langchain_azure_ai-1.0.4-py3-none-any.whl.
File metadata
- Download URL: langchain_azure_ai-1.0.4-py3-none-any.whl
- Upload date:
- Size: 100.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c2031172c4acf743a24d4cdb430078464ac3e8e0c1704ced3e719b566628d638
|
|
| MD5 |
991bfefc81933ca857076a2fd5eb4848
|
|
| BLAKE2b-256 |
88d0b960ae9ac877cd601a3155767ebcad8a049c4cf500fed466e4c1e9917b1c
|