Files
agent-framework/dotnet
T
Roger Barreto 705473c276 .NET: Add hosted agent observability sample (#5660)
* .Net: Add hosted agent observability sample

Mirrors the Python sample added in #5608 for Foundry hosted agents. The
.NET hosting library already wires OpenTelemetry automatically via
Microsoft.Agents.AI.Foundry.Hosting (ApplyOpenTelemetry) plus
Azure.AI.AgentServer.Core's AddAgentHostTelemetry, so no framework
changes are needed. The sample is documentation plus a runnable artifact
that produces an interesting span tree (invoke_agent / agent_invoke /
chat / execute_tool).

Adds Hosted-Observability under FoundryHostedAgents/responses with two
small tools (GetCurrentLocation, GetWeather), agent.yaml /
agent.manifest.yaml declaring OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT
(the .NET equivalent of Python's ENABLE_SENSITIVE_DATA), Dockerfile +
Dockerfile.contributor, .env.example and README explaining the .NET vs
Python defaults. Project added to agent-framework-dotnet.slnx.

* Address PR feedback: use Random.Shared and add .dockerignore
705473c276 · 2026-05-06 08:33:16 +00:00
History
..
2026-05-05 09:23:36 +00:00
2026-04-03 11:27:36 +00:00

Get Started with Microsoft Agent Framework for C# Developers

Quickstart

Basic Agent - .NET

using Azure.AI.OpenAI;
using Azure.Identity;
using Microsoft.Agents.AI;
using OpenAI.Responses;

var endpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT")!;
var deploymentName = Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENT_NAME")!;

var agent = new AzureOpenAIClient(new Uri(endpoint), new AzureCliCredential())
    .GetResponsesClient(deploymentName)
    .AsAIAgent(name: "HaikuBot", instructions: "You are an upbeat assistant that writes beautifully.");

Console.WriteLine(await agent.RunAsync("Write a haiku about Microsoft Agent Framework."));

Examples & Samples

Agent Framework Documentation