Skip to main content

API Reference

Use this page when you already understand the concepts and need the current public surface at a glance.

Runnables

APIUse
Runnable<I, O>base contract with invoke and pipe
RunnableLambda<I, O>wrap sync or async custom logic
RunnableSequence<I, O>run steps in order
RunnableParallel<I, TMap>run branches from the same input concurrently
RunnableMap<I, TMap>build a named object from one input
RunnablePassthrough<T>return input unchanged
ModelRunnableadapt Model into a string -> string runnable

Prompts

PromptTemplate<TVars>

  • input: object of template variables
  • output: formatted prompt string
  • throws: PromptTemplateError when required variables are missing

Output Parsers

APIBehavior
StringOutputParserreturns raw text unchanged
JsonOutputParser<T>parses JSON text into typed output

JsonOutputParser<T> throws OutputParserError on invalid JSON.

Agent Runtime

Agent

new Agent({ model, tools, passes?, hooks?, maxSteps? })
agent.run(input: string): Promise<string>

Runtime behavior:

  • iterative model loop
  • tool execution when requested
  • memory context injection
  • max-step enforcement

Config details:

  • tools are registered by unique tool name
  • passes can transform interpreted instructions before execution
  • hooks.onStart(state) and hooks.onEnd(state, result) allow lifecycle instrumentation
  • maxSteps defaults to 20
  • runtimePolicy config:
    • modelTimeoutMs: max time for a model call
    • modelRetry.maxAttempts: number of model attempts (default 1)
    • modelRetry.backoffMs: linear backoff base between retries

Tools

tool(...)

tool({
name,
description,
schema, // zod schema
execute // async handler
})

Behavior:

  • args are validated against schema before execution
  • unknown tool names raise ToolNotFoundError
  • schema mismatch raises ToolValidationError

Workflows

Workflow

new Workflow({ steps })
workflow.run(input, { resumeFrom? })

Types:

  • WorkflowStep: { id, run, when? }
  • WorkflowSnapshot: captured per-step input/output metadata
  • WorkflowResumeState: replayable state with nextStepIndex, data, snapshots
  • WorkflowRunResult: { output, snapshots, resumeState }

Errors

  • ToolNotFoundError
  • ToolValidationError
  • ModelError
  • MaxStepsExceededError
  • PromptTemplateError
  • OutputParserError

Canonical code mapping and compatibility policy: error-codes.md Versioned runtime contract: core-contract-v0.1.md