Table of Contents

Class FilterPipeline

Namespace
LMKit.TextGeneration.Filters
Assembly
LM-Kit.NET.dll

An ordered collection of filters that intercept prompt, completion, and tool invocation stages.

public sealed class FilterPipeline
Inheritance
FilterPipeline
Inherited Members
Extension Methods

Examples

Configuring a pipeline with multiple filters:

using LMKit.TextGeneration;
using LMKit.TextGeneration.Filters;

var pipeline = new FilterPipeline();

// Add class-based filters
pipeline.PromptFilters.Add(new LoggingPromptFilter());
pipeline.CompletionFilters.Add(new TokenTelemetryFilter());
pipeline.ToolInvocationFilters.Add(new ToolLoggingFilter());

// Add inline lambda filters
pipeline.AddPromptFilter(async (ctx, next) =>
{
    Console.WriteLine($"Prompt: {ctx.Prompt}");
    await next(ctx);
});

// Assign to a conversation
var chat = new MultiTurnConversation(model);
chat.Filters = pipeline;

Using with AgentBuilder:

using LMKit.Agents;
using LMKit.TextGeneration.Filters;

var agent = new AgentBuilder()
    .WithModel(model)
    .WithPersona("Assistant")
    .WithFilters(filters =>
    {
        filters.PromptFilters.Add(new ModerationFilter());
        filters.CompletionFilters.Add(new QualityGateFilter());
        filters.AddToolInvocationFilter(async (ctx, next) =>
        {
            Console.WriteLine($"Tool: {ctx.ToolCall.Name}");
            await next(ctx);
        });
    })
    .Build();

Remarks

Filters execute in a middleware (onion) pattern: each filter wraps the next one. Code before await next(context) runs on the way in; code after runs on the way out. The execution order is determined by the order filters are added to the lists.

Assign a FilterPipeline to Filters for direct conversation usage, or configure it via AgentBuilder.WithFilters() for agent-based workflows.

Execution model with two prompt filters:

Prompt Filter 1 (before)
  Prompt Filter 2 (before)
    [inference]
  Prompt Filter 2 (after)
Prompt Filter 1 (after)

Properties

CompletionFilters

Gets the ordered list of completion filters.

PromptFilters

Gets the ordered list of prompt filters.

ToolInvocationFilters

Gets the ordered list of tool invocation filters.