# IMentorQueryHandler<TQuery, TResult>

> The IMentorQueryHandler<TQuery, TResult> interface of Novior.MentorAgent.Abstractions.Interfaces: Handles a query: a request that only reads, written as a…

- URL: https://docs.mentoragent.net/api/novior-mentoragent-abstractions-interfaces/imentorqueryhandler-2
- Verified with: MentorAgent 1.4.0
- Last updated: 2026-11-18
- Packages: Novior.MentorAgent.Abstractions

Handles a query: a request that only reads, written as a type of its own, usually a record. Registered with `MentorOptions.Actions.AddQuery<TQuery, THandler>()`, the query is one of the coordinator's actions, named after `TQuery` in snake\_case and always read-only: the model gives the query's properties as the action's arguments, MentorAgent passes the query it built from them to [`IMentorQueryHandler<TQuery, TResult>.HandleAsync`](https://docs.mentoragent.net/api/novior-mentoragent-abstractions-interfaces/imentorqueryhandler-2#handleasync), and the model reads the result.

The handler is a service the application registers itself. An application that already sends its queries through a dispatcher, MediatR for example, writes a handler that sends the query on.

## Definition

Namespace: `Novior.MentorAgent.Abstractions.Interfaces`. Package: `Novior.MentorAgent.Abstractions`.

`public interface IMentorQueryHandler<TQuery, TResult>`

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

## Methods

### `HandleAsync`

`Task<TResult?> HandleAsync(TQuery query, CancellationToken cancellationToken)`

Answers `query`. An exception fails the action, and the model reads that it failed.

**Parameters**

- `query`: The query, built from the model's arguments.
- `cancellationToken`: Cancelled when the turn is.

**Returns:** The result the model reads.

---

- Previous: [IMentorPageContext interface](https://docs.mentoragent.net/api/novior-mentoragent-abstractions-interfaces/imentorpagecontext.md)
- Next: [IMentorStateService interface](https://docs.mentoragent.net/api/novior-mentoragent-abstractions-interfaces/imentorstateservice.md)
