import type { KtxModelRole } from '../../llm/types.js'; import type { z } from 'zod'; export interface KtxRuntimeToolOutput { markdown: string; structured?: TOutput; } export interface KtxRuntimeToolDescriptor { name: string; description: string; inputSchema: z.ZodObject; execute(input: TInput): Promise>; } export type KtxRuntimeToolSet = Record; export type RunLoopStopReason = 'budget' | 'natural' | 'error'; /** @internal */ export interface RunLoopStepInfo { stepIndex: number; stepBudget: number; } export interface RunLoopParams { modelRole: KtxModelRole; systemPrompt: string; userPrompt: string; toolSet: KtxRuntimeToolSet; stepBudget: number; telemetryTags: Record; onStepFinish?: (info: RunLoopStepInfo) => void | Promise; } export interface RunLoopResult { stopReason: RunLoopStopReason; error?: Error; } export interface KtxGenerateTextInput { role: KtxModelRole; prompt: string; system?: string; tools?: KtxRuntimeToolSet; temperature?: number; } export interface KtxGenerateObjectInput> { role: KtxModelRole; prompt: string; system?: string; tools?: KtxRuntimeToolSet; temperature?: number; schema: TSchema; } export interface KtxLlmRuntimePort { generateText(input: KtxGenerateTextInput): Promise; generateObject>( input: KtxGenerateObjectInput, ): Promise; runAgentLoop(params: RunLoopParams): Promise; } export interface AgentRunnerPort { runLoop(params: RunLoopParams): Promise; } export class RuntimeAgentRunner implements AgentRunnerPort { constructor(private readonly runtime: KtxLlmRuntimePort) {} runLoop(params: RunLoopParams): Promise { return this.runtime.runAgentLoop(params); } }