Skip to main content

User Guide

Choose A Workflow Style

NeedUse
fixed input-to-output pipelinechain
resumable multi-step business flowWorkflow
model may need external actionsagent
multiple named values from one inputRunnableMap
independent branchesRunnableParallel
provider model inside a chainModelRunnable

Chains

Use chains for predictable workflows such as extraction, classification, rewriting, and structured generation.

Typical shape:

input -> prompt -> model -> parser

Agents

Use agents when a response may require one or more tool calls before completion.

Typical shape:

user input -> model -> tool call or final response -> repeat until final

Workflows

Use Workflow when you need explicit step checkpoints and resumability.

Typical shape:

input -> step-1 -> step-2 -> ... -> output

Workflow gives you:

  • step snapshots with per-step input/output
  • resumeState for continuing partially completed runs
  • optional when(...) conditions for step-level branching

Use Workflow for operational/business orchestration and use runnables/chains for model-centric transformations.

Hooks And Passes

Use agent hooks for lifecycle instrumentation:

  • hooks.onStart(state)
  • hooks.onEnd(state, result)

Use instruction passes when you need to inspect or transform interpreted agent instructions before execution.

Error Handling

Framework errors include:

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

Handle them at the application boundary and convert them into user-safe responses as needed.

Testing

  • test runnables independently
  • test parser output shape
  • test tool validation failures
  • keep end-to-end examples for core flows