Azure functions

From j4flmao/agent-skills · View interactive version

Azure functions is an AI agent skill from the GitHub repository j4flmao/agent-skills. Use when the user asks about Azure Functions, Durable Functions orchestrator or activity functions, durable entities, fan-out/fan-in, Event Grid triggers, Flex Consumption or other hosting plans. Produces replay-safe Durable Functions code and a hosting-plan choice. Not for AWS Lambda (use cloud-nat

How to use this skill

Skill file

Azure Functions and Durable Functions

Purpose

Build event-driven Azure Functions and stateful Durable Functions workflows correctly. The key mechanics are the Durable Task Framework's event-sourced replay (which dictates strict orchestrator coding rules) and Event Grid's push delivery with retries (which dictates idempotent handlers).

Agent Protocol

Trigger

"azure functions", "durable functions", "orchestrator function", "activity function", "durable entities", "event grid trigger", "flex consumption", "hosting plan", "fan-out fan-in".

Input Context

Output Artifact

Function code and host/plan configuration. No file unless requested.

Response Format

Hosting plan: {Flex Consumption|Premium|Dedicated|Container Apps} (why)
Pattern: {function chaining|fan-out/fan-in|async HTTP API|monitor|human interaction|aggregator}
Durable backend: {Azure Storage|Netherite|MSSQL|Durable Task Scheduler}
Idempotency: {how duplicates are handled}

Completion Criteria

Durable Functions Mechanics

Orchestrator Rules (replay safety)

| Do not | Use instead |

|---|---|

| DateTime.UtcNow, new Date() | context.CurrentUtcDateTime / context.df.currentUtcDateTime |

| Guid.NewGuid(), random numbers | context.NewGuid() or generate inside an activity |

| HTTP calls, DB queries, file I/O | Activity functions (or CallHttpAsync durable HTTP) |

| Thread.Sleep, Task.Delay, setTimeout | context.CreateTimer(...) |

| Unbounded loops creating huge history | ContinueAsNew to restart with fresh history |

| Logging without guard | context.CreateReplaySafeLogger(...) / check IsReplaying |

Fan-out / Fan-in (.NET isolated worker)

using Microsoft.Azure.Functions.Worker;
using Microsoft.DurableTask;
using Microsoft.DurableTask.Client;

public static class ResizeImages
{
    [Function(nameof(ResizeOrchestrator))]
    public static async Task<int> ResizeOrchestrator(
        [OrchestrationTrigger] TaskOrchestrationContext context)
    {
        string[] blobs = await context.CallActivityAsync<string[]>(nameof(ListBlobs), "incoming");

        var retry = TaskOptions.FromRetryPolicy(new RetryPolicy(
            maxNumberOfAttempts: 3, firstRetryInterval: TimeSpan.FromSeconds(5)));

        var tasks = blobs.Select(b => context.CallActivityAsync<long>(nameof(Resize), b, retry));
        long[] sizes = await Task.WhenAll(tasks);          // fan-in
        return sizes.Length;
    }

    [Function(nameof(ListBlobs))]
    public static string[] ListBlobs([ActivityTrigger] string container) =>
        BlobLister.List(container);                       // I/O allowed in activities

    [Function(nameof(Resize))]
    public static long Resize([ActivityTrigger] string blobName) =>
        ImageResizer.Resize(blobName);

    [Function("ResizeStart")]
    public static async Task<HttpResponseData> Start(
        [HttpTrigger(AuthorizationLevel.Function, "post")] HttpRequestData req,
        [DurableClient] DurableTaskClient client)
    {
        string id = await client.ScheduleNewOrchestrationInstanceAsync(nameof(ResizeOrchestrator));
        return await client.CreateCheckStatusResponseAsync(req, id); // 202 + status URLs
    }
}

BlobLister and ImageResizer are your own services; the orchestrator never touches storage directly.

Event Grid Delivery Semantics

Hosting Plan Decision

| Plan | Scale to zero | VNet integration | Notes |

|---|---|---|---|

| Flex Consumption | Yes | Yes | Recommended serverless plan for new Linux apps; per-function scaling, always-ready instances optional |

| Consumption (Windows/legacy Linux) | Yes | No | Linux Consumption is legacy—prefer Flex Consumption for new work |

| Premium (Elastic Premium) | No (min 1 warm) | Yes | Pre-warmed instances, longer executions |

| Dedicated (App Service plan) | No | Yes | Predictable cost when you already run App Service |

| Azure Container Apps | Yes | Yes | Functions in containers alongside other microservices |

Durable Functions orchestrations can run for days; individual activity executions are still bound by the plan's function timeout.

Anti-Patterns

Checklist

References

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.