Add core LlmPipeline base class

This commit is contained in:
2026-08-12 20:54:38 +02:00
parent 8d468903a4
commit 3f99bce3c6
2 changed files with 106 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
import type { Logger } from '../logging/logger';
import type { LlmTool } from './LlmTool';
import type { RunContext } from './RunContext';
import type { Tracer } from './Tracer';
export abstract class LlmPipeline<TInput, TOutput> {
constructor(
protected readonly tracer: Tracer,
protected readonly logger: Logger
) {}
protected abstract readonly name: string;
protected abstract runInternal(input: TInput, ctx: RunContext): Promise<TOutput>;
async runAsync(input: TInput): Promise<TOutput> {
const trace = this.tracer.startTrace(this.name);
const ctx: RunContext = { trace, logger: this.logger };
try {
return await this.runInternal(input, ctx);
} finally {
await this.tracer.flush();
}
}
protected runTool<TToolInput, TToolOutput>(
tool: LlmTool<TToolInput, TToolOutput>,
input: TToolInput,
ctx: RunContext
): Promise<TToolOutput> {
return tool.runAsync(input, ctx);
}
}