> For the complete documentation index, see [llms.txt](https://docs.umbraco.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.umbraco.com/ai-in-umbraco/19.latest/reference/models/ai-context.md).

# AIContext

Model representing an AI context with resources.

Represents a collection of resources (brand voice, guidelines, content) that can be injected into AI operations.

## Namespace

```csharp
using Umbraco.AI.Core.Contexts;
```

## Definition

{% code title="AIContext" %}

```csharp
public sealed class AIContext : IAIVersionableEntity
{
    public Guid Id { get; internal set; }
    public required string Alias { get; set; }
    public required string Name { get; set; }
    public IList<AIContextResource> Resources { get; set; } = [];

    // Audit properties
    public DateTime DateCreated { get; init; } = DateTime.UtcNow;
    public DateTime DateModified { get; set; } = DateTime.UtcNow;
    public Guid? CreatedByUserId { get; set; }
    public Guid? ModifiedByUserId { get; set; }

    // Versioning
    public int Version { get; internal set; } = 1;
}
```

{% endcode %}

## Properties

| Property           | Type                       | Description                                     |
| ------------------ | -------------------------- | ----------------------------------------------- |
| `Id`               | `Guid`                     | Unique identifier (auto-generated)              |
| `Alias`            | `string`                   | Unique alias for programmatic lookup (required) |
| `Name`             | `string`                   | Display name (required)                         |
| `Resources`        | `IList<AIContextResource>` | Collection of resources                         |
| `DateCreated`      | `DateTime`                 | When created (UTC)                              |
| `DateModified`     | `DateTime`                 | When last modified (UTC)                        |
| `CreatedByUserId`  | `Guid?`                    | User who created                                |
| `ModifiedByUserId` | `Guid?`                    | User who last modified                          |
| `Version`          | `int`                      | Current version number                          |

## Example

{% code title="Example" %}

```csharp
var context = new AIContext
{
    Alias = "brand-guidelines",
    Name = "Brand Guidelines",
    Resources = new List<AIContextResource>
    {
        new AIContextResource
        {
            ResourceTypeId = "text",
            Name = "Tone of Voice",
            Description = "Writing style guidelines",
            SortOrder = 0,
            Settings = "Always use a friendly, professional tone...",
            InjectionMode = AIContextResourceInjectionMode.Always
        },
        new AIContextResource
        {
            ResourceTypeId = "text",
            Name = "Product Terminology",
            SortOrder = 1,
            Settings = "Use these terms when discussing products..."
        }
    }
};
```

{% endcode %}

## Related

* [AIContextResource](#aicontextresource) - Resource model
* [IAIContextService](/ai-in-umbraco/19.latest/reference/services/ai-context-service.md) - Context service

***

## AIContextResource

Represents a single resource within a context.

## Definition

{% code title="AIContextResource" %}

```csharp
public sealed class AIContextResource
{
    public Guid Id { get; internal set; }
    public required string ResourceTypeId { get; init; }
    public required string Name { get; set; }
    public string? Description { get; set; }
    public int SortOrder { get; set; }
    public object? Settings { get; set; }
    public AIContextResourceInjectionMode InjectionMode { get; set; } = AIContextResourceInjectionMode.Always;
}
```

{% endcode %}

## Properties

| Property         | Type                             | Description                            |
| ---------------- | -------------------------------- | -------------------------------------- |
| `Id`             | `Guid`                           | Unique identifier (auto-generated)     |
| `ResourceTypeId` | `string`                         | Type of resource (required, immutable) |
| `Name`           | `string`                         | Display name (required)                |
| `Description`    | `string?`                        | Optional description                   |
| `SortOrder`      | `int`                            | Order for injection                    |
| `Settings`       | `object?`                        | Resource content (type-specific)       |
| `InjectionMode`  | `AIContextResourceInjectionMode` | When to inject                         |

## Resource Types

| Type ID    | Data Type | Description         |
| ---------- | --------- | ------------------- |
| `text`     | `string`  | Plain text content  |
| `document` | `object`  | Structured document |
| `url`      | `string`  | URL reference       |

## Injection Modes

{% code title="AIContextResourceInjectionMode" %}

```csharp
public enum AIContextResourceInjectionMode
{
    Always = 0,   // Always inject
    OnDemand = 1  // Only inject when explicitly requested
}
```

{% endcode %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.umbraco.com/ai-in-umbraco/19.latest/reference/models/ai-context.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
