Description

Write workspace file

Writes a project/document file to the workspace output folder. Do NOT use for user facts — use store_memory with paths like user/name instead.

Included in Version 7

Dynamically extracted tool implementation.
How to register WorkspaceToolscsharp
registry.Register(new AgentTool(            "write_workspace_file",            "Writes a project/document file to the workspace output folder. Do NOT use for user facts — use store_memory with paths like user/name instead.",            args => WriteWorkspaceFile(args),            new            {                type = "object",                properties = new                {                    path = new { type = "string", description = "Relative path/filename of the file to write in the output folder." },                    content = new { type = "string", description = "The text content to write into the file." }                },                required = new[] { "path", "content" }            }        ));
Helper classes for WorkspaceToolscsharp
    private string WriteWorkspaceFile(string argumentsJson)    {        if (Workspace is null)            return "Error: Workspace is not initialized.";        try        {            using var doc = JsonDocument.Parse(argumentsJson);            var root = doc.RootElement;            if (!root.TryGetProperty("path", out var pathProp) || !root.TryGetProperty("content", out var contentProp))            {                return "Error: Missing path or content properties.";            }            string relativePath = pathProp.GetString() ?? "";            string content = contentProp.GetString() ?? "";            if (string.IsNullOrWhiteSpace(relativePath))            {                return "Error: Path cannot be empty.";            }            if (IsMemoryNamespacePath(relativePath))            {                return StoreViaMemoryAsync(relativePath, content);            }            string? safePath = GetSafePath(Workspace.OutputFolder, relativePath);            if (safePath is null)            {                return "Error: Access denied. Path is outside of output workspace directory.";            }            string? dir = Path.GetDirectoryName(safePath);            if (dir is not null && !Directory.Exists(dir))            {                Directory.CreateDirectory(dir);            }            File.WriteAllText(safePath, content, System.Text.Encoding.UTF8);            return $"Success: Successfully wrote {content.Length} characters to file '{relativePath}'.";        }        catch (Exception ex)        {            return $"Error writing file: {ex.Message}";        }    }