Skip to content

@aeye/core — Prompt

The Prompt class manages the full lifecycle of an AI interaction including template rendering, tool calling, output parsing, and retries.

Constructor

typescript
new Prompt<TContext, TMetadata, TName, TInput, TOutput, TTools>(input: PromptInput)

See Prompts component page for the full PromptInput configuration reference.

Properties

PropertyTypeDescription
kind'prompt'Component kind
nameTNamePrompt name
descriptionstringPrompt description
refsTToolsTool components
inputPromptInputFull configuration

Methods

get(mode?, input?, ctx?)

Convenient method to get output in various modes:

typescript
// Get structured result (waits for completion)
const result = await prompt.get('result', input, ctx);

// Get tool outputs
const tools = await prompt.get('tools', input, ctx);

// Stream all events
const stream = await prompt.get('stream', input, ctx);

// Stream tool events only
const toolStream = await prompt.get('streamTools', input, ctx);

// Stream text content only
const textStream = await prompt.get('streamContent', input, ctx);

Get Types

ModeReturn TypeDescription
'result'Promise<TOutput | undefined>Parsed structured output
'tools'Promise<PromptToolOutput[]>Array of tool results
'stream'AsyncGenerator<PromptEvent>All events
'streamTools'AsyncGenerator<PromptToolEvent>Tool events only
'streamContent'AsyncGenerator<string>Text chunks only

run(input?, ctx?)

Execute and stream all events:

typescript
for await (const event of prompt.run(input, ctx)) {
  // handle events
}

applicable(ctx?)

Check if the prompt is available in the given context.

metadata(input?, ctx?)

Get prompt metadata.

Events

Events emitted during run() / get('stream'):

EventValue TypeDescription
requestRequestAI request about to be sent
textPartialstringText chunk from streaming
textstringComplete text for this iteration
textCompletestringAll accumulated text
textResetstringText reset (error/retry)
refusalstringModel refusal message
reasonReasoningComplete reasoning trace
reasonPartialReasoningReasoning chunk
toolParseName{ id, name }Tool name parsed
toolParseArguments{ id, name, args }Tool args streaming
toolStart{ name, input }Tool execution starting
toolOutput{ tool, result }Tool completed
toolInterrupt{ tool, message }Tool interrupted
toolSuspend{ tool, message }Tool suspended prompt
toolError{ tool, error }Tool failed
messageMessageMessage added
completeTOutputFinal output
suspendstringPrompt suspended
requestUsageUsageUsage for this request
responseTokensnumberOutput token count
usageUsageFinal accumulated usage

Iteration Budget

maxIterations = outputRetries + forgetRetries + toolIterations + toolRetries + 1

Defaults: 2 + 1 + 3 + 2 + 1 = 9

Reconfiguration

The reconfig callback receives PromptReconfigInput:

typescript
interface PromptReconfigInput {
  iteration: number;
  maxIterations: number;
  toolParseErrors: number;
  toolCallErrors: number;
  toolSuccesses: number;
  toolRetries: number;
  outputRetries: number;
  forgetRetries: number;
  tools: Set<string>;
}

And can return PromptReconfig:

typescript
interface PromptReconfig {
  config?: Partial<Request>;
  maxIterations?: number;  // 0 = stop immediately, >0 = iterations from now
  toolRetries?: number;
  outputRetries?: number;
  forgetRetries?: number;
}

Released under the GPL-3.0 License.