Skip to content

Python: .NET: [Bug]: 'No service for type 'Microsoft.Agents.AI.DevUI.DevUIAuthFilter' has been registered #6368

Closed

Description

@samcov

Description

When running the DevUI sample, insead of using OpenAI I use Ollama. All of the code is the same except I get an IChatClient from Ollama.

    IvcAIClient iac = new();
    IChatClient chatClient = iac.GetOllamaChatClient(Endpoint);
    builder.Services.AddChatClient(chatClient);

However, when I reach the line to app.MapDevUI();, it throws the exception, which appears like a DI error. The full error is: System.InvalidOperationException: 'No service for type 'Microsoft.Agents.AI.DevUI.DevUIAuthFilter' has been registered.

Is that type being registered somewhere in the normal example that I didn't see? The full code is shown below.

Code Sample

// Copyright (c) Microsoft. All rights reserved.

// This sample demonstrates basic usage of the DevUI in an ASP.NET Core application with AI agents.

using System.ComponentModel;
//using Azure.AI.OpenAI;
//using Azure.Identity;
using com.ivc.ai.clients;
using Microsoft.Agents.AI;
using Microsoft.Agents.AI.DevUI;
using Microsoft.Agents.AI.Hosting;
using Microsoft.Agents.AI.Workflows;
using Microsoft.Extensions.AI;

namespace DevUI_Step01_BasicUsage;

/// <summary>
/// Sample demonstrating basic usage of the DevUI in an ASP.NET Core application.
/// </summary>
/// <remarks>
/// This sample shows how to:
/// 1. Set up Azure OpenAI as the chat client
/// 2. Create function tools for agents to use
/// 3. Register agents and workflows using the hosting packages with tools
/// 4. Map the DevUI endpoint which automatically configures the middleware
/// 5. Map the dynamic OpenAI Responses API for Python DevUI compatibility
/// 6. Access the DevUI in a web browser
///
/// The DevUI provides an interactive web interface for testing and debugging AI agents.
/// DevUI assets are served from embedded resources within the assembly.
/// Simply call MapDevUI() to set up everything needed.
///
/// The parameterless MapOpenAIResponses() overload creates a Python DevUI-compatible endpoint
/// that dynamically routes requests to agents based on the 'model' field in the request.
/// </remarks>
internal static class Program
{
    /// <summary>
    /// Entry point that starts an ASP.NET Core web server with the DevUI.
    /// </summary>
    /// <param name="args">Command line arguments.</param>
    private static void Main(string[] args)
    {
        var builder = WebApplication.CreateBuilder(args);

        // Set up the Azure OpenAI client
        const string Endpoint = "http://192.168.0.134:11434";// builder.Configuration["AZURE_OPENAI_ENDPOINT"] ?? throw new InvalidOperationException("AZURE_OPENAI_ENDPOINT is not set.");
        //var deploymentName = builder.Configuration["AZURE_OPENAI_DEPLOYMENT_NAME"] ?? "gpt-5.4-mini";

        // WARNING: DefaultAzureCredential is convenient for development but requires careful consideration in production.
        // In production, consider using a specific credential (e.g., ManagedIdentityCredential) to avoid
        // latency issues, unintended credential probing, and potential security risks from fallback mechanisms.
        //var chatClient = new AzureOpenAIClient(new Uri(endpoint), new DefaultAzureCredential())
        //    .GetChatClient(deploymentName)
        //    .AsIChatClient();

        IvcAIClient iac = new();
        IChatClient chatClient = iac.GetOllamaChatClient(Endpoint);
        builder.Services.AddChatClient(chatClient);

        // Define some example tools
        [Description("Get the weather for a given location.")]
        static string GetWeather([Description("The location to get the weather for.")] string location)
            => $"The weather in {location} is cloudy with a high of 15°C.";

        [Description("Calculate the sum of two numbers.")]
        static double Add([Description("The first number.")] double a, [Description("The second number.")] double b)
            => a + b;

        [Description("Get the current time.")]
        static string GetCurrentTime()
            => DateTime.Now.ToString("HH:mm:ss");

        // Register sample agents with tools
        builder.AddAIAgent("assistant", "You are a helpful assistant. Answer questions concisely and accurately.")
            .WithAITools(
                AIFunctionFactory.Create(GetWeather, name: "get_weather"),
                AIFunctionFactory.Create(GetCurrentTime, name: "get_current_time")
            );

        builder.AddAIAgent("poet", "You are a creative poet. Respond to all requests with beautiful poetry.");

        builder.AddAIAgent("coder", "You are an expert programmer. Help users with coding questions and provide code examples.")
            .WithAITool(AIFunctionFactory.Create(Add, name: "add"));

        // Register sample workflows
        var assistantBuilder = builder.AddAIAgent("workflow-assistant", "You are a helpful assistant in a workflow.");
        var reviewerBuilder = builder.AddAIAgent("workflow-reviewer", "You are a reviewer. Review and critique the previous response.");
        builder.AddWorkflow("review-workflow", (sp, key) =>
        {
            var agents = new List<IHostedAgentBuilder>() { assistantBuilder, reviewerBuilder }.Select(ab => sp.GetRequiredKeyedService<AIAgent>(ab.Name));
            return AgentWorkflowBuilder.BuildSequential(workflowName: key, agents: agents);
        }).AddAsAIAgent();

        builder.Services.AddOpenAIResponses();
        builder.Services.AddOpenAIConversations();

        var app = builder.Build();

        app.MapOpenAIResponses();
        app.MapOpenAIConversations();

        if (builder.Environment.IsDevelopment())
        {
            app.MapDevUI();
        }

        Console.WriteLine("DevUI is available at: https://localhost:50516/devui");
        Console.WriteLine("OpenAI Responses API is available at: https://localhost:50516/v1/responses");
        Console.WriteLine("Press Ctrl+C to stop the server.");

        app.Run();
    }
}

Error Messages / Stack Traces

System.InvalidOperationException: 'No service for type 'Microsoft.Agents.AI.DevUI.DevUIAuthFilter' has been registered

Package Versions

Microsoft.Agents.AI.DevUI.dll, Microsoft.Agents.AI.Hosting.OpenAI.dll

.NET Version

.Net 10

Additional Context

No response

Activity

  1. added
    bugUsage: [Issues], Target: all issues (Legacy, prefer issue type: bug)
    .NETUsage: [Issues, PRs], Target: .Net
    on Jun 6, 2026
  2. added
    pythonUsage: [Issues, PRs], Target: Python
    triageUsage: [Issues], Target: All issues that still need to be triaged
    on Jun 6, 2026
  3. changed the title [-].NET: [Bug]: 'No service for type 'Microsoft.Agents.AI.DevUI.DevUIAuthFilter' has been registered[/-] [+]Python: .NET: [Bug]: 'No service for type 'Microsoft.Agents.AI.DevUI.DevUIAuthFilter' has been registered[/+] on Jun 6, 2026
  4. added
    reproducedUsage: [Issues], Target: all issues that can be reproduced by the triage workflow
    on Jun 6, 2026
  5. github-actions commented on Jun 6, 2026

    @github-actions
    Contributor

    🤖 Automated triage reproduction notes (agent-authored — trust but verify)

    Agent analysis

    Repro: DevUIExtensions.MapDevUI() in dotnet/src/Microsoft.Agents.AI.DevUI/DevUIExtensions.cs (line 43) calls GetRequiredService() which throws when AddDevUI() has not been called. The official sample at dotnet/samples/02-agents/DevUI/DevUI_Step01_BasicUsage/Program.cs also lacks AddDevUI(). Minimal repro: build a WebApplication without calling builder.Services.AddDevUI() then call app.MapDevUI() — it throws InvalidOperationException. Fix should either auto-register services inside MapDevUI or update sample/docs to require explicit AddDevUI().

    • Failing test: dotnet/tests/Microsoft.Agents.AI.DevUI.UnitTests/DevUIMapWithoutAddDevUI_ReproTest.cs
    • Files examined: dotnet/src/Microsoft.Agents.AI.DevUI/DevUIExtensions.cs, dotnet/src/Microsoft.Agents.AI.DevUI/ServiceCollectionsExtensions.cs, dotnet/src/Microsoft.Agents.AI.DevUI/DevUIAuthFilter.cs, dotnet/src/Microsoft.Agents.AI.DevUI/HostApplicationBuilderExtensions.cs, dotnet/samples/02-agents/DevUI/DevUI_Step01_BasicUsage/Program.cs, dotnet/tests/Microsoft.Agents.AI.DevUI.UnitTests/DevUIIntegrationTests.cs
    • Tests run: dotnet/tests/Microsoft.Agents.AI.DevUI.UnitTests/DevUIMapWithoutAddDevUI_ReproTest.cs
    • Current version: 1.9.0-preview
  6. samcov commented on Jun 6, 2026

    @samcov
    Author

    I can confirm that adding the following line solves the problem.

        // Add DevUI services
        builder.AddDevUI();
    

    DevUI shows up properly! It's up to you guys to decide if it should be folded into app.MapDevUI().

    Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    .NETUsage: [Issues, PRs], Target: .NetbugUsage: [Issues], Target: all issues (Legacy, prefer issue type: bug)pythonUsage: [Issues, PRs], Target: PythonreproducedUsage: [Issues], Target: all issues that can be reproduced by the triage workflowtriageUsage: [Issues], Target: All issues that still need to be triaged

    Type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions