microsoft/semantic-kernel · error · InvalidOperationException

Invalid manifest file path.

Error message

Invalid manifest file path.

What it means

Thrown by the private GetFullPath helper when a referenced path (an instructions $[file(...)] or an action File) is relative, is not an http URL, AND the manifest directory (Path.GetDirectoryName of the declarative agent file path) is null or empty. Without a base directory there is no anchor to resolve the relative path against, so resolution is refused rather than silently falling back to the CWD.

Source

Thrown at dotnet/src/Functions/Functions.OpenApi.Extensions/Extensions/DeclarativeAgentExtensions.cs:127

        if (string.IsNullOrEmpty(source) ||
            !source!.StartsWith("$[file('", StringComparison.OrdinalIgnoreCase) ||
            !source.EndsWith("')]", StringComparison.OrdinalIgnoreCase))
        {
            return source;
        }
#if NET
        var filePath = source[8..^3];
#else
        var filePath = source.Substring(8, source.Length - 11);
#endif
        filePath = GetFullPath(manifestFilePath, filePath);
        return await DocumentLoader.LoadDocumentFromFilePathAsync(filePath, logger, cancellationToken).ConfigureAwait(false);
    }
    private static string GetFullPath(string? manifestDirectory, string relativeOrAbsolutePath)
    {
        return !Path.IsPathRooted(relativeOrAbsolutePath) && !relativeOrAbsolutePath.StartsWith("http", StringComparison.OrdinalIgnoreCase)
            ? string.IsNullOrEmpty(manifestDirectory)
                ? throw new InvalidOperationException("Invalid manifest file path.")
                : Path.Combine(manifestDirectory, relativeOrAbsolutePath)
            : relativeOrAbsolutePath;
    }
}

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Pass a fully-qualified or clearly rooted path to CreateChatCompletionAgentFromDeclarativeAgentManifestAsync so Path.GetDirectoryName yields a real directory.
  2. Use Path.GetFullPath(manifestPath) before calling so the directory component is always populated.
  3. Ensure any $[file('...')] instructions reference and action File values resolve relative to that directory.

Example fix

// before - bare filename yields an empty directory component
var agent = await kernel.CreateChatCompletionAgentFromDeclarativeAgentManifestAsync<ChatCompletionAgent>("agent.yaml");

// after - absolute path gives a real manifest directory
var fullPath = Path.GetFullPath(Path.Combine(AppContext.BaseDirectory, "Agents", "agent.yaml"));
var agent = await kernel.CreateChatCompletionAgentFromDeclarativeAgentManifestAsync<ChatCompletionAgent>(fullPath);
Defensive patterns

Strategy: validation

Validate before calling

var fullManifestPath = Path.GetFullPath(filePath);
if (string.IsNullOrEmpty(Path.GetDirectoryName(fullManifestPath)))
    throw new InvalidOperationException("Manifest path must include a directory component.");

Prevention

When it happens

Trigger: Loading a declarative agent manifest by a bare filename (e.g. 'agent.yaml') from the current directory, so Path.GetDirectoryName returns an empty string, and the manifest references a relative file (instructions file or action File). Because the directory component is empty, GetFullPath cannot combine the relative reference.

Common situations: Passing just 'agent.yaml' instead of an absolute or clearly-rooted path; running the loader where the CWD has no directory prefix; a manifest path constructed by string concatenation that dropped the directory portion.

Related errors


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