Documentation
Table of Contents

Quick start

Start with a scripted example to see how IntentSharp checks results and handles failed attempts without calling a model. The steps that follow build a console program with your own provider: a typed call, a collection call and a call to an intent kept in a file. The code is compiled against the library on every site build.

Try a sample without a model account

Using .NET 10? Run two invoice contracts in one C# console app. The sample uses IntentSharp 1.0.1, rejects an invalid currency, and accepts the scripted retry.

Using .NET 8? Download the IntentSharp 1.0.0 urgency sample and extract it. In its IntentSharp.Sample folder, with the .NET 8 SDK installed, run:

dotnet run -- --self-test

Restore downloads the pinned 1.0.0 packages from NuGet. The checks use scripted replies, with no model key or external model call. For example, a reply of 7 fails a rule, the retry of 5 passes, and two invalid replies produce an unsuccessful result. The sample also checks an explicit catalog reload and keeps the last good definition after an invalid save. They exercise application behavior; test your model's accuracy, latency and connectivity separately. The sample's README explains the optional --live mode, which uses your provider account and may incur its charges. Licensing still applies.

To try IntentSharp in your own development or test project, start a free 30-day evaluation. To use your own model account with a new console project, follow the steps below.

1. Create the project

You need the .NET 8 SDK or later; the program can target .NET 8, 9 or 10.

dotnet new console -n QuickStart
cd QuickStart
dotnet add package IntentSharp
dotnet add package IntentSharp.Catalog

The packages come from nuget.org. IntentSharp is the client and the calls; IntentSharp.Catalog runs intents kept in files. Installation covers the other packages.

2. Add the provider file and an API key

Create config/intentsharp.providers.json in the project folder. It names the provider, its model and where its key is read from:

{
  "intentsharp": "providers/1",
  "providers": [
    { "name": "main", "kind": "anthropic", "secret": "env:ANTHROPIC_API_KEY", "model": "<model id>" }
  ],
  "roles": { "answer": "main" }
}

Write the id of a model your Anthropic account offers in place of <model id>: IntentSharp ships no model id. For OpenAI, write "kind": "openai" and "secret": "env:OPENAI_API_KEY". Then set the key in the shell you run from:

export ANTHROPIC_API_KEY="..."
$env:ANTHROPIC_API_KEY = "..."

The file names the variable, never the key. Keep the .intentsharp folder the store writes beside the file out of source control. Each run calls the model, so your provider bills it; to run with no key, pass a ScriptedProvider to UseProvider (Testing). Providers adds a fallback provider and the other ways to give a key.

3. Add an intent file

Create intents/Orders.ClassifyUrgency.intent.yaml in the project folder:

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

The program names the intent; the file decides its wording, its result (a whole number), the rules the answer must pass and the examples the model sees. Copy both folders next to the program when it builds, inside <Project> in QuickStart.csproj:

<ItemGroup>
  <None Update="config\**\*" CopyToOutputDirectory="PreserveNewest" />
  <None Update="intents\**\*" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>

The program reads the copies in the build output (such as bin/Debug/net10.0/intents); the catalog throws DirectoryNotFoundException when its folder is missing.

4. Write the program

Replace Program.cs with this:

using IntentSharp;
using IntentSharp.Catalog;
using IntentSharp.Documents;
using IntentSharp.Extensions;

// 1. Build a client. config/intentsharp.providers.json names the provider, its model and the environment
//    variable its key is read from; the code names none of them.
using var store = new FolderDocumentStore(Path.Combine(AppContext.BaseDirectory, "config"));
using var client = new IntentClientBuilder()
    .UseProviderOptions(store)
    .Build();

// 2. A typed call. The answer comes back as a checked PurchaseRequest, or as a failed result.
var email = "Hi, this is Dana from Northwind. We'd like 40 units of SKU A-1192 delivered by 2026-11-15.";

var order = await email.AIAsync<PurchaseRequest>(client, "Extract the purchase request from this email.");
if (order.Success)
    Console.WriteLine($"{order.Value!.Contact} wants {order.Value.Quantity} x {order.Value.Sku} by {order.Value.DeliverBy:yyyy-MM-dd}");
else
    foreach (var issue in order.Issues) Console.WriteLine(issue);

// 3. A collection call. Your own Ticket objects come back, not copies.
var tickets = new List<Ticket>
{
    new(101, "Login page returns 500 after password reset", "Critical"),
    new(102, "Add dark mode", "Low"),
    new(103, "Export to CSV drops the last row", "High"),
};

var bugs = await tickets.AIFilterAsync(client, "tickets that describe a defect rather than a feature request");
Console.WriteLine(bugs.Success ? "Defects: " + string.Join(", ", bugs.Value!.Select(t => t.Id)) : "Defects: no verified answer");

// 4. An intent from a file. intents/Orders.ClassifyUrgency.intent.yaml decides the wording, the result shape, the
//    rules and the examples, and a saved edit applies on the next call.
using var catalog = new FileIntentCatalog(Path.Combine(AppContext.BaseDirectory, "intents"));
var runtime = new IntentRuntime(client, catalog);

var urgency = await runtime.RunAsync<int>("Orders.ClassifyUrgency",
    "Our packaging line stops on Thursday unless the 40 replacement belts arrive. Can you expedite?");
Console.WriteLine(urgency.Success ? $"Urgency: {urgency.Value}" : "Urgency: no verified answer");

// Type declarations come after the top-level statements.
public sealed class PurchaseRequest
{
    public string Contact { get; set; } = "";
    public string Sku { get; set; } = "";
    public int Quantity { get; set; }
    public DateOnly DeliverBy { get; set; }
}

public sealed record Ticket(int Id, string Title, string Severity);
  • The client. FolderDocumentStore reads the config folder, and UseProviderOptions takes the providers from its provider file; Build throws InvalidOperationException when the file defines no provider. The key is read on the first call, and a call whose key is not set throws ProviderConfigurationException. Build reads the license key from INTENTSHARP_LICENSE_KEY; without one the client still works.
  • A typed call. AIAsync<T> returns an AIResult<T>: check Success before reading Value, and read Issues for what went wrong.
  • A collection call. On success the original objects come back, selected or ordered by the model, each at most once. The other collection methods are in Collections.
  • An intent from a file. FileIntentCatalog loads and watches the folder, and RunAsync<T> runs the named intent with the shape, rules and examples the file declares. A saved edit applies on the next call, with no restart; an edit with an error keeps the definition loaded before. An unknown name, enabled: false or a shape that does not fit T throws before any model call.

5. Run it

dotnet run

The program prints one line per call. Run on ScriptedProvider with scripted answers, it prints:

Dana wants 40 x A-1192 by 2026-11-15
Defects: 101, 103
Urgency: 4

With a real model, the values are the model's checked answers. A wrong answer does not throw: it is retried with the findings, and if it still fails, the line says so.

6. Add a license key

Evaluation is free for 30 days. Ask for an evaluation key, which arrives by email, and set it the same way as the API key:

export INTENTSHARP_LICENSE_KEY="..."

The key is checked with no network call, once, when the client is built. To see what the check found, read client.License at startup:

// What the license check found when the client was built. It never calls the network.
LicenseStatus license = client.License;
Console.WriteLine($"License: {license.State}");   // Licensed, Evaluation, None, ...
if (license.DaysRemaining is int days)
    Console.WriteLine($"Days remaining: {days}");
if (license.Message is { Length: > 0 } message)
    Console.WriteLine(message);                    // what to do, when there is something to do

Your license key shows the other ways to set it. Production use, and any business use after the evaluation, needs a paid license: see Licensing.

Next