User Guide
Core Concepts
- Runnable: a unit with
invoke+pipe. - Chain: composition of runnables into deterministic pipelines.
- PromptTemplate: runtime prompt formatting using named placeholders.
- OutputParser: conversion from raw model text into structured outputs.
- Agent Runtime: iterative loop that can execute tools and continue until final response.
Choosing the Right Primitive
- Use
RunnableLambdafor custom transformation logic. - Use
RunnableMapwhen one input needs multiple named derived values. - Use
RunnableParallelfor independent branches that can run concurrently. - Use
RunnablePassthroughwhen downstream stage needs the original input unchanged. - Use
ModelRunnablewhen adapting a provider model into runnable pipelines.
Error Handling Pattern
The framework exposes explicit error types:
ModelErrorToolNotFoundErrorToolValidationErrorMaxStepsExceededErrorPromptTemplateErrorOutputParserError
Recommended pattern:
- catch framework errors at application boundary
- map to user-safe messages
- log full error and
causefor diagnostics
Testing Recommendations
- Unit test each runnable in isolation.
- Add contract tests for chain behavior and parser guarantees.
- Keep one golden-path example that always compiles and runs.