Crestapps core document processing

From CrestApps/CrestApps.AgentSkills · View interactive version

Crestapps core document processing is an AI agent skill from the GitHub repository CrestApps/CrestApps.AgentSkills. Skill for CrestApps.Core 2.0 document processing and the separate ingestion path. Covers AddDocumentProcessing with OpenXml, Pdf, Word and reference downloads, AddCoreAIDocumentIngestion with AddPlainTextReader, AddFigureProcessing, AddFigureBackfill, AddPdf and AddDocumentIntelligence, the IAIDocum

How to use this skill

Skill file

CrestApps.Core Document Processing

Use this skill when a host lets users upload documents into chat sessions, chat interactions or AI profiles, or when it needs to read files into an AI knowledge base without the chat stack. For the Presentation, Word and PDF agents see crestapps-core-document-agents. For scheduled folder and file-server intake see crestapps-core-file-sources.

Two packages, two jobs

| Package | Holds | Register with |

|---|---|---|

| CrestApps.Core.AI.Ingestion | readers, the processor pipeline, IDocumentFileStore, IKnowledgeIngestionService | AddCoreAIDocumentIngestion(...) |

| CrestApps.Core.AI.Ingestion.Pdf | the PdfPig PDF reader and PdfLayoutOptions | AddPdf() on the ingestion builder |

| CrestApps.Core.AI.Documents | uploads, tabular workspaces, generated files, the chat tools, the Tabular Data Agent | AddDocumentProcessing(...) / AddCoreAIDocumentProcessing() |

| CrestApps.Core.AI.Documents.OpenXml | .docx, .xlsx, .pptx, .potx reader, Office writers, Presentation Agent | AddOpenXml() |

| CrestApps.Core.AI.Documents.Pdf | PDF reader plus PDF writer and PDF Agent | AddPdf() on the document-processing builder |

| CrestApps.Core.AI.Documents.Word | Word Agent | AddWord() |

| CrestApps.Core.Azure.DocumentIntelligence | Azure AI Document Intelligence reader | AddDocumentIntelligence(...) on the ingestion builder |

AddCoreAIDocumentProcessing() calls AddCoreAIDocumentIngestion(i => i.AddPlainTextReader().AddFigureProcessing().AddFigureBackfill()) for you, so a chat host does not register the ingestion half separately.

Chat Document Processing

builder.Services.AddCrestAppsCore(crestApps => crestApps
    .AddAISuite(ai => ai
        .AddMarkdown()
        .AddChatInteractions(chatInteractions => chatInteractions
            .AddEntityCoreStores())
        .AddDocumentProcessing(documentProcessing => documentProcessing
            .AddEntityCoreStores()
            .AddOpenXml()
            .AddPdf()
            .AddWord()
            .AddReferenceDownloads())
        .AddOpenAI())
    .AddEntityCoreSqliteDataStore("Data Source=app.db"));

var app = builder.Build();

app.AddDownloadAIDocumentEndpoint();
app.AddDownloadAIDocumentFigureEndpoint();
app.AddUploadChatInteractionDocumentEndpoint();
app.AddRemoveChatInteractionDocumentEndpoint();
app.AddUploadChatSessionDocumentEndpoint();
app.AddRemoveChatSessionDocumentEndpoint();

| Endpoint extension | Route |

|---|---|

| AddDownloadAIDocumentEndpoint() | GET ai/documents/{documentId}/download |

| AddDownloadAIDocumentFigureEndpoint() | GET ai/documents/{documentId}/figures/{figureId} |

| AddDownloadKnowledgeFigureEndpoint() | GET ai/knowledge/{dataSourceId}/figures/{canonicalId} |

Download and figure endpoints authorize through the resource-based AIChatDocumentOperations.ManageDocuments requirement (chat interaction, chat session and AI profile documents). Knowledge figures use AIKnowledgeOperations.ViewFigures against the owning AIDataSource. Register an AuthorizationHandler<OperationAuthorizationRequirement, TResource> that grants them.

AddChatApiEndpoints() is internal composition in the MVC and Blazor sample hosts. Custom hosts map the endpoint extensions above directly.

Ingestion Without Chat

A host that only reads files into a knowledge base registers the ingestion half on its own. None of the upload, tabular or chat tool services come with it.

builder.Services
    .AddCoreAIServices()
    .AddCoreAIDocumentIngestion(ingestion => ingestion
        .AddPlainTextReader()
        .AddFigureProcessing()
        .AddFigureBackfill()
        .AddPdf());

| Builder call | Registers | Leave out when |

|---|---|---|

| always | pipeline, reader resolver, IDocumentFileStore, IImageAnalysisService, IKnowledgeIngestionService, the File source handler | never |

| AddPlainTextReader() | .txt, .csv, .md, .json, .xml, .html, .htm, .log, .yaml, .yml | those types never arrive |

| AddFigureProcessing() | FigureCaptionProcessor, FigureSalienceProcessor, FigureDescriptionProcessor | you want no vision calls |

| AddFigureBackfill() | IFigureDescriptionBackfillService and its hosted job | you schedule backfill yourself |

| AddPdf() | PDF reader only (no writer, no agent) | you read no PDFs |

| AddDocumentIntelligence(...) | Azure layout reader wrapped in FallbackIngestionDocumentReader | no Azure endpoint |

Office files are read by CrestApps.Core.AI.Documents.OpenXml, which depends on document processing, so a host ingesting .docx, .xlsx or .pptx still registers AddDocumentProcessing(...).AddOpenXml().

Keyed readers resolve to the last registration. When a host uses both chat document processing and file sources, call AddDocumentProcessing() before AddCoreFileSources() so the HTML reader registered by file sources wins .html over the plain-text reader.

Custom Readers and Processors

builder.Services.AddCoreAIIngestionDocumentReader<RtfIngestionDocumentReader>(".rtf");
builder.Services.AddCoreAIIngestionDocumentProcessor<EmailRedactionProcessor>();
using System.Text.RegularExpressions;
using CrestApps.Core.AI.Ingestion;
using Microsoft.Extensions.DataIngestion;

public sealed partial class EmailRedactionProcessor : AIDocumentIngestionProcessor
{
    public override Task<IngestionDocument> ProcessAsync(
        IngestionDocument document,
        DocumentIngestionContext context,
        CancellationToken cancellationToken = default)
    {
        foreach (var section in document.Sections)
        {
            cancellationToken.ThrowIfCancellationRequested();

            foreach (var paragraph in section.Elements.OfType<IngestionDocumentParagraph>())
            {
                if (!string.IsNullOrEmpty(paragraph.Text))
                {
                    paragraph.Text = EmailPattern().Replace(paragraph.Text, "[email]");
                }
            }
        }

        return Task.FromResult(document);
    }

    [GeneratedRegex(@"[\w.+-]+@[\w-]+\.[\w.]+")]
    private static partial Regex EmailPattern();
}

DocumentIngestionContext carries FigureMode, VisionDeploymentName, UtilityDeploymentName, MaxFigureDescriptionsPerDocument (default 25), Language, DescribeFiguresInline and DataSourceId. The single-argument ProcessAsync is sealed and runs with DocumentIngestionContext.Default.

See references/ingestion-pipeline.md for a custom reader, reader resolution, PDF layout analysis, captions, salience, transcription and Azure Document Intelligence.

Upload Limits

The framework reads upload settings from InteractionDocumentOptions (the sample hosts map their InteractionDocumentSettings site settings onto it).

builder.Services.Configure<InteractionDocumentOptions>(options =>
{
    options.MaxIndexableCharacters = 50000;   // 0 means no limit
    options.DescribeFiguresInUploads = true;  // false keeps figures but skips vision transcription
    options.TopN = 3;
    options.AllowImageUploads = true;
});

ChatDocumentsOptions lists the allowed, embeddable and tabular extensions, but its Add methods are internal. An extension becomes uploadable by registering a reader for it with AddCoreAIIngestionDocumentReader<T>(...). Use the public members such as MaxVisionImageBytesPerFile, MaxVisionInputBytesPerRequest, AnalyzeImagesAtUpload and the GetAllowedFileExtensions(...) and IsAllowedFileExtension(...) extensions to drive upload UI and server validation.

Storage

Uploaded files, figure images and agent workspaces go through IDocumentFileStore (namespace CrestApps.Core.AI.Ingestion). The default is FileSystemFileStore under DocumentFileSystemFileStoreOptions.BasePath. Replace it with your own singleton for blob storage.

builder.Services.AddSingleton<IDocumentFileStore, BlobDocumentFileStore>();

Built-in Tools

| Tool | Name | Notes |

|---|---|---|

| SearchDocumentsTool | search_documents | vector search over attached documents |

| ReadDocumentTool | read_document | full text of one document |

| GetDocumentMetadataTool | get_document_metadata | metadata, tabular columns, and the figures a document holds |

| ViewDocumentFigureTool | view_document_figure | caption, page, link and markdown image for a figure, optional vision question |

| InspectImageTool | inspect_image | detailed look at an uploaded image |

| GenerateFileTool | generate_file | writes a downloadable file through IGeneratedFileWriter |

The hidden Tabular Data Agent (tabular-data-agent) tools are list_tabular_data, query_tabular_data, preview_tabular_data, execute_tabular_command, fill_empty_tabular_cells, format_tabular_data, export_tabular_data and compare_tabular_data. Worksheets load as separate tables, rollup rows go to a sibling <table>_rollups table, and TabularPreviewOptions caps the SVG preview.

Tool results that implement IAIToolContentProvider reach a chat model as text, while the MCP server keeps the rich content blocks.

Upgrading Within 2.0 Previews

Upgrading from 1.x

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.