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
Parameter | Default |
---|---|
Content extends unknown | string |
Parameters
Parameter | Type | Description |
---|---|---|
args | object | - |
args.chatModel | ChatModel | The ChatModel used to make API calls. |
args.context ? | Ctx | Optional context to pass to ChatModel.run calls |
args.functionCallConcurrency ? | number | The 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 ? | number | The maximum number of iterations before the runner throws an error. An iteration is a single call to the model/API. |
args.mode ? | Mode | Controls 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 ? | string | Add a system message to the beginning of the messages array. |
args.validateContent ? | (content ) => Content | Promise <Content > | - |
Returns
Runner
<Content
>