Store Chat Messages & State Without Managing Infrastructure.Check Out DialogueDB
Skip to content

Executor Options ​

Creation Options ​

When creating an executor with createLlmExecutor, you pass two arguments:

  1. Configuration object — the LLM, prompt, parser, and optional state
  2. Options object (optional) — hooks and other settings
typescript
import { useLlm, createChatPrompt, createParser, createLlmExecutor } from "llm-exe";

const executor = createLlmExecutor(
  {
    llm: useLlm("openai.gpt-4o-mini"),
    prompt: createChatPrompt("Summarize: {{text}}"),
    parser: createParser("string"),
  },
  {
    hooks: {
      onSuccess: (exec) => console.log("Result:", exec.output),
      onError: (exec) => console.error("Error:", exec.errorMessage),
      onComplete: (exec) => console.log(`Done in ${exec.end - exec.start}ms`),
    },
  }
);

Configuration ​

OptionTypeRequiredDescription
llmBaseLlmYesLLM instance created with useLlm()
promptBasePromptYesPrompt instance, or a function that returns one
parserBaseParserNoParser instance. Defaults to string parser if not provided
stateBaseStateNoState instance for managing dialogue and context
namestringNoName for the executor, used in tracing and metadata

Hooks ​

See Hooks for full documentation on available hooks.

Execute Options ​

When calling executor.execute(), you can optionally pass a second argument with execution-time options:

typescript
const result = await executor.execute(
  { text: "Hello world" },
  { jsonSchema: mySchema }
);
OptionTypeDescription
jsonSchemaRecord<string, any>JSON schema to pass to the LLM for structured output