Skip to main content

Module func

Module func 

Source
Expand description

Functional API for defining workflows with plain functions

This module provides the functional entrypoint/task API as an alternative to StateGraph. Users can define workflows using ordinary async functions with runtime context instead of manually building graphs.

§Concepts

  • Entrypoint functions - Main workflow functions that can be compiled into graphs
  • Task configuration - Reusable functions with retry/cache/timeout policies
  • Runtime<S> - Provides access to previous state, checkpointer, and store

§Architecture

The functional API is a lightweight wrapper around StateGraph:

  • Entrypoint functions compile to single-node graphs
  • Task functions use TaskConfig for per-node configuration
  • Runtime<S> provides the same context as CoreRuntime with additional functional-API-specific features

§Example

use juncture_core::func::{compile_entrypoint, Runtime};
use juncture_core::checkpoint::MemorySaver;
use juncture_core::state::CowState;
use juncture_core::runtime::Runtime as CoreRuntime;

// Define the workflow function
async fn my_workflow(
    state: CowState<MyState>,
    runtime: &CoreRuntime<MyState>,
) -> Result<MyStateUpdate, JunctureError> {
    Ok(MyStateUpdate::default())
}

// Compile into a graph
let graph = compile_entrypoint::<MyState, Input, Output, _>(
    my_workflow,
    Some(Arc::new(MemorySaver::new()))
)?;

// Execute
let result = graph.invoke(input, &config).await?;

Structs§

Runtime
Runtime context for functional API workflows

Functions§

compile_entrypoint
Compile a functional workflow entrypoint into an executable graph
compile_entrypoint_with_config
Compile a functional workflow entrypoint with task configuration