> 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/17.latest/reference/models/ai-context.md).

# AIContext

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/17.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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
