One checked path for every model answer.

Any .NET value and an intent go to the model you choose, unless the cache already holds the answer or the call stops first on a setup mistake. The answer is checked by code and by your rules before your code sees it, a failed check goes back to the model with the findings, and limits you set stop a call that runs too long. Each stage below is named after the term you meet in the API, with code that compiles against the library on every build of this site.

What lives in files

Most of what decides a call is data that a person, a coding agent or your application can read and change, not code that needs a release.

FileWhat it holds, and who reads it
Intent filesThe goal, the data model (a shape, in the file format), the rules, the examples and the budget; read by the runtime, and by agents as tools.
Rule filesAllow, deny, pattern, range, count and schema rules per checkpoint, enforced or detect-only; read at every checkpoint.
The settings documentThe limits and behaviors a file may set; security items fail closed.
The provider fileEntries, chains, aliases, secret references and the bounds on where keys go: each entry's endpoint, the address its key is sent to, and whether plain http is allowed.
Compiled mappingsStored steps keyed by the input and output data models; they run without a model call.
Documents and versionsEvery file above is a document with versions, a ledger and revert.

The pipeline

From your value to a checked result.

A call on a value or a collection, a method marked [AIIntent], a command planned for a target, an intent from a file and an agent tool built from one all get the same checks, retries and limits.

Click a box in the drawing, or pick a stage.

The path of one checked call Your value (text, a record, a list, a DataTable or JSON) and an intent go to the model, unless the cache already holds an answer for the same request. A switched-off, unknown or mismatched intent stops with an exception before any model call. Every answer, cached or fresh, is checked in code. A failed check goes back to the model with the findings, within MaxAttempts, MaxModelCalls and Timeout; when the answer passes, or the attempts run out, the call returns an AIResult with Success, Value, Issues and Attempts. Your value text, a record, a list, a DataTable or JSON Intent wording, shape and rules, in code or in a file Model OpenAI, Anthropic or any IChatClient; fallback if transient Checks refusal, truncation, JSON, members, nulls and your rules AIResult<T> Success, Value, Issues, Attempts passed failed a check: retry with the findings,within MaxAttempts, MaxModelCalls and Timeout out of attempts: Success = false, with the issues cache hit: no call for the answer, still checked switched off, unknownor wrong shape: throwsbefore any model call
The drawing: the path of one checked call
The path of one checked call Your value (text, a record, a list, a DataTable or JSON) and an intent go to the model, unless the cache already holds an answer for the same request. A switched-off, unknown or mismatched intent stops with an exception before any model call. Every answer, cached or fresh, is checked in code. A failed check goes back to the model with the findings, within MaxAttempts, MaxModelCalls and Timeout; when the answer passes, or the attempts run out, the call returns an AIResult with Success, Value, Issues and Attempts. Your value text, a record, a list, a DataTable or JSON Intent wording, shape and rules, in code or in a file Model OpenAI, Anthropic or any IChatClient, with fallback Checks refusal, truncation, JSON, members, nulls, your rules AIResult<T> Success, Value, Issues, Attempts switched off, unknown or wrong shape: throws, no model call cache hit: no call for the answer, still checked failed a check: retry with the findings, within MaxAttempts, MaxModelCalls and Timeout passed out of attempts: Success = false, with the issues

The value: what you send.

The input is any .NET object: text, a record, a list, a DataTable or JSON. GenerateAsync<T> runs an intent with no input.

Input longer than MaxInputChars (200,000 characters by default) is refused with an exception before any model call, never cut. A collection goes in one request, so the same limit caps its size. Text only: no images, files or chat history.

Read more: a collection, and each operation's check

A string in, your own type out
var email = "Invoice INV-2291 from Contoso Supplies: 40 replacement belts at 31.00 each. Amount due: 1,240.00 US$ by 2026-11-01.";
var invoice = await email.AIAsync<Invoice>(client, "Extract the vendor, invoice number, currency and total from this invoice email.");
Output
Success: trueValue: Invoice { Vendor = Contoso Supplies, InvoiceNumber = INV-2291, Currency = USD, Total = 1240.00 }Issues: none

The intent: what you want done.

A plain-language instruction applied to a value. Inline, it needs no file: AIRequestOptions adds system instructions, an output requirement, worked examples, the model and the provider for that call. Or give it a name and keep the same settings, with its shape and rules, in a YAML or JSON file that reloads when it changes.

An intent can also sit on a method: mark it with [AIIntent("...")], add [AIConstraint] settings (MaxAttempts, MaxExecutionTimeMs, MaxModelCalls, RequireJudge, OutputRequirement or CustomValidator), and run it with client.ExecuteIntentAsync<T>(method, input). Settings on the class are the defaults, a setting on the method overrides them, and the method body never runs. A method has no setting for examples, the output-token limit, the provider, the model, DoNotRecord or tags.

Two ways to state an intent
// In code: the intent is the instruction, applied to any value.
var order = await email.AIAsync<PurchaseRequest>(client, "Extract the purchase request from this email.");

// In a file: the code names the intent; Orders.ClassifyUrgency.intent.yaml holds its wording, shape and rules.
var urgency = await email.RunIntentAsync<int>(intents, "Orders.ClassifyUrgency");
An intent on a method
[AIIntent("Write a one-sentence reply that confirms this purchase request to the customer.",
    ExpectedOutput = "One sentence that names the quantity, the SKU and the delivery date.")]
[AIConstraint(ConstraintKind.MaxAttempts, 2)]
[AIConstraint(ConstraintKind.MaxExecutionTimeMs, 15_000)]
public static string ConfirmOrder(PurchaseRequest order)
    => throw new NotImplementedException("The attributes define this method; its body never runs.");

public static Task<AIResult<string>> ConfirmOrderAsync(IntentClient client, PurchaseRequest order)
    => client.ExecuteIntentAsync<string>(typeof(OrderReplies).GetMethod(nameof(ConfirmOrder))!, order);
Output
Intent (from [AIIntent]): Write a one-sentence reply that confirms this purchase request to the customer.Model calls: 1Success: trueValue: Thanks, Dana: 40 units of A-1192 will reach you by 2026-11-15.Issues: none

The shape: what comes back.

Ask for a .NET type, such as an int, an enum, a record with nested lists or a List<T>, and the answer comes back as that type, checked, or the call fails. A required member missing from the answer is reported, not filled with a default; enums are read by name, and a null passes only where your type allows one. Ranges, lengths and patterns belong in your rules.

A shape can also be a JSON schema chosen at run time, from config or a database, and the value then comes back as JSON. IntentSharp checks only that it is JSON and not null; your validators or an intent file's schema shape check the rest.

A type, or a schema at run time
// A .NET type: the model is sent a strict schema built from PurchaseRequest, and the reply must parse into it.
// A required member missing from the reply is an issue, not a default value.
AIResult<PurchaseRequest> order = await email.AIAsync<PurchaseRequest>(client, "Extract the purchase request from this email.");

// A shape defined at run time: a JSON schema, and the value comes back as JSON.
var schema = JsonNode.Parse("""{"type": "object", "properties": {"sku": {"type": "string"}, "quantity": {"type": "integer"}}}""")!;
AIResult<JsonNode> line = await client.TransformAsync(email, "Extract the SKU and the quantity.", schema);

The model: yours to choose.

OpenAI and Anthropic, any Microsoft.Extensions.AI IChatClient, or your own IAIProvider, named in a provider file that also says where each key is read from. The next provider of a chain answers when a rule or setting refuses the first, or after a transient error: a 408, a 429, a 5xx, a transport error, an unreadable reply, a model the provider does not serve or the provider's timeout. Other errors, and answers that fail a check, never fall back.

A request or an intent file can name its model and its provider; naming the provider turns fallback off for it, and the default judge, if on, still asks the provider of the judge role. A named model goes to the first provider only; a fallback asks for its own model. WithRateLimiter keeps each provider under a request rate in this process.

Fewer tokens with the request cache

With WithCache(new InMemoryRequestCache()), an identical request to the same provider is answered from the cache in your process, with no model call for the answer, and still checked against the current rules; a judge, when on, still makes its own call. Memory, cache and rate limiting has the controls.

Providers
// The provider file names the providers, their models and where each key is read from. Its answer role is a
// chain: the next provider is called only on a transient error (a 408, a 429, a 5xx, a transport error, an
// unreadable reply, a model the provider does not serve or the provider's HTTP timeout).
using var store = new FolderDocumentStore("config");   // holds intentsharp.providers.json
using var client = new IntentClientBuilder()
    .UseProviderOptions(store)
    .Build();

// Or any Microsoft.Extensions.AI IChatClient.
using var onChatClient = new IntentClientBuilder().UseChatClient(chatClient).Build();
One fallback, for transient errors
using var client = new IntentClientBuilder()
    .UseProvider(primary)
    .UseFallbackProvider(fallback)   // only on a transient error: 408, 429, 5xx, transport, unreadable reply, 404, timeout
    .Build();

var urgency = await email.AIAsync<int>(client, "Rate the urgency of this order email from 1 (routine) to 5 (critical).");
Output
Primary (scripted): threw AIProviderException "Service unavailable (503).", IsTransient = true, on 1 callSuccess: trueValue: 4Issues: noneProvider: FallbackAttempts: 1, answered by Fallback
The request cache
using var client = new IntentClientBuilder()
    .UseProvider(provider)
    .WithCache(new InMemoryRequestCache())
    .Build();

var intent = "Rate the urgency of this order email from 1 (routine) to 5 (critical).";
var first = await email.AIAsync<int>(client, intent);   // calls the model
var again = await email.AIAsync<int>(client, intent);   // the same request: answered from the cache, no model call

// A different request has a different key and calls the model: a new wording, or a new result shape (text).
var reworded = await email.AIAsync<int>(client, intent + " A stopped production line is critical.");
var asText = await email.AIAsync(client, intent);
Output
first: Success: true, Value: 4, FromCache: falseagain: Success: true, Value: 4, FromCache: true, Usage: 0 input tokens, 0 output tokensreworded: Success: true, Value: 5, FromCache: falseasText: Success: true, Value: 4, FromCache: falseModel calls (ScriptedProvider.CallCount): 3 for 4 requests; "again" made none.

The checks: what a good answer looks like.

Every answer is checked without calling a model: a refusal, a cut-off reply, a reply that does not fit the type, missing members, nulls and enum names. Then your rules run: limits in the intent file (minimum, maximum, allowed values, patterns), or Require<T> and Validate<T> on the typed value in code.

A broken rule becomes a finding with the exact path and value, such as value.currency is "US$"; allowed: USD, EUR, GBP. A check that throws becomes a finding too, and its message goes to the model, like every finding.

A pass means these checks passed. Checks narrow the answers; they cannot prove an answer right.

Checks in code
// Your own checks on the typed value. A failed check is an issue, and the next attempt sends it to the model.
var options = new AIRequestOptions()
    .Require<PurchaseRequest>(r => r.Quantity > 0, "Quantity must be a positive number.")
    .Validate<PurchaseRequest>(r => r.DeliverBy < DateOnly.FromDateTime(DateTime.Today)
        ? [$"DeliverBy is {r.DeliverBy:yyyy-MM-dd}, which is in the past."]
        : []);
var order = await email.AIAsync<PurchaseRequest>(client, "Extract the purchase request from this email.", options);
Invoice.Extract.intent.yaml (rules)Intent file
rules:
  properties:
    currency:
      enum: [USD, EUR, GBP]
    total:
      minimum: 0

Attempts: retry with the findings.

When a check fails, the next attempt sends the previous answer (up to 6,000 characters) and the findings back to the model. A refusal is not retried.

Four things are capped, on the client or per call: attempts, model calls (judge calls included, cache hits not), output tokens per call and the time for the whole request. By default: 2 attempts, 6 model calls, 4,096 output tokens and 5 minutes for the whole request. A reached limit ends the call with Success = false and an issue that names it. The limits count calls, tokens and time, not money.

An optional judge, a second model call on the provider of the judge role, can review an answer that passed the checks, when JudgeMode allows (Never, OnRequest, the default, or Always); its objections drive the next attempt. A judge that refuses to review fails the attempt. A judge reply that cannot be read as a verdict accepts the answer and logs a Warning under the default JudgeStrictness, and a judge call that fails ends the call with Success = false. What is checked has the rest.

Limits and the attempt log
// Every attempt after the first sends the previous answer and the findings back to the model.
var options = new AIRequestOptions { MaxAttempts = 3, MaxModelCalls = 4, Timeout = TimeSpan.FromSeconds(30) };
var order = await email.AIAsync<PurchaseRequest>(client, "Extract the purchase request from this email.", options);
foreach (var attempt in order.Attempts)
    Console.WriteLine($"Attempt {attempt.Number}: {(attempt.Passed ? "passed" : string.Join(" ", attempt.Issues.Select(i => i.Message)))}");
Invoice example: the finding, then the corrected answer
[Validator] attempt 1: value.currency is "US$"; allowed: USD, EUR, GBP.Success: true, after 2 attemptsValue: {"vendor":"Contoso Supplies","invoiceNumber":"INV-2291","currency":"USD","total":1240.00}
A ceiling on model calls
var options = new AIRequestOptions { MaxAttempts = 5, MaxModelCalls = 3, Timeout = TimeSpan.FromSeconds(10) }
    .Require<PurchaseRequest>(r => r.Quantity > 0, "Quantity must be a positive number.");

var order = await email.AIAsync<PurchaseRequest>(client, "Extract the purchase request from this email.", options);
Output
Success: false, after 3 attemptsIssues:  [Validator] attempt 1: Quantity must be a positive number.  [Validator] attempt 2: Quantity must be a positive number.  [Validator] attempt 3: Quantity must be a positive number.  [Constraint] attempt 4: Model call ceiling of 3 reached before a verified result was produced.Model calls (ScriptedProvider.CallCount): 3 of the 5 answers queued

The result: what was checked, not a confidence score.

AIResult<T> carries Success, the Value, every issue (where it was found, on which attempt, what is wrong) and every attempt. A refusal, a bad answer, a provider error or a reached limit becomes an issue, not an exception, and a failure is never hidden behind a default value. Each call starts an Activity named IntentSharp.Transform for your tracing.

Reading the result
if (order.Success)
    Console.WriteLine($"{order.Value!.Quantity} x {order.Value.Sku} for {order.Value.Contact}");
else
    foreach (var issue in order.Issues)
        Console.WriteLine(issue);   // where it was found, on which attempt, and what is wrong
MemberMeaning
SuccessTrue when the value passed every check and the judge, if it ran, did not reject it.
ValueThe checked value on success; the type's default otherwise.
IssuesEach problem found, with its source, its attempt and its message.
AttemptsOne record per attempt: provider, model, tokens, time, the reply and its issues.
FromCacheTrue when the answer came from the cache. A judge, if on, still makes one call.
GetValueOrThrow()The value, or an IntentSharpException that lists every issue.

What you get back has the token counts, and AIResult<T> in the API reference has every member.

A collection: each operation has its own check.

Filter, sort and group hand back your own objects. On success the original objects come back, selected or ordered by the model: a filter's matches once each, and every element exactly once for sort and group.

Your tickets, sorted
List<Ticket> tickets = OpenTickets();var sorted = await tickets.AISortAsync(client, "most urgent first");
Output
Success: trueValue, in the new order:  101 Login page returns 500 after password reset (Critical)  103 Export to CSV drops the last row (High)  104 Let admins invite users in bulk (Medium)  102 Add dark mode (Low)Every sorted Ticket is the object from tickets, not a copy: trueIssues: none
OperationIts check
AISortAsyncReturns every object exactly once, in the new order.
AIFilterAsyncReturns the matching objects in their original order.
AIGroupAsyncPlaces each object in exactly one group.
AIMapAsyncReturns one output per input, with the count checked.
AIMapValuesAsyncKeeps your dictionary keys, and fails on a missing, extra or repeated key.
AIReduceAsyncReturns one typed answer about the whole list.
AIClassifyAsyncReturns a value of your enum, read by name, never a number.
AIConvertAsyncConverts a value to your type, with no instruction to write.

Where the rules and data models live

Rules move out of the code. Most steps call no model.

The business rules of a call live in an intent file, as data, and your code keeps what needs code: the types, the call by name, the named code checks and what to do with the result. The runtime joins the two on every call, and one step on that path calls a model; the optional judge is one more.

Click a box, or pick a step.

Where the rules live on one call Two lanes and the path between them. In your code, where a change needs a release: the call by name with RunAsync, your result types registered with IntentTypeRegistry, your named code checks, and the AIResult your code receives. In the intent file, as data that a save changes: the name, version, owner and enabled flag; the instruction in plain words, the examples and the shape; the model, provider, attempts and timeout; and the rules with the names of the code checks to run. The runtime joins them. It resolves the file, and an unknown intent, enabled: false or a wrong shape stops with an exception before any model call. It builds the request. With a cache set by WithCache, an identical request is a cache hit: it makes no call for the answer, and the answer is still checked. Otherwise the model is called, and a retry is one more call. The answer is checked against its type, the file's rules and your code checks with no model call. A judge, if on, is one more model call after the checks, on a cached answer too. The result goes back to your code, passed or not. A saved file reloads with no build, and a bad save keeps the last good version. In your code: a change needs a release The runtime, in your process In the intent file, as data: a save changes it, no release Call by name RunAsync<T> with the intent's name and your value Your types result types, registered with IntentTypeRegistry Code checks C# validators, registered in code, named in the file AIResult<T> Success, Value, Issues, Attempts, back to your code Resolve finds the file by name; checks shape and enabled no model call Build request wording, examples, schema and limits, as a call in code no model call Model call on a cache miss; a retry is one more call calls the model Checks type and JSON, the file's rules, then your code checks no model call a judge is one call Identity name, version, owner, enabled Instruction the intent in plain words, examples, system text, shape Model choice model, provider, attempts, timeout, judge on or off Rules as data 13 kinds of limit; names of code checks to run On save reloads, no build; a bad save keeps the last good one An exception, no model call, for an unknown intent, enabled: false or a wrong shape with WithCache, a hit: no call for the answer, still checked passed, or out of attempts, with the issues
The drawing: where the rules live on one call
Where the rules live on one call Two lanes and the path between them. In your code, where a change needs a release: the call by name with RunAsync, your result types registered with IntentTypeRegistry, your named code checks, and the AIResult your code receives. In the intent file, as data that a save changes: the name, version, owner and enabled flag; the instruction in plain words, the examples and the shape; the model, provider, attempts and timeout; and the rules with the names of the code checks to run. The runtime joins them. It resolves the file, and an unknown intent, enabled: false or a wrong shape stops with an exception before any model call. It builds the request. With a cache set by WithCache, an identical request is a cache hit: it makes no call for the answer, and the answer is still checked. Otherwise the model is called, and a retry is one more call. The answer is checked against its type, the file's rules and your code checks with no model call. A judge, if on, is one more model call after the checks, on a cached answer too. The result goes back to your code, passed or not. A saved file reloads with no build, and a bad save keeps the last good version. In the file: a save changes it. In your code: a change needs a release. The runtime joins them, in your process. In the file name, version, owner, enabled In your code RunAsync<T> by name Resolve finds the file by name; an unknown, disabled or wrong shape stops here. no model call In the file wording, examples, the shape In your code result types, registered Build the request wording, examples, schema, limits, as a call in code a hit: no call for the answer no model call In the file model and provider, attempts and timeout Model call on a cache miss; a retry is one more call In the file rules as data, check names In your code the named code checks Checks type and JSON, the file's rules, then your code checks no model call a judge, if on, is one call passed, or out of attempts In your code AIResult<T> Success, Value, Issues In the file On save reloads with no build; a bad save keeps the last good one

Call by name: your code names the intent.

Lane
Your code
Model call
None at this step
A change needs
A release

Your code names the intent and passes the value, with RunAsync<T> on the runtime or value.RunIntentAsync<T>; it names nothing else about the intent. The file decides the wording, the shape, the rules and which registered code checks apply.

Code that calls a new intent by name needs a release.

The call, still in your code
var priority = await email.RunIntentAsync<string>(intents, "Orders.ClassifyPriority");

Read more: the intent

Your types: result types registered in code.

Lane
Your code
Model call
None
A change needs
A release

The type you ask for in RunAsync<T> must fit the shape the file declares, or the call stops before any model call.

A file can name one of your own .NET types as its shape, but only a type your application registered by name with IntentTypeRegistry; a file cannot name an arbitrary type. The model is asked for a registered type exactly as in a call made in code. Type names are checked only when an intent runs, and a new .NET result type needs a release, since it is registered in code.

Read more: the shape

Code checks: C# validators, named in the file.

Lane
Your code
Model call
None
A change needs
A release

For checks that rules cannot express, such as a vendor that must exist in a database or a total that must match the line items, your application registers a C# validator under a name. A file switches it on by listing that name under validators; the file cannot carry code.

Named checks run in code, after the file's rules, on every answer that reads as the result type. Their messages, and the message of a check that throws, go to the model on the next attempt, so keep secrets and personal data out of them. The names are checked only when an intent runs, and a new named code check needs a release.

Read more: the checks

AIResult<T>: the result, back to your code.

Lane
Your code
Model call
None
A change needs
A release

The result goes back to your code, passed or not: Success, the Value, every issue and every attempt. Everything the model gets wrong is an issue in an ordinary AIResult<T>, with every attempt recorded. The runtime's own exceptions are setup mistakes, thrown before any model call.

The returned result does not carry the intent's tags. When the run is recorded in the operation log, its entry carries them, and the one log line written per run names the intent and its version.

Read more: the result

Resolve: find the file by name.

Lane
The runtime
Model call
None
A change needs
A save for the name, enabled flag or shape; a release for the type you ask for

Every call uses the intent's current definition, so the next call after a save uses the new version, and a call already running finishes on the one it started with.

An unknown intent, a switched-off one or a wrong shape throws before any model call: IntentNotFoundException, IntentDisabledException or IntentShapeMismatchException.

Read more: what does not call the model

Build request: the same call as a request in code.

Lane
The runtime
Model call
None
A change needs
A save for what the file sets; a change to the client for the rest

A call from a file gets the same checks, retries and limits as a call made in code.

The run is tagged with the intent's name, version and source file. Input longer than the client's MaxInputChars is refused before any model call, never cut.

Read more: the value

Model call: the one step that calls a model.

Lane
The runtime
Model call
Yes, unless the cache answers
A change needs
A save for what the file sets; a change to the client for the rest

The one step on the path that calls a model: the provider and the model the file names, or else the first provider of the client's answer role and its model. With WithCache, an identical request is answered from the cache with no model call for the answer.

A retry is one more call, within the attempts, model calls and time you set. A fallback provider is used after a transient error or when a rule or setting refuses the first, and naming a provider in the file turns fallback off for that intent.

Read more: the model

Checks: the answer against its type and your rules.

Lane
The runtime
Model call
None; a judge is one
A change needs
A save for the rules; a release for a new code check

The answer is checked against its type, the file's full schema for a schema shape, the file's rules and your code checks, with no model call. A cached answer is checked against the current rules too.

A broken rule becomes a finding with the exact path and value, and the next attempt sends it to the model. Only the optional judge calls a model.

A finding from the invoice file's currency rule
[Validator] attempt 1: value.currency is "US$"; allowed: USD, EUR, GBP.

Read more: the checks

Identity: what the code calls, and who owns it.

Lane
The intent file
Model call
None, it is data
A change needs
A save, no release

name is what the code calls, unique in the catalog. Raise version with every change, so the audit trail can tell versions apart; each run is tagged with the intent's name, version and source file. owner says who answers for the intent, for audit and listings.

enabled: false switches the intent off: it still loads, and a call throws IntentDisabledException before any model call. AIRequestOptions, which a call made in code uses, has nothing for these fields.

Orders.ClassifyUrgency.intent.yaml (name, version, owner)Intent file
name: Orders.ClassifyUrgency
version: 1
owner: order-desk

Read more: the file, field by field

Instruction: the intent in plain words.

Lane
The intent file
Model call
None, it is data
A change needs
A save, no release

intent is the instruction the model receives, in plain words, which its owner can read and change without reading C#. shape says what comes back: here a whole number; also text, a yes or no, a date, a list, a .NET type registered in code or a JSON schema.

examples are inputs and the outputs you expect, shown to the model on every attempt. They steer the format and the judgement, but a reply that copies an example and breaks a rule still fails. systemInstructions adds to the system prompt, and outputRequirements says what a good answer looks like, in prose.

Orders.ClassifyUrgency.intent.yaml (intent and shape)Intent file
intent: Rate the urgency of this order email from 1 (routine) to 5 (critical).
shape: int
Orders.ClassifyUrgency.intent.yaml (examples)Intent file
examples:
  - input: "Line 3 is down until the bearings arrive. Ship today."
    output: 5
  - input: "Please restock these when convenient, no rush."
    output: 1

Read more: judgement in plain words

Model choice: the model, the provider and the limits.

Lane
The intent file
Model call
None, it is data
A change needs
A save, no release

model names the model to ask. It goes to the first provider of the chain only; a fallback asks for its own model. provider picks a configured provider by name, and naming one turns fallback off for this intent; the default judge, if on, still asks the provider of the client's judge role. Provider names are checked only when an intent runs.

attempts, timeout and maxOutputTokens set the attempts this intent may make, the time budget for the whole run and the output-token limit for each model call, and judge: true asks for the model judge when the client's JudgeMode allows it. A field the file leaves out falls back to the client's options. A file has no field for Temperature, MaxModelCalls or BypassCache, which only code sets.

Read more: the model

Rules as data: the limits every answer must pass.

Lane
The intent file
Model call
None, it is data
A change needs
A save, no release

rules are the limits every answer must pass before your code sees it: 13 kinds of check, from ranges and patterns to allowed values and required members, run in code on every answer, with no model call. validators lists the names of checks written in C# and registered in your application; they run after the rules, on every answer that reads as the result type, even one a rule has already failed.

A check named under validators, like a .NET type named under shape, must be one your application registered by name; nothing in a file can load code.

Orders.ClassifyUrgency.intent.yaml (rules)Intent file
rules:
  minimum: 1
  maximum: 5

Read more: the checks

On save: the next call uses it.

Lane
The intent file
Model call
None, it is data
A change needs
A save, no release

A save to the file changes the wording, the limits, the examples or the model on the next call, with no build and no deployment; calls already running finish on the old version.

While the application runs, a bad save keeps the last good version, and the problem is reported with the file and the line. With the request cache on, an answer cached before a change to the rules is checked against the new rules first.

Orders.ClassifyUrgency.intent.yaml, version 2Intent file
name: Orders.ClassifyUrgencyversion: 2owner: order-deskintent: Rate the urgency of this order email from 1 (routine) to 3 (critical).shape: intrules:  minimum: 1  maximum: 3examples:  - input: "Line 3 is down until the bearings arrive. Ship today."    output: 3  - input: "Please restock these when convenient, no rush."    output: 1
Output, the next call
Success: trueValue: 3Issues: noneintent.name: Orders.ClassifyUrgencyintent.version: 2intent.source: Orders.ClassifyUrgency.intent.yaml

Read more: live reload

The data model lives in the intent file too: its shape names a type your code registered, a value or a list, or holds a JSON schema, and a save can change it with no release.

A pass means the checks passed, not that the answer is right. The limits count calls, tokens and time, not money.

What does not call the model.

The model is asked for judgement. The checks, the limits and the wiring around it run in your code, and some calls end with no model call at all.

  • A repeated request. With WithCache, an identical request to the same provider is answered from the cache while the entry lasts (one hour by default), with no call for the answer, and still checked against the current rules. If the judge is on, it still reviews the cached answer, which is one model call. A new wording, shape or input is a fresh call.
  • An intent switched off. enabled: false in its file makes a call throw IntentDisabledException before any model call.
  • A setup mistake. An unknown intent name, a shape that does not fit the type you ask for, input over MaxInputChars or a limit out of range throws before any model call.
  • Every check. Refusal, truncation, JSON, required members, enum names, your Require and Validate rules and an intent file's rules run in code. Of the checks, only the optional judge calls a model.
  • An approved command for a target. TargetRuntime.PlanAsync asks the model for one command in the language your target describes, such as SQL for a database, and does not run it. Once a person approves the plan, ExecuteAsync has your target run it with no model call, and the target's inspection and your rule files check it again each time. The check is a guard, not a permission boundary.
  • Your own objects back. Sort, filter and group return your original objects, never copies, selected or ordered by the model: a filter's matches once each, and every element exactly once for sort and group.
  • Agent tools. AsAIFunctions builds an agent's tool list from your intents with no model call. Each tool call is one checked run.

    The tools, built in a compiled demo (2 lines)
    Intents as agent tools
    var runtime = new IntentRuntime(client, catalog);var options = new ChatOptions { Tools = [.. runtime.AsAIFunctions()] };
    Output: two tools, no model call (8 lines)
    Output
    Tools: Invoice_Extract, Orders_ClassifyUrgency Description of Orders_ClassifyUrgency:Intent: Rate the urgency of this order email from 1 (routine) to 5 (critical). Result: an int value. Returns {"success": true, "intent": "Orders.ClassifyUrgency", "value": <result>} when the result passed verification, or {"success": false, "intent": "Orders.ClassifyUrgency", "error": "..."} when it did not. Model calls while building the tools: 0
  • CI and tests. FileIntentCatalog checks a folder of intent files in CI with no key, and ScriptedProvider stands in for the model in unit tests.
Around the call

Log, host and tests.

The same call runs in your host and in CI, with a record of what the model answered.

A log of model calls

Each client keeps a log of its calls, on by default: the last 10,000 in memory, or wherever a memory of your own given to WithMemory keeps them. Every call that returns a result is recorded, failed ones too, unless the answer came from the cache, with the intent, the first 2,000 characters of the input, the output, the model, the tokens and your tags. DoNotRecord keeps a call out, WithMemory(null) turns the log off, and the log is never fed back into prompts.

In your host

AddIntentSharp(configuration) registers one client from appsettings and builds it when the host starts, so a setup mistake, such as a provider file with no provider, or a LicenseException shows at startup, not on the first request. A key is read on a provider's first call, so a missing key fails that call.

In your tests

ScriptedProvider stands in for the model in unit tests, with no network and no key, and records every request, so a test can check that a retry carried the findings. The outputs on this page come from it.