This guide covers deploying SignalWire AI Agents to serverless platforms from .NET.
SignalWire AI Agents support deployment to major cloud function platforms:
- Azure Functions - Serverless compute service on Microsoft Azure
- AWS Lambda - Serverless compute on Amazon Web Services
- Google Cloud Functions - Serverless compute on Google Cloud
The agent automatically detects Azure Functions environment using these variables:
AZURE_FUNCTIONS_ENVIRONMENT- Azure Functions runtime environmentFUNCTIONS_WORKER_RUNTIME- Runtime languageAzureWebJobsStorage- Azure storage connection string
- Create your function project:
func init MyAgentFunction --dotnet
cd MyAgentFunction
func new --name AgentHandler --template "HttpTrigger"- Add the SignalWire SDK reference:
<PackageReference Include="SignalWire.Sdk" Version="*" />- Create the function (
AgentHandler.cs). TheSignalWire.Serverless.Adapterstatic class bridges the platform request into the agent'sHandleRequestand returns a platform response dictionary (Adapter.HandleAzure(agent, request)):
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Http;
using SignalWire.Agent;
using SignalWire.Serverless;
public class AgentHandler
{
private readonly AgentBase _agent;
public AgentHandler()
{
_agent = new AgentBase(new AgentOptions
{
Name = "azure-agent",
Route = "/",
});
_agent.PromptAddSection("Role", "You are a helpful assistant running on Azure Functions.");
_agent.AddLanguage("English", "en-US", "inworld.Mark");
_agent.SetParams(new Dictionary<string, object> { ["ai_model"] = "gpt-4.1-nano" });
}
[Function("AgentHandler")]
public Dictionary<string, object?> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequestData req)
{
// Build the request dictionary (method/url/headers/body) from req,
// then dispatch through the adapter.
var request = new Dictionary<string, object?>
{
["method"] = req.Method,
["url"] = req.Url.ToString(),
};
return Adapter.HandleAzure(_agent, request);
}
}- Deploy using Azure CLI:
az functionapp create \
--resource-group myResourceGroup \
--consumption-plan-location westus \
--runtime dotnet-isolated \
--runtime-version 8.0 \
--functions-version 4 \
--name my-agent-function \
--storage-account mystorageaccount
func azure functionapp publish my-agent-functionSet these in your Azure Function App settings:
SIGNALWIRE_PROJECT_ID="your-project-id"
SIGNALWIRE_API_TOKEN="your-token"
AGENT_USERNAME="your-username"
AGENT_PASSWORD="your-password"https://{function-app-name}.azurewebsites.net/api/{function-name}
With authentication:
https://username:password@{function-app-name}.azurewebsites.net/api/{function-name}
- Create a Lambda project:
dotnet new lambda.EmptyFunction --name MyAgentLambda
cd MyAgentLambda/src/MyAgentLambda
dotnet add package SignalWire.Sdk
dotnet add package Amazon.Lambda.Core- Create your handler (
Function.cs). The handler receives the API Gateway event dictionary and passes it (with the agent) toAdapter.HandleLambda, which returns the API Gateway response (statusCode/headers/body):
using Amazon.Lambda.Core;
using SignalWire.Agent;
using SignalWire.Serverless;
public class LambdaFunction
{
private readonly AgentBase _agent;
public LambdaFunction()
{
_agent = new AgentBase(new AgentOptions
{
Name = "lambda-agent",
Route = "/",
});
_agent.PromptAddSection("Role", "You are a helpful assistant running on AWS Lambda.");
_agent.AddLanguage("English", "en-US", "inworld.Mark");
_agent.SetParams(new Dictionary<string, object> { ["ai_model"] = "gpt-4.1-nano" });
}
public Dictionary<string, object?> Handler(Dictionary<string, object?> apiGatewayEvent)
=> Adapter.HandleLambda(_agent, apiGatewayEvent);
}- Deploy:
dotnet lambda deploy-function MyAgentLambda \
--function-role arn:aws:iam::123456789:role/lambda-roleexport SIGNALWIRE_PROJECT_ID="your-project-id"
export SIGNALWIRE_API_TOKEN="your-token"
export SWML_BASIC_AUTH_USER="dev"
export SWML_BASIC_AUTH_PASSWORD="w00t"- Create your function project:
dotnet new web -n MyAgentFunction
cd MyAgentFunction
dotnet add package SignalWire.Sdk
dotnet add package Google.Cloud.Functions.Hosting- Create your function (
Function.cs). Google Cloud Functions has no dedicated adapter entry point; dispatch the request straight to the agent'sHandleRequest(method, path, headers, body), which returns a(Status, Headers, Body)tuple:
using Google.Cloud.Functions.Framework;
using Microsoft.AspNetCore.Http;
using SignalWire.Agent;
public class AgentFunction : IHttpFunction
{
private readonly AgentBase _agent;
public AgentFunction()
{
_agent = new AgentBase(new AgentOptions
{
Name = "gcp-agent",
Route = "/",
});
_agent.PromptAddSection("Role", "You are a helpful assistant on Google Cloud.");
_agent.AddLanguage("English", "en-US", "inworld.Mark");
_agent.SetParams(new Dictionary<string, object> { ["ai_model"] = "gpt-4.1-nano" });
}
public async Task HandleAsync(HttpContext context)
{
using var reader = new StreamReader(context.Request.Body);
var body = await reader.ReadToEndAsync();
var headers = context.Request.Headers
.ToDictionary(h => h.Key, h => h.Value.ToString());
var (status, respHeaders, respBody) =
_agent.HandleRequest(context.Request.Method, context.Request.Path, headers, body);
context.Response.StatusCode = status;
foreach (var kvp in respHeaders) context.Response.Headers[kvp.Key] = kvp.Value;
await context.Response.WriteAsync(respBody);
}
}- Deploy:
gcloud functions deploy my-agent \
--runtime dotnet8 \
--trigger-http \
--entry-point AgentFunction \
--allow-unauthenticatedhttps://{region}-{project-id}.cloudfunctions.net/{function-name}
All platforms support HTTP Basic Authentication:
using SignalWire.Agent;
var agent = new AgentBase(new AgentOptions
{
Name = "my-agent",
BasicAuthUser = "your-username",
BasicAuthPassword = "your-password",
});- Client sends request with
Authorization: Basic <credentials>header - Agent validates credentials against configured username/password
- If invalid, returns 401 with
WWW-Authenticateheader - If valid, processes the request normally
# Azure Functions
func start
# AWS Lambda (local invoke)
dotnet lambda invoke-function MyAgentLambda --payload '{"httpMethod":"GET","path":"/"}'# Test without auth (should return 401)
curl https://your-function-url/
# Test with valid auth
curl -u username:password https://your-function-url/
# Test SWAIG function call
curl -u username:password \
-H "Content-Type: application/json" \
-d '{"call_id": "test", "argument": {"parsed": [{"param": "value"}]}}' \
https://your-function-url/your_function_name- Use connection pooling for database connections
- Implement proper caching strategies
- Minimize cold start times with smaller deployment packages
- Always use HTTPS endpoints
- Implement proper authentication
- Use environment variables for sensitive data
- Consider using cloud-native secret management (Azure Key Vault, AWS Secrets Manager)
- Enable cloud platform logging
- Monitor function execution times
- Set up alerts for errors and timeouts
- Use distributed tracing for complex workflows
- Right-size memory allocation
- Implement proper timeout settings
- Use reserved capacity for predictable workloads
- Monitor and optimize function execution patterns
Environment Detection:
using System;
using SignalWire.Serverless;
// Check detected mode: "lambda", "gcf", "azure", "cgi", or "server"
var mode = Adapter.Detect();
Console.WriteLine($"Detected mode: {mode}");URL Generation:
using System;
using SignalWire.Agent;
var agent = new AgentBase(new AgentOptions { Name = "test" });
Console.WriteLine($"Base URL: {agent.GetFullUrl()}");
Console.WriteLine($"Auth URL: {agent.GetFullUrl(includeAuth: true)}");Authentication Issues:
- Verify username/password are set correctly
- Check that Authorization header is being sent
- Ensure credentials match exactly (case-sensitive)
Enable debug logging:
using Microsoft.Extensions.Logging;
var loggerFactory = LoggerFactory.Create(builder =>
builder.SetMinimumLevel(LogLevel.Debug));- Add cloud function entry point
- Configure environment variables
- Update URL generation logic
- Test authentication flow