Skip to main content

Crate blazen

Crate blazen 

Source
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

FeatureDescription
llm (default)LLM provider integrations
openaiOpenAI + OpenAI-compatible providers
anthropicAnthropic Claude provider
persistCheckpoint storage via redb
telemetryObservability, tracing spans, and workflow history
allEverything

Re-exports§

pub use serde;
pub use serde_json;

Modules§

llm
LLM provider integrations (requires llm feature).
prelude
Convenient wildcard import for common types and traits.

Structs§

BytesWrapper
Wrapper around Vec<u8> that uses serde_bytes for efficient binary serialization (especially with MessagePack).
Context
Shared workflow context.
DynamicEvent
A type-erased event that carries its type name and payload as JSON.
EventEnvelope
Wraps an event with metadata for the internal queue.
InputRequestEvent
Emitted by a step to request human input. Triggers auto-pause.
InputResponseEvent
The human’s response, injected on resume.
StartEvent
Emitted to kick off a workflow with arbitrary JSON data.
StepRegistration
Metadata about a registered step, including its handler function.
StopEvent
Emitted to signal that a workflow has completed with a result.
Workflow
A validated, ready-to-run workflow.
WorkflowBuilder
Fluent builder for constructing a Workflow.
WorkflowHandler
Handle to a running workflow.

Enums§

StateValue
A value that can be stored in the workflow context state map.
StepOutput
The result of a step execution.
WorkflowError
Errors produced by the workflow engine.

Traits§

AnyEvent
Type-erased event for the internal event queue.
Event
The core routing trait.

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§

InputHandlerFn
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::Event trait implementation.