pub fn compile_entrypoint<S: State + Default, I, O, F>(
func: F,
checkpointer: Option<Arc<dyn CheckpointSaver>>,
) -> Result<CompiledGraph<S, I, O>, TopologyError>Expand description
Compile a functional workflow entrypoint into an executable graph
This function wraps a simple async function in a StateGraph with a
single entrypoint node, providing a functional API alternative to manual
graph construction.
§Type Parameters
S- State typeI- Input type (must implementIntoState<S>)O- Output type (must implementFromState<S>)F- Function type (must implementIntoNode<S>)
§Parameters
func- The entrypoint function to compilecheckpointer- Optional checkpoint saver for state persistence
§Returns
A compiled graph that can be invoked with CompiledGraph::invoke
or streamed with CompiledGraph::stream.
§Errors
Returns TopologyError if:
- The function cannot be converted into a node
- The graph structure is invalid
§Examples
§Basic usage
ⓘ
use juncture_core::func::compile_entrypoint;
use juncture_core::checkpoint::MemorySaver;
use juncture_core::state::CowState;
use juncture_core::runtime::Runtime as CoreRuntime;
use juncture_core::JunctureError;
async fn my_workflow(
state: CowState<MyState>,
runtime: &CoreRuntime<MyState>,
) -> Result<MyStateUpdate, JunctureError> {
Ok(MyStateUpdate::default())
}
let graph = compile_entrypoint::<MyState, Input, Output, _>(
my_workflow,
Some(Arc::new(MemorySaver::new()))
)?;
let result = graph.invoke(input, &config).await?;§With task configuration
ⓘ
use juncture_core::func::compile_entrypoint_with_config;
use juncture_core::config::TaskConfig;
use juncture_core::graph::{RetryPolicy, NodeMetadata};
use std::time::Duration;
let retry_policy = RetryPolicy::max_attempts(3);
let task_config = TaskConfig {
retry_policy: Some(retry_policy.clone()),
cache_policy: None,
timeout: Some(Duration::from_secs(30)),
name: Some("my_workflow".to_string()),
};
let graph = compile_entrypoint_with_config(
my_workflow,
&task_config,
Some(Arc::new(MemorySaver::new()))
)?;