microsoft/semantic-kernel · error · KernelException

The process must have an Id set

Error message

The process must have an Id set

What it means

Thrown by the static `BuildWorkflow(KernelProcess)` when `process.State.Id` is null. The workflow requires a stable identifier to serialize, so a process without an Id is rejected at construction of the `Workflow` object. It is a KernelException thrown inline in the object initializer.

Source

Thrown at dotnet/src/Experimental/Process.Core/Workflow/WorkflowBuilder.cs:328

        return Task.CompletedTask;
    }

    #endregion

    #region FromProcess

    /// <summary>
    /// Builds a workflow from a kernel process.
    /// </summary>
    /// <param name="process"></param>
    /// <returns></returns>
    public static Task<Workflow> BuildWorkflow(KernelProcess process)
    {
        Verify.NotNull(process);

        Workflow workflow = new()
        {
            Id = process.State.Id ?? throw new KernelException("The process must have an Id set"),
            Description = process.Description,
            FormatVersion = "1.0",
            Name = process.State.Name,
            Nodes = [new Node { Id = "End", Type = "declarative", Version = "1.0", Description = "Terminal state" }],
            Variables = [],
        };

        // Add variables
        foreach (var thread in process.Threads)
        {
            workflow.Variables.Add(thread.Key, new VariableDefinition()
            {
                Type = VariableType.Thread,
            });
        }

        if (process.UserStateType != null)
        {

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Assign a non-null Id when creating the process: `process.State.Id = "myProcess"` or via the builder's id parameter.
  2. If loading from JSON/YAML, ensure the source contains an `id` field and the deserializer maps it to `State.Id`.
  3. Add a guard before calling BuildWorkflow: `if (process.State.Id is null) throw ...` with a clearer message.

Example fix

// before
var process = new KernelProcess(state, steps, edges);
await WorkflowBuilder.BuildWorkflow(process);
// after
state.Id = "myProcess";
var process = new KernelProcess(state, steps, edges);
await WorkflowBuilder.BuildWorkflow(process);
Defensive patterns

Strategy: validation

Validate before calling

if (process?.State?.Id is null || string.IsNullOrWhiteSpace(process.State.Id))
    throw new InvalidOperationException("Cannot build a workflow from a process with no Id; assign process.State.Id first.");
await WorkflowBuilder.BuildWorkflow(process);

Type guard

bool HasProcessId(KernelProcess p) => !string.IsNullOrWhiteSpace(p?.State?.Id);

Try / catch

try { await WorkflowBuilder.BuildWorkflow(process); }
catch (KernelException ex) when (ex.Message.Contains("must have an Id"))
{ _logger.LogError(ex, "Process missing Id before workflow build."); throw; }

Prevention

When it happens

Trigger: Construct a `KernelProcess` (or its `KernelProcessState`) without assigning an Id and pass it to `BuildWorkflow`; build a process from a builder that never called `.WithId(...)` / never set the id; deserialize a process whose state lost its Id.

Common situations: Programmatic process construction where the Id was assumed to auto-generate; tests that create a throwaway process without an Id; serialization round-trips that drop the Id field.

Related errors


AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13). Data as JSON: /api/errors/c7dedc42bdaaba43. Report an issue: GitHub.