Skip to content

Quickstart: a simple AI agent built with the GitHub Copilot SDK, running as an Azure Function.

Notifications You must be signed in to change notification settings

Azure-Samples/simple-agent-functions-dotnet

Repository files navigation

Simple Agent QuickStart (.NET Copilot SDK)

A simple AI agent built with the GitHub Copilot SDK, running as an Azure Function.

Prerequisites

Quickstart

  1. Clone the repository

  2. Run the function locally:

    cd agent
    func start
  3. Test the agent (in a new terminal):

    # Interactive chat client
    cd chat
    dotnet run
    
    # Or use curl directly
    curl -X POST http://localhost:7071/api/ask -d "what are the laws"

    Set AGENT_URL and FUNCTION_KEY to point to a deployed instance:

    export AGENT_URL=$(azd env get-value SERVICE_API_URI)
    export FUNCTION_KEY=$(az functionapp keys list \
      -n $(azd env get-value AZURE_FUNCTION_APP_NAME) \
      -g $(azd env get-value RESOURCE_GROUP) \
      --query "functionKeys.default" -o tsv)
    dotnet run

Want to use Microsoft Foundry models instead? See Deploy Microsoft Foundry Resources below.

Source Code

The agent logic is in agent/Ask.cs. It creates a CopilotClient, configures a session with a system message (Asimov's Three Laws of Robotics), and exposes an HTTP endpoint (/api/ask) that accepts a prompt and returns the agent's response.

chat/Chat.cs is a lightweight .NET console client that POSTs messages to the function in a loop, giving you an interactive chat experience. It defaults to http://localhost:7071 but can be pointed at a deployed instance via the AGENT_URL environment variable.

Deploy Microsoft Foundry Resources

If you're using BYOK and don't already have a Microsoft Foundry project with a model deployed:

azd auth login
azd up

This provisions all resources and configures local development automatically.

What Gets Deployed

  • Microsoft Foundry project with GPT-5-mini model
  • Azure Functions app (.NET 10, Flex Consumption plan)
  • Storage, monitoring, and all necessary RBAC role assignments
  • Optional: Search for vector store (disabled by default)
  • Optional: Cosmos DB for agent thread storage (disabled by default)

Using Microsoft Foundry (BYOK)

By default the agent uses GitHub Copilot's models. To use your own model from Microsoft Foundry instead, set these environment variables:

export AZURE_OPENAI_ENDPOINT="https://<your-ai-services>.openai.azure.com/"
export AZURE_OPENAI_API_KEY="<your-api-key>"
export AZURE_OPENAI_MODEL="gpt-5-mini"  # optional, defaults to gpt-5-mini

Getting these values:

  • If you ran azd up, the endpoint is already in your environment — run azd env get-values | grep AZURE_OPENAI_ENDPOINT
  • For the API key, go to Azure Portal → your AI Services resource → Keys and Endpoint → select the Azure OpenAI tab
  • Or find both in the Microsoft Foundry portal under your project settings

See the BYOK docs for details.

Learn More

About

Quickstart: a simple AI agent built with the GitHub Copilot SDK, running as an Azure Function.

Resources

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors