Expand description
§Blazen
A high-performance, event-driven workflow framework for Rust.
Blazen models computation as a directed graph of steps connected by
typed events. The runtime maintains an internal event queue, routing
events to matching step handlers and spawning them concurrently until a
StopEvent terminates the workflow.
§Quick start
ⓘ
use blazen::prelude::*;
#[derive(Debug, Clone, Serialize, Deserialize, Event)]
struct GreetEvent { name: String }
#[step]
async fn greet(event: StartEvent, _ctx: Context) -> Result<StopEvent, WorkflowError> {
let name = event.data["name"].as_str().unwrap_or("World");
Ok(StopEvent { result: serde_json::json!({ "greeting": format!("Hello, {}!", name) }) })
}
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let workflow = WorkflowBuilder::new("greeter")
.step(greet_registration())
.build()?;
let result = workflow.run(serde_json::json!({ "name": "Zach" })).await?.result().await?;
println!("{}", result.to_json());
Ok(())
}§Feature flags
| Feature | Description |
|---|---|
llm (default) | LLM provider integrations |
openai | OpenAI + OpenAI-compatible providers |
anthropic | Anthropic Claude provider |
persist | Checkpoint storage via redb |
telemetry | Observability, tracing spans, and workflow history |
all | Everything |
Re-exports§
pub use serde;pub use serde_json;
Modules§
- llm
- LLM provider integrations (requires
llmfeature). - prelude
- Convenient wildcard import for common types and traits.
Structs§
- Bytes
Wrapper - Wrapper around
Vec<u8>that usesserde_bytesfor efficient binary serialization (especially withMessagePack). - Context
- Shared workflow context.
- Dynamic
Event - A type-erased event that carries its type name and payload as JSON.
- Event
Envelope - Wraps an event with metadata for the internal queue.
- Input
Request Event - Emitted by a step to request human input. Triggers auto-pause.
- Input
Response Event - The human’s response, injected on resume.
- Start
Event - Emitted to kick off a workflow with arbitrary JSON data.
- Step
Registration - Metadata about a registered step, including its handler function.
- Stop
Event - Emitted to signal that a workflow has completed with a result.
- Workflow
- A validated, ready-to-run workflow.
- Workflow
Builder - Fluent builder for constructing a
Workflow. - Workflow
Handler - Handle to a running workflow.
Enums§
- State
Value - A value that can be stored in the workflow context state map.
- Step
Output - The result of a step execution.
- Workflow
Error - Errors produced by the workflow engine.
Traits§
Functions§
- intern_
event_ type - Intern a dynamic event type name, returning a
&'static str. - register_
event_ deserializer - Register a deserializer function for a given event type string.
- try_
deserialize_ event - Attempt to deserialize a JSON value into a concrete event type using the registry.
Type Aliases§
- Input
Handler Fn - Async callback for handling input requests inline (without pausing).
- Result
- Convenience alias for
Result<T, WorkflowError>. - StepFn
- Type-erased async step function.
Attribute Macros§
- step
#[step]attribute macro that generates a step registration function alongside the original async function.
Derive Macros§
- Event
- Derive macro that generates a
blazen_events::Eventtrait implementation.