Getting Started with Workflows
Learn how to use LlamaIndex's lightweight workflow engine for TypeScript
Workflows are a simple and lightweight engine for TypeScript. Built with ❤️ by LlamaIndex.
- Minimal core API (<=2kb)
- 100% Type safe
- Event-driven, stream oriented programming
- Support for multiple JS runtimes/frameworks
Installation
Install the package directly:
Key Concepts
- Events: Data carriers that flow through the workflow
- Handlers: Functions that process events and emit new events
- Workflow: Connects events and handlers together
- Context: Runtime environment for a workflow execution
Basic Usage
Let's build a simple workflow that processes a text input:
1. Define events
First, we need to define the events that will flow through our workflow:
2. Create a workflow and connect events
Next, we'll create our workflow and define how events are processed:
3. Run the workflow
Finally, we can execute our workflow. You can process the event stream directly or use utilities.
Using node:stream/promises
:
:::note
This may require setting "lib": ["ES2022", "DOM", "DOM.Iterable", "DOM.AsyncIterable"],
and "module": "NodeNext"
or similar in your tsconfig.json
to use top-level await
and pipeline
.
:::
Using Stream Utilities:
Ready to learn more? Check out our detailed examples to see workflows in action!