Skip to main content

Crate takeln

Crate takeln 

Source
Expand description

§takeln

Typed Rust runtime for durable DAG-based agent workflows.

takeln is a lightweight, production-grade execution engine for Directed Acyclic Graphs (DAGs) in Rust. It provides built-in wave-based parallel scheduling, robust state checkpointing, retry policies, budget enforcement, and LLM metadata instrumentation.

§Feature Flags

FlagDefaultDescription
postgresNoEnables PostgresCheckpointer backed by PostgreSQL via sqlx
sqliteNoEnables SqliteCheckpointer backed by SQLite via rusqlite

§Quick Start

use async_trait::async_trait;
use takeln::{Graph, Node, NodeContext, NodeOutput, GraphError, InMemoryCheckpointer};

#[derive(Clone, serde::Serialize, serde::Deserialize, Default)]
struct MyState { value: String }

struct AppendNode { suffix: String }

#[async_trait]
impl Node<MyState> for AppendNode {
    async fn call(&self, _ctx: NodeContext, mut state: MyState) -> Result<NodeOutput<MyState>, GraphError> {
        state.value.push_str(&self.suffix);
        Ok(NodeOutput::bare(state))
    }
}

#[tokio::main]
async fn main() {
    let mut graph = Graph::new();
    graph.add_node("A", AppendNode { suffix: "Hello".to_string() });
    graph.add_node("B", AppendNode { suffix: " World".to_string() });
    graph.add_edge("A", "B");
    graph.add_edge("B", "__END__");

    let checkpointer = InMemoryCheckpointer::new();
    let state = graph.run("thread_1", MyState::default(), "A", &checkpointer, None).await.unwrap();
    assert_eq!(state.value, "Hello World");
}

Re-exports§

pub use checkpoint::Checkpointer;
pub use checkpoint_meta::CheckpointMeta;
pub use checkpoint_meta::CheckpointStatus;
pub use checkpoint_meta::CrashRecoveryPolicy;
pub use checkpoint_meta::RetentionPolicy;
pub use context::NodeContext;
pub use dag::DAGBuilder;
pub use dag::DAGNode;
pub use dag::NodeStatus;
pub use dag::DAG;
pub use dynamic::ChildRunner;
pub use dynamic::DynamicFnNode;
pub use dynamic::DynamicNode;
pub use emitter::NoopEmitter;
pub use emitter::SpanContext;
pub use emitter::SpanEmitter;
pub use emitter::SpanStatus;
pub use emitter::TracingEmitter;
pub use error::GraphError;
pub use error::TakelnError;
pub use graph::Edge;
pub use graph::FnNode;
pub use graph::Graph;
pub use graph::GraphBuilder;
pub use graph::GraphEvent;
pub use graph::Node;
pub use graph::NodeConfig;
pub use graph::NodeMeta;
pub use graph::NodeOutput;
pub use graph::RetryPolicy;
pub use graph::State;
pub use graph::WaveFailurePolicy;
pub use history::ExecutionRecord;
pub use hitl::ResumeContext;
pub use hitl::ResumeMode;
pub use hitl::ResumeRecord;
pub use hitl::YieldRequest;
pub use merge::Merge;
pub use metrics::MetricsHook;
pub use metrics::NoopMetricsHook;
pub use resource_limits::ResourceLimits;
pub use store::memory::InMemoryCheckpointer;
pub use store::postgres::PgPool;
pub use store::postgres::PostgresCheckpointer;
pub use store::sqlite::SqliteCheckpointer;

Modules§

checkpoint
checkpoint_meta
context
Execution context passed to every node invocation.
dag
dynamic
Dynamic node execution primitives.
emitter
error
graph
history
hitl
Structured Human-in-the-Loop (HITL) yield requests.
merge
metrics
resource_limits
Resource limits for graph execution.
store