# IWorkflowDefinitionStore

> Tracon documentation. Tracon is a .NET package family that adds a control
> plane on Microsoft Agent Framework, published as NuGet packages that run
> inside your own ASP.NET Core application.
>
> Page: https://tracon.dev/api/tracon.iworkflowdefinitionstore/
> Summary: IWorkflowDefinitionStore: The store for workflow definitions stored in the database. Every save produces a new version, old versions are not deleted, and a rollback writes an old.

<div class="api-provenance">Namespace Tracon · Assembly <code>Tracon.Abstractions.dll</code></div>

The store for workflow definitions stored in the database. Every save produces a
new version, old versions are not deleted, and a rollback writes an old version's
content back as a new one.

```csharp
public interface IWorkflowDefinitionStore
```

## Remarks

**A version number is an identity, not a counter.** Deleting a
definition does not delete its history, and saving the same name again continues the
numbering from the highest version ever written. A number therefore always names
the same content: a run that recorded version 3 of `narrated` can be resumed
with exactly that content, even after the workflow was deleted and created again.
(An agent definition keeps the numbering the same way, but not the history: deleting it
deletes its versions, and the next save continues from the highest number the name had.)

**Tenant behavior — EXPLICIT tenant.** Every member takes the tenant
as a parameter and never reads `ITenantContext`: the store is also called from
the workflow execution pipeline, where there is no HTTP context.

## Methods

### <a id="Tracon_IWorkflowDefinitionStore_DeleteAsync_System_String_System_String_System_Threading_CancellationToken_"></a> DeleteAsync\(string, string, CancellationToken\)

Deletes the definition.

```csharp
ValueTask<bool> DeleteAsync(string tenantId, string name, CancellationToken cancellationToken = default)
```

#### Parameters

`tenantId` [string](https://learn.microsoft.com/dotnet/api/system.string)

The tenant identifier.

`name` [string](https://learn.microsoft.com/dotnet/api/system.string)

The workflow name.

`cancellationToken` [CancellationToken](https://learn.microsoft.com/dotnet/api/system.threading.cancellationtoken)

The cancellation token.

#### Returns

 [ValueTask](https://learn.microsoft.com/dotnet/api/system.threading.tasks.valuetask\-1)<[bool](https://learn.microsoft.com/dotnet/api/system.boolean)\>

[true](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool) if the delete happened.

### <a id="Tracon_IWorkflowDefinitionStore_GetAsync_System_String_System_String_System_Threading_CancellationToken_"></a> GetAsync\(string, string, CancellationToken\)

Fetches the definition with the given name.

```csharp
ValueTask<WorkflowDefinition?> GetAsync(string tenantId, string name, CancellationToken cancellationToken = default)
```

#### Parameters

`tenantId` [string](https://learn.microsoft.com/dotnet/api/system.string)

The tenant identifier.

`name` [string](https://learn.microsoft.com/dotnet/api/system.string)

The workflow name.

`cancellationToken` [CancellationToken](https://learn.microsoft.com/dotnet/api/system.threading.cancellationtoken)

The cancellation token.

#### Returns

 [ValueTask](https://learn.microsoft.com/dotnet/api/system.threading.tasks.valuetask\-1)<[WorkflowDefinition](/api/tracon.workflowdefinition/)?\>

The definition; [null](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null) if it does not exist.

### <a id="Tracon_IWorkflowDefinitionStore_GetVersionAsync_System_String_System_String_System_Int32_System_Threading_CancellationToken_"></a> GetVersionAsync\(string, string, int, CancellationToken\)

Fetches one version of a definition.

```csharp
ValueTask<WorkflowDefinition?> GetVersionAsync(string tenantId, string name, int version, CancellationToken cancellationToken = default)
```

#### Parameters

`tenantId` [string](https://learn.microsoft.com/dotnet/api/system.string)

The tenant identifier.

`name` [string](https://learn.microsoft.com/dotnet/api/system.string)

The workflow name.

`version` [int](https://learn.microsoft.com/dotnet/api/system.int32)

The version number.

`cancellationToken` [CancellationToken](https://learn.microsoft.com/dotnet/api/system.threading.cancellationtoken)

The cancellation token.

#### Returns

 [ValueTask](https://learn.microsoft.com/dotnet/api/system.threading.tasks.valuetask\-1)<[WorkflowDefinition](/api/tracon.workflowdefinition/)?\>

The definition as it was saved at that version, with its `Version` and
`UpdatedAt` set; [null](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null) if that version does not exist.

#### Remarks

The history outlives the definition: a version of a workflow that was deleted is
still returned. A caller that needs the workflow to exist asks
[IWorkflowDefinitionStore.GetAsync](/api/tracon.iworkflowdefinitionstore/#Tracon_IWorkflowDefinitionStore_GetAsync_System_String_System_String_System_Threading_CancellationToken_) first.

### <a id="Tracon_IWorkflowDefinitionStore_ListAsync_System_String_System_Threading_CancellationToken_"></a> ListAsync\(string, CancellationToken\)

Lists all of a tenant's definitions, by name.

```csharp
ValueTask<IReadOnlyList<WorkflowDefinition>> ListAsync(string tenantId, CancellationToken cancellationToken = default)
```

#### Parameters

`tenantId` [string](https://learn.microsoft.com/dotnet/api/system.string)

The tenant identifier.

`cancellationToken` [CancellationToken](https://learn.microsoft.com/dotnet/api/system.threading.cancellationtoken)

The cancellation token.

#### Returns

 [ValueTask](https://learn.microsoft.com/dotnet/api/system.threading.tasks.valuetask\-1)<[IReadOnlyList](https://learn.microsoft.com/dotnet/api/system.collections.generic.ireadonlylist\-1)<[WorkflowDefinition](/api/tracon.workflowdefinition/)\>\>

The definitions.

### <a id="Tracon_IWorkflowDefinitionStore_ListVersionsAsync_System_String_System_String_System_Threading_CancellationToken_"></a> ListVersionsAsync\(string, string, CancellationToken\)

Lists every version of a definition, from newest to oldest.

```csharp
ValueTask<IReadOnlyList<WorkflowDefinition>> ListVersionsAsync(string tenantId, string name, CancellationToken cancellationToken = default)
```

#### Parameters

`tenantId` [string](https://learn.microsoft.com/dotnet/api/system.string)

The tenant identifier.

`name` [string](https://learn.microsoft.com/dotnet/api/system.string)

The workflow name.

`cancellationToken` [CancellationToken](https://learn.microsoft.com/dotnet/api/system.threading.cancellationtoken)

The cancellation token.

#### Returns

 [ValueTask](https://learn.microsoft.com/dotnet/api/system.threading.tasks.valuetask\-1)<[IReadOnlyList](https://learn.microsoft.com/dotnet/api/system.collections.generic.ireadonlylist\-1)<[WorkflowDefinition](/api/tracon.workflowdefinition/)\>\>

Full snapshots, not deltas; empty when the name was never saved.

### <a id="Tracon_IWorkflowDefinitionStore_RollbackAsync_System_String_System_String_System_Int32_System_Threading_CancellationToken_"></a> RollbackAsync\(string, string, int, CancellationToken\)

Makes the given version current. A rollback does not delete or move anything: it
saves the version's content as a new version.

```csharp
ValueTask<WorkflowDefinition> RollbackAsync(string tenantId, string name, int version, CancellationToken cancellationToken = default)
```

#### Parameters

`tenantId` [string](https://learn.microsoft.com/dotnet/api/system.string)

The tenant identifier.

`name` [string](https://learn.microsoft.com/dotnet/api/system.string)

The workflow name.

`version` [int](https://learn.microsoft.com/dotnet/api/system.int32)

The version number to roll back to.

`cancellationToken` [CancellationToken](https://learn.microsoft.com/dotnet/api/system.threading.cancellationtoken)

The cancellation token.

#### Returns

 [ValueTask](https://learn.microsoft.com/dotnet/api/system.threading.tasks.valuetask\-1)<[WorkflowDefinition](/api/tracon.workflowdefinition/)\>

The definition saved as the new version.

#### Remarks

The store does not judge whether the content is still valid: a function the
version names may have been unregistered since. The caller validates it the way a
save is validated before it calls this. When the workflow was deleted, the
rollback creates it again and the numbering continues.

#### Exceptions

 [TraconException](/api/tracon.traconexception/)

That version does not exist.

### <a id="Tracon_IWorkflowDefinitionStore_SaveAsync_System_String_Tracon_WorkflowDefinition_System_Threading_CancellationToken_"></a> SaveAsync\(string, WorkflowDefinition, CancellationToken\)

Saves the definition. The incoming `WorkflowDefinition.Version`
value is ignored; the store determines the version number.

```csharp
ValueTask<WorkflowDefinition> SaveAsync(string tenantId, WorkflowDefinition definition, CancellationToken cancellationToken = default)
```

#### Parameters

`tenantId` [string](https://learn.microsoft.com/dotnet/api/system.string)

The tenant identifier.

`definition` [WorkflowDefinition](/api/tracon.workflowdefinition/)

The definition to save.

`cancellationToken` [CancellationToken](https://learn.microsoft.com/dotnet/api/system.threading.cancellationtoken)

The cancellation token.

#### Returns

 [ValueTask](https://learn.microsoft.com/dotnet/api/system.threading.tasks.valuetask\-1)<[WorkflowDefinition](/api/tracon.workflowdefinition/)\>

The definition with its version number assigned.
