|
| 1 | +--- |
| 2 | +title: Use AI tools and models in Azure Functions |
| 3 | +description: Describes the ways in which Azure Functions supports the use of AI in your function code executions, including LLMs, RAG, agentic workflows, and other AI-related frameworks. |
| 4 | +ms.topic: conceptual |
| 5 | +ms.date: 04/29/2025 |
| 6 | +ai-usage: ai-assisted |
| 7 | +ms.custom: |
| 8 | + - build-2025 |
| 9 | +ms.collection: |
| 10 | + - ce-skilling-ai-copilot |
| 11 | +zone_pivot_groups: programming-languages-set-functions |
| 12 | +#Customer intent: As a developer, I want to learn how I can leverage AI models, tools, and other resourtcers so that my function executions can take full advantage of all of the AI-related resources available to an Azure service. |
| 13 | +--- |
| 14 | + |
| 15 | +# Use AI tools and models in Azure Functions |
| 16 | + |
| 17 | +Azure Functions provides serverless compute resources that integrate with AI and Azure services to streamline the process of building cloud-hosted intelligent applications. This article provides a survey of the breadth of AI-related scenarios, integrations, and other AI resources that you can use in your function apps. |
| 18 | + |
| 19 | +Some of the inherent benefits of using Azure Functions as a compute resource for your AI-integrated tasks include: |
| 20 | + |
| 21 | ++ **Rapid, event-driven scaling**: you have compute resources available when you need it. With certain plans, your app scales back to zero when it's not needed. For more information, see [Event-driven scaling in Azure Functions](event-driven-scaling.md). |
| 22 | ++ **Built-in support for Azure OpenAI**: the [OpenAI binding extension] greatly simplifies the process of interacting with Azure OpenAI for working with agents, assistants, and retrieval-augmented generation (RAG) workflows. |
| 23 | ++ **Broad language and library support**: Functions lets you interact with AI using your [choice of programming language](./supported-languages.md), plus you're able to use a broad variety of [AI frameworks and libraries](#ai-tools-and-frameworks). |
| 24 | ++ **Orchestration capabilities**: while function executions are inherently stateless, the [Durable Functions extension](./durable/durable-functions-overview.md) lets you create the kind of complex workflows required by your AI agents. |
| 25 | + |
| 26 | +This article is language-specific, so make sure you choose your programming language at the [top of the page](#top). |
| 27 | + |
| 28 | +## Core AI integration scenarios |
| 29 | + |
| 30 | +The combination of built-in bindings and broad support for external libraries provides you with a wide range of potential scenarios for augmenting your apps and solutions with the power of AI. These are some key AI integration scenarios supported by Functions. |
| 31 | + |
| 32 | +### Retrieval-augmented generation |
| 33 | + |
| 34 | +Because Functions is able to handle multiple events from various data sources simultaneously, it's an effective solution for real-time AI scenarios, like RAG systems that require fast data retrieval and processing. Rapid event-driven scaling reduces the latency experienced by your customers, even in high-demand situations. |
| 35 | + |
| 36 | +Here are some reference samples for RAG-based scenarios: |
| 37 | + |
| 38 | +::: zone pivot="programming-language-csharp" |
| 39 | +**[RAG with Azure AI Search](https://github.com/Azure-Samples/azure-functions-openai-aisearch-dotnet)** |
| 40 | +::: zone-end |
| 41 | +::: zone pivot="programming-language-python" |
| 42 | +**[RAG with Azure AI Search](https://github.com/Azure-Samples/azure-functions-openai-aisearch-python)** |
| 43 | +::: zone-end |
| 44 | +::: zone pivot="programming-language-java,programming-language-typescript,programming-language-powershell" |
| 45 | +**[RAG with Azure AI Search](https://github.com/Azure/azure-functions-openai-extension/tree/main/samples/rag-aisearch)** |
| 46 | +::: zone-end |
| 47 | +::: zone pivot="programming-language-javascript" |
| 48 | +**[RAG with Azure AI Search](https://github.com/Azure-Samples/azure-functions-openai-aisearch-node)** |
| 49 | +::: zone-end |
| 50 | +> For RAG, you can use SDKs, including but not limited to Azure Open AI and Azure SDKs to build out your scenarios. This reference sample uses the [OpenAI binding extension] to highlight OpenAI RAG with Azure AI Search. |
| 51 | +
|
| 52 | +::: zone pivot="programming-language-csharp" |
| 53 | +**[Custom chat bot](https://github.com/Azure-Samples/function-dotnet-ai-openai-chatgpt/)** |
| 54 | +::: zone-end |
| 55 | +::: zone pivot="programming-language-python" |
| 56 | +**[Custom chat bot](https://github.com/Azure-Samples/function-python-ai-openai-chatgpt)** |
| 57 | +::: zone-end |
| 58 | +::: zone pivot="programming-language-java,programming-language-typescript,programming-language-powershell" |
| 59 | +**[Custom chat bot](https://github.com/Azure/azure-functions-openai-extension/tree/main/samples/chat)** |
| 60 | +::: zone-end |
| 61 | +::: zone pivot="programming-language-javascript" |
| 62 | +**[Custom chat bot](https://github.com/Azure-Samples/function-javascript-ai-openai-chatgpt)** |
| 63 | +::: zone-end |
| 64 | +::: zone pivot="programming-language-csharp,programming-language-javascript,programming-language-python" |
| 65 | +> Shows you how to create a friendly chat bot that issues simple prompts, receives text completions, and sends messages, all in a stateful session using the [OpenAI binding extension]. |
| 66 | +::: zone-end |
| 67 | + |
| 68 | +### Assistant function calling |
| 69 | + |
| 70 | +Assistant function calling gives your AI assistant or agent the ability to invoke specific functions or APIs dynamically based on the context of a conversation or task. These behaviors enable assistants to interact with external systems, retrieve data, and perform other actions. |
| 71 | + |
| 72 | +Functions is ideal for implementing assistant function calling in agentic workflows. In addition to scaling efficiently to handle demand, [binding extensions](./functions-triggers-bindings.md) simplify the process of using Functions to connect assistants with remote Azure services. If there's no binding for your data source or you need full control over SDK behaviors, you can always manage your own client SDK connections in your app. |
| 73 | + |
| 74 | +::: zone pivot="programming-language-java,programming-language-typescript,programming-language-powershell" |
| 75 | +Here are some reference samples for assistant function calling scenarios: |
| 76 | +::: zone-end |
| 77 | +::: zone pivot="programming-language-csharp" |
| 78 | +**[Assistants function calling (OpenAI bindings)](https://github.com/Azure-Samples/azure-functions-assistants-openai-dotnet)** |
| 79 | +::: zone-end |
| 80 | +::: zone pivot="programming-language-python" |
| 81 | +**[Assistants function calling (OpenAI bindings)](https://github.com/Azure-Samples/azure-functions-assistants-python)** |
| 82 | +::: zone-end |
| 83 | +::: zone pivot="programming-language-csharp,programming-language-python" |
| 84 | +> Uses the [OpenAI binding extension] to enable calling custom functions with the assistant skill trigger. |
| 85 | +::: zone-end |
| 86 | +::: zone pivot="programming-language-csharp" |
| 87 | +**[Agents function calling (Azure AI SDKs)](https://github.com/Azure-Samples/azure-functions-ai-services-agent-dotnet)** |
| 88 | +::: zone-end |
| 89 | +::: zone pivot="programming-language-python" |
| 90 | +**[Agents function calling (Azure AI SDKs)](https://github.com/Azure-Samples/azure-functions-ai-services-agent-python)** |
| 91 | +::: zone-end |
| 92 | +::: zone pivot="programming-language-javascript" |
| 93 | +**[Agents function calling (Azure AI SDKs)](https://github.com/Azure-Samples/azure-functions-ai-services-agent-javascript)** |
| 94 | +::: zone-end |
| 95 | +::: zone pivot="programming-language-csharp,programming-language-python,programming-language-javascript" |
| 96 | +> Uses function calling features for agents in Azure AI SDKs to implement custom functions calling. |
| 97 | +::: zone-end |
| 98 | +### Remote MCP servers |
| 99 | + |
| 100 | +The Model Context Protocol (MCP) provides a standardized way for AI models to communicate with external systems to determine their capabilities and how they can best be used by AI assistants and agents. An MCP server enables an AI model (client) to more efficiently make these determinations. |
| 101 | + |
| 102 | +Functions provides an MCP binding extension that simplifies the process of creating custom MCP servers in Azure. |
| 103 | + |
| 104 | +::: zone pivot="programming-language-java,programming-language-javascript,programming-language-powershell" |
| 105 | +Here's an example of such a custom MCP server project: |
| 106 | +::: zone-end |
| 107 | +::: zone pivot="programming-language-csharp" |
| 108 | +**[Remote MCP servers](https://github.com/Azure-Samples/remote-mcp-functions-dotnet)** |
| 109 | +::: zone-end |
| 110 | +::: zone pivot="programming-language-python" |
| 111 | +**[Remote MCP servers](https://github.com/Azure-Samples/remote-mcp-functions-python)** |
| 112 | +::: zone-end |
| 113 | +::: zone pivot="programming-language-typescript" |
| 114 | +**[Remote MCP servers](https://github.com/Azure-Samples/remote-mcp-functions-typescript)** |
| 115 | +::: zone-end |
| 116 | +::: zone pivot="programming-language-csharp,programming-language-python,programming-language-typescript" |
| 117 | +> Provides an MCP server template along with several function tool endpoints, which can be run locally and also deployed to Azure. |
| 118 | +::: zone-end |
| 119 | +### Agentic workflows |
| 120 | + |
| 121 | +While it's common for AI-driven processes to autonomously determine how to interact with models and other AI assets, there are many cases where a higher level of predicability is required or where the required steps are well-defined. These directed agentic workflows are composed of an orchestration of separate tasks or interactions that agents are required to follow. |
| 122 | + |
| 123 | +The [Durable Functions extension](durable/durable-functions-overview.md) helps you take advantage of the strengths of Functions to create multi-step, long-running operations with built-in fault tolerance. These workflows are perfect for your directed agentic workflows. For example, a trip planning solution might first gather requirements from the user, search for plan options, obtain user approval, and finally make required bookings. In this scenario, you can build an agent for each step and then coordinate their actions as a workflow using Durable Functions. |
| 124 | + |
| 125 | +For more workflow scenario ideas, see [Application patterns](durable/durable-functions-overview.md#application-patterns) in Durable Functions. |
| 126 | + |
| 127 | +## AI tools and frameworks |
| 128 | + |
| 129 | +Because Functions lets you build apps in your preferred language and using your favorite libraries, there's a wide range of flexibility in what AI libraries and frameworks you can use in your AI-enabled function apps. |
| 130 | + |
| 131 | +Here are some of the key Microsoft AI frameworks of which you should be aware: |
| 132 | + |
| 133 | +| Framework/library | Description | |
| 134 | +| ----- | ----- | |
| 135 | +| [Azure AI Services SDKs](/azure/developer/ai/azure-ai-for-developers) | By working directly with client SDKs, you can use the full breadth of Azure AI services functionality directly in your function code. | |
| 136 | +| [OpenAI binding extension] | Easily integrate the power of Azure OpenAI in your functions and let Functions manage the service integration. | |
| 137 | +| [Semantic Kernel](/semantic-kernel/overview) | Enables you to easily build AI agents and models. | |
| 138 | + |
| 139 | +Functions also enables your apps to reference third-party libraries and frameworks, which means that you can also use all of your favorite AI tools and libraries in your AI-enabled functions. |
| 140 | + |
| 141 | +## Related articles |
| 142 | + |
| 143 | ++ [Azure Functions scenarios](functions-scenarios.md) |
| 144 | ++ [Tutorial: Add Azure OpenAI text completion hints to your functions in Visual Studio Code](functions-add-openai-text-completion.md) |
| 145 | + |
| 146 | +[OpenAI binding extension]: functions-bindings-openai.md |
| 147 | + |
| 148 | + |
| 149 | + |
| 150 | + |
0 commit comments