Documentation
Functions
createAIRunner

Function: createAIRunner()

createAIRunner<Content>(args): Runner<Content>

Creates a function to run a chat model in a loop

  • Handles parsing, running, and inserting responses for function & tool call messages
  • Handles errors by adding a message with the error and rerunning the model
  • Optionally validates the content of the last message

Type parameters

ParameterDefault
Content extends unknownstring

Parameters

ParameterTypeDescription
argsobject-
args.chatModelChatModelThe ChatModel used to make API calls.
args.context?CtxOptional context to pass to ChatModel.run calls
args.functionCallConcurrency?numberThe number of function calls to make concurrently.
args.functions?AIFunction<ZodObject<any, UnknownKeysParam, ZodTypeAny, object, object>, any>[]The functions the model can call.
args.maxIterations?numberThe maximum number of iterations before the runner throws an error. An iteration is a single call to the model/API.
args.mode?ModeControls whether functions or tool_calls are used.
args.params?Partial<Omit<Run & Config, "messages" | "functions" | "tools">>Model params to use for each API call (optional).
args.shouldBreakLoop?(msg) => boolean-
args.systemMessage?stringAdd a system message to the beginning of the messages array.
args.validateContent?(content) => Content | Promise<Content>-

Returns

Runner<Content>

Source

src/prompt/functions/ai-runner.ts:12 (opens in a new tab)