# Quickstart

> Create a Blazor app, turn a service method into an action with confirmation, connect a model and add the chat widget in about fifteen minutes.

- URL: https://docs.mentoragent.net/get-started/quickstart
- Verified with: MentorAgent 1.0.0
- Last updated: 2026-10-14
- Duration: 15 min
- Packages: Novior.MentorAgent

In this quickstart you build **Cases**, a small Blazor Server app for support cases. Its agent reads the status of a case whenever it needs to, and adds a note to a case only after you confirm.

This quickstart uses Blazor, because the chat widget is ready-made for Blazor. With a React, Angular or Vue front end, or a mobile app, the service and its registration stay the same. You add `Novior.MentorAgent.Server` to the backend and build the chat UI yourself, as in [Any front end](https://docs.mentoragent.net/configure/any-front-end).

**What you need:**

- the .NET 10 SDK;
- an OpenAI API key.

[Prerequisites](https://docs.mentoragent.net/get-started/prerequisites) lists the versions that MentorAgent is tested with. You can also download the finished project as a [zip file](https://mentoragent.net/downloads/mentoragent-quickstart.zip). It is under the MIT license.

## Create the app

Create a Blazor Web App with Server interactivity:

```shell
dotnet new blazor -n Cases --interactivity Server --all-interactive
cd Cases
```

`--all-interactive` makes every page interactive. The widget needs it: on a page rendered statically, its button shows up but clicking it does nothing.

## Add the packages

Add MentorAgent:

**.NET CLI**

```shell
dotnet add package Novior.MentorAgent
```

**PackageReference**

```xml title="YourApp.csproj"
<ItemGroup>
  <PackageReference Include="Novior.MentorAgent" Version="1.0.0" />
</ItemGroup>
```

**Central Package Management**

```xml title="Directory.Packages.props"
<ItemGroup>
  <PackageVersion Include="Novior.MentorAgent" Version="1.0.0" />
</ItemGroup>
```

```xml title="YourApp.csproj"
<ItemGroup>
  <PackageReference Include="Novior.MentorAgent" />
</ItemGroup>
```

**File-based app**

```csharp title="app.cs"
#:package Novior.MentorAgent@1.0.0
```

MentorAgent does not include a model provider package. This quickstart uses OpenAI, so add the OpenAI client for `Microsoft.Extensions.AI`:

```shell
dotnet add package Microsoft.Extensions.AI.OpenAI --version 10.6.0
```

The package also installs `OpenAI`. The `--version` in the command is the version that the quickstart project was tested with.

## Describe what the agent can do

Create `CaseService.cs` in the project folder:

```csharp title="CaseService.cs"
using Novior.MentorAgent.Attributes;

public class CaseService
{
    [MentorAction(
        Description = "Returns the status of a case",
        ReadOnly = true)]
    public string GetCaseStatus(string caseNumber)
        => $"Case {caseNumber} is under review.";

    [MentorAction(Description = "Adds a note to a case")]
    public string AddNote(string caseNumber, string text)
        => $"Note added to case {caseNumber}.";
}
```

The `[MentorAction]` attribute marks a method as an action. The model sees each action as a tool: a function that it can ask MentorAgent to run. The tool is named after the method, in snake case (lowercase words joined by underscores): `GetCaseStatus` becomes `get_case_status`, and `AddNote` becomes `add_note`.

- `GetCaseStatus` only reads, so it declares `ReadOnly = true`. The agent calls it without asking anyone.
- `AddNote` changes data. A `[MentorAction]` that is not read-only asks for confirmation by default, so the agent shows a confirmation box before it adds the note.

## Register the service and the model

At the top of `Program.cs`, add the `using` directives:

```csharp title="Program.cs"
using Novior.MentorAgent.Extensions;
using Microsoft.Extensions.AI;
using OpenAI;
```

Then, after `var builder = WebApplication.CreateBuilder(args);`, register the service and MentorAgent:

```csharp title="Program.cs"
builder.Services.AddScoped<CaseService>();
builder.Services.AddMentorAgent(options =>
{
    options.AppName = "Case management";
    options.ChatClient = new OpenAIClient(
            builder.Configuration["OpenAI:Key"] ?? throw new InvalidOperationException(
                "OpenAI:Key is missing: run dotnet user-secrets set OpenAI:Key <your-key>"))
        .GetChatClient("gpt-4o-mini")
        .AsIChatClient();
    options.ScanAssemblies = [typeof(Program).Assembly];
});
```

- `AddScoped<CaseService>()` registers your service as usual. MentorAgent finds its methods in the assemblies listed in `ScanAssemblies`, and gets the instance from dependency injection.
- `AppName`, `ScanAssemblies` and a model are required. Here you set the model with `ChatClient`. If you have your own Agent Framework agent, set `Agent` instead.
- `gpt-4o-mini` is the model. Any model that supports tool calling works.

Keep the key out of the code, in the project's user secrets. Replace `<your-key>` with your OpenAI API key in the second command:

```shell
dotnet user-secrets init
dotnet user-secrets set OpenAI:Key <your-key>
```

To use Azure OpenAI or a local model with Ollama, change the lines that set `ChatClient`. [Model providers](https://docs.mentoragent.net/configure/model-providers) lists the packages and the `using` directives that you need. It also covers the providers that need an `Agent` instead.

## Add the widget

Add the widget's namespace to `Components/_Imports.razor`:

```razor title="Components/_Imports.razor"
@using Novior.MentorAgent.Abstractions.Components
```

Then put the widget at the end of `Components/Layout/MainLayout.razor`:

```razor title="Components/Layout/MainLayout.razor"
<ChatWidget />
```

The widget loads its own styles and scripts, so `App.razor` stays as it is.

## Try it

Run the app:

```shell
dotnet run
```

Open the address shown in the terminal and click the widget button in the corner of the page.

1. Type "What is the status of case C-1?". The agent calls `get_case_status` and answers with what your method returned.
2. Type "Add a note to case C-1: documents received". The agent calls `add_note`, and a confirmation box appears in the widget. It shows the action and its arguments, with labels made from the parameter names: `caseNumber` becomes "Case Number".
3. Click **Confirm**. `AddNote` runs and returns its message.

If you click **Cancel** instead, the method does not run, and the model is told that you declined. `AddNote` keeps nothing: the [tutorial](https://docs.mentoragent.net/get-started/tutorial/actions) adds a store that keeps the notes.

If something does not work, [Troubleshooting](https://docs.mentoragent.net/get-started/troubleshooting) starts from what you see.

## See the tool calls in the log

While an action runs, the widget shows its description, not the name of the tool. To see which tool the agent calls while you develop, set the log level of the `Novior.MentorAgent` category to `Debug` in `appsettings.Development.json`:

```json
{
  "Logging": {
    "LogLevel": {
      "Novior.MentorAgent": "Debug"
    }
  }
}
```

The terminal then shows a line such as `[MentorAgent] Tool call: get_case_status` for every call. Keep the other entries of the `LogLevel` section that the file already has.

## Next steps

- Build a fuller case-management agent, step by step, in the tutorial, starting with [1 · Turn service methods into actions](https://docs.mentoragent.net/get-started/tutorial/actions).
- Add MentorAgent to a project you already have: [Add MentorAgent to an existing app](https://docs.mentoragent.net/get-started/existing-app), or, with a React, Angular, Vue or mobile front end, [Any front end](https://docs.mentoragent.net/configure/any-front-end).
- Configure it for your host and provider: [Blazor Server app](https://docs.mentoragent.net/configure/blazor-server), [Model providers](https://docs.mentoragent.net/configure/model-providers), and the [Production checklist](https://docs.mentoragent.net/configure/production) before you go to production.
- Read how roles and confirmation protect your actions: [Roles, confirmation and governance](https://docs.mentoragent.net/concepts/governance).
- Look up an unfamiliar term in the [Glossary](https://docs.mentoragent.net/reference/glossary).

---

- Previous: [What's new](https://docs.mentoragent.net/whats-new.md)
- Next: [1 · Turn service methods into actions](https://docs.mentoragent.net/get-started/tutorial/actions.md)
