agentleFS
shyamsridhar123shyamsridhar123/oneshot/.github/skills/agent-deployment/SKILL.md

agent-deployment

Skill4 starsChanged 10 months agoMITView on GitHub

Deploy Microsoft Agent Framework agents to production environments including Azure Functions, containers, and Azure AI Foundry. Use this skill when deploying agents to cloud platforms, containerizing agents, or integrating with Azure services.

  • Reads credentials
  • Installs packages

1 other project uses a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

4 rules. About 0 are common, 4 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈4

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Always implement health endpoints:

    line 368
  2. Distinctive:

    Use Managed Identity: - Never embed API keys in code

    line 387
  3. Distinctive:

    Enable HTTPS only: - No unencrypted traffic

    line 388
  4. Distinctive:

    Add authentication: - Use Azure AD or API keys

    line 390

≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Deploying Microsoft Agent Framework Agents

This skill helps you deploy AI agents built with Microsoft Agent Framework to production environments.

When to Use This Skill

  • Deploying agents to Azure Functions
  • Containerizing agents with Docker
  • Deploying to Azure AI Foundry
  • Setting up production configurations
  • Scaling agent workloads

Deployment Options

PlatformBest ForScaling
Azure FunctionsEvent-driven, serverlessAutomatic
Azure Container AppsContainerized workloadsAutomatic
Azure Kubernetes ServiceEnterprise, multi-agentManual/Auto
Azure AI FoundryFull lifecycle managementManaged

Azure Functions Deployment (Python)

Project Structure

my-agent-function/
├── function_app.py
├── requirements.txt
├── host.json
└── local.settings.json

function_app.py

import azure.functions as func
import asyncio
import json
from agent_framework.azure import AzureOpenAIResponsesClient
from azure.identity import DefaultAzureCredential

app = func.FunctionApp()

# Initialize agent once (reuse across invocations)
def get_agent():
    return AzureOpenAIResponsesClient(
        credential=DefaultAzureCredential()
    ).as_agent(
        name="ProductionAgent",
        instructions="You are a helpful assistant."
    )

agent = get_agent()

@app.route(route="chat", methods=["POST"])
async def chat(req: func.HttpRequest) -> func.HttpResponse:
    try:
        body = req.get_json()
        message = body.get("message", "")
        
        if not message:
            return func.HttpResponse(
                json.dumps({"error": "Message is required"}),
                status_code=400,
                mimetype="application/json"
            )
        
        response = await agent.run(message)
        
        return func.HttpResponse(
            json.dumps({"response": response}),
            status_code=200,
            mimetype="application/json"
        )
    except Exception as e:
        return func.HttpResponse(
            json.dumps({"error": str(e)}),
            status_code=500,
            mimetype="application/json"
        )

requirements.txt

azure-functions
agent-framework
azure-identity

host.json

{
  "version": "2.0",
  "extensions": {
    "http": {
      "routePrefix": "api"
    }
  },
  "logging": {
    "logLevel": {
      "default": "Information"
    }
  }
}

local.settings.json

{
  "IsEncrypted": false,
  "Values": {
    "FUNCTIONS_WORKER_RUNTIME": "python",
    "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    "AZURE_OPENAI_ENDPOINT": "https://your-resource.openai.azure.com/",
    "AZURE_OPENAI_RESPONSES_DEPLOYMENT_NAME": "gpt-4o-mini"
  }
}

Deploy to Azure

# Create Function App
az functionapp create \
    --resource-group myResourceGroup \
    --consumption-plan-location eastus \
    --runtime python \
    --runtime-version 3.11 \
    --functions-version 4 \
    --name my-agent-function \
    --storage-account mystorageaccount

# Enable managed identity
az functionapp identity assign \
    --resource-group myResourceGroup \
    --name my-agent-function

# Grant access to Azure OpenAI
az role assignment create \
    --role "Cognitive Services OpenAI User" \
    --assignee <managed-identity-principal-id> \
    --scope /subscriptions/<sub-id>/resourceGroups/<rg>/providers/Microsoft.CognitiveServices/accounts/<aoai-resource>

# Deploy
func azure functionapp publish my-agent-function

Azure Functions Deployment (.NET)

Project Structure

MyAgentFunction/
├── Program.cs
├── ChatFunction.cs
├── MyAgentFunction.csproj
├── host.json
└── local.settings.json

ChatFunction.cs

using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Http;
using Microsoft.Extensions.Logging;
using System.Net;
using System.Text.Json;

public class ChatFunction
{
    private readonly ILogger<ChatFunction> _logger;
    private readonly IAIAgent _agent;

    public ChatFunction(ILogger<ChatFunction> logger, IAIAgent agent)
    {
        _logger = logger;
        _agent = agent;
    }

    [Function("chat")]
    public async Task<HttpResponseData> Run(
        [HttpTrigger(AuthorizationLevel.Function, "post")] HttpRequestData req)
    {
        var body = await JsonSerializer.DeserializeAsync<ChatRequest>(req.Body);
        
        var response = await _agent.RunAsync(body.Message);
        
        var httpResponse = req.CreateResponse(HttpStatusCode.OK);
        await httpResponse.WriteAsJsonAsync(new { response });
        return httpResponse;
    }
}

public record ChatRequest(string Message);

Program.cs

using Azure.Identity;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using OpenAI;

var host = new HostBuilder()
    .ConfigureFunctionsWebApplication()
    .ConfigureServices(services =>
    {
        services.AddApplicationInsightsTelemetryWorkerService();
        services.ConfigureFunctionsApplicationInsights();
        
        // Register agent as singleton
        services.AddSingleton<IAIAgent>(sp =>
        {
            var client = new OpenAIClient(
                new BearerTokenPolicy(new DefaultAzureCredential(), "https://ai.azure.com/.default"),
                new OpenAIClientOptions() 
                { 
                    Endpoint = new Uri(Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT")!) 
                });
            
            return client.GetOpenAIResponseClient(
                Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENT")!)
                .AsAIAgent(name: "ProductionAgent", instructions: "You are helpful.");
        });
    })
    .Build();

host.Run();

Docker Deployment

Dockerfile (Python)

FROM python:3.11-slim

WORKDIR /app

COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

COPY . .

EXPOSE 8000

CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]

main.py (FastAPI)

from fastapi import FastAPI, HTTPException
from pydantic import BaseModel
from agent_framework.azure import AzureOpenAIResponsesClient
from azure.identity import DefaultAzureCredential

app = FastAPI()

agent = AzureOpenAIResponsesClient(
    credential=DefaultAzureCredential()
).as_agent(
    name="ProductionAgent",
    instructions="You are a helpful assistant."
)

class ChatRequest(BaseModel):
    message: str

class ChatResponse(BaseModel):
    response: str

@app.post("/chat", response_model=ChatResponse)
async def chat(request: ChatRequest):
    try:
        response = await agent.run(request.message)
        return ChatResponse(response=response)
    except Exception as e:
        raise HTTPException(status_code=500, detail=str(e))

@app.get("/health")
async def health():
    return {"status": "healthy"}

Build and Deploy to Azure Container Apps

# Build image
docker build -t my-agent:latest .

# Push to Azure Container Registry
az acr login --name myregistry
docker tag my-agent:latest myregistry.azurecr.io/my-agent:latest
docker push myregistry.azurecr.io/my-agent:latest

# Deploy to Container Apps
az containerapp create \
    --name my-agent-app \
    --resource-group myResourceGroup \
    --environment myEnvironment \
    --image myregistry.azurecr.io/my-agent:latest \
    --target-port 8000 \
    --ingress external \
    --min-replicas 1 \
    --max-replicas 10 \
    --user-assigned <managed-identity-id> \
    --env-vars \
        AZURE_OPENAI_ENDPOINT=https://... \
        AZURE_OPENAI_RESPONSES_DEPLOYMENT_NAME=gpt-4o-mini

Azure AI Foundry Integration

Microsoft Agent Framework integrates with Azure AI Foundry for full lifecycle management.

from agent_framework.azure import AzureAIFoundryClient

# Connect to Azure AI Foundry project
client = AzureAIFoundryClient(
    project_name="my-ai-project",
    resource_group="myResourceGroup"
)

# Deploy agent to Foundry
deployment = await client.deploy_agent(
    agent=agent,
    deployment_name="production-agent",
    instance_type="Standard_DS3_v2",
    instance_count=2
)

print(f"Deployed to: {deployment.endpoint}")

Production Configuration

Environment Variables

# Required
AZURE_OPENAI_ENDPOINT=https://your-resource.openai.azure.com/
AZURE_OPENAI_RESPONSES_DEPLOYMENT_NAME=gpt-4o-mini

# Optional
AZURE_OPENAI_API_VERSION=2024-02-15-preview
APPLICATIONINSIGHTS_CONNECTION_STRING=InstrumentationKey=...

# For non-managed-identity auth
AZURE_OPENAI_API_KEY=your-key

Health Checks

Always implement health endpoints:

@app.get("/health/live")
async def liveness():
    return {"status": "alive"}

@app.get("/health/ready")
async def readiness():
    # Check agent connectivity
    try:
        await agent.run("health check")
        return {"status": "ready"}
    except Exception as e:
        return {"status": "not ready", "error": str(e)}

Security Best Practices

  1. Use Managed Identity - Never embed API keys in code
  2. Enable HTTPS only - No unencrypted traffic
  3. Implement rate limiting - Prevent abuse
  4. Add authentication - Use Azure AD or API keys
  5. Log requests - For audit and debugging
  6. Set timeouts - Prevent runaway requests

Example: Rate Limiting Middleware

from fastapi import Request
from fastapi.responses import JSONResponse
from collections import defaultdict
import time

class RateLimiter:
    def __init__(self, requests_per_minute: int = 60):
        self.requests_per_minute = requests_per_minute
        self.requests = defaultdict(list)
    
    async def __call__(self, request: Request, call_next):
        client_ip = request.client.host
        now = time.time()
        
        # Clean old requests
        self.requests[client_ip] = [
            t for t in self.requests[client_ip] 
            if now - t < 60
        ]
        
        if len(self.requests[client_ip]) >= self.requests_per_minute:
            return JSONResponse(
                {"error": "Rate limit exceeded"},
                status_code=429
            )
        
        self.requests[client_ip].append(now)
        return await call_next(request)

app.middleware("http")(RateLimiter(requests_per_minute=60))

Scaling Considerations

MetricRecommendation
Requests/secStart with 2-3 instances, scale based on load
Memory512MB-1GB per instance minimum
Timeout30-60 seconds for agent responses
Cold startUse premium/dedicated plans to minimize
Concurrency10-20 concurrent requests per instance

References

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.