pub struct CompiledGraph<S: State> { /* private fields */ }Expand description
The compiled, executable graph.
Implementations§
Source§impl<S: State> CompiledGraph<S>
impl<S: State> CompiledGraph<S>
Sourcepub fn with_checkpointer(self, checkpointer: Arc<dyn Checkpointer>) -> Self
pub fn with_checkpointer(self, checkpointer: Arc<dyn Checkpointer>) -> Self
Set a checkpointer for state persistence.
Sourcepub fn context(&self) -> &GraphContext
pub fn context(&self) -> &GraphContext
Get the GraphContext for this compiled graph.
Nodes can use this context to issue dynamic control flow commands
(e.g., goto or end) that override normal edge-based routing.
Sourcepub async fn invoke(&self, state: S) -> Result<S, SynapseError>where
S: Serialize + DeserializeOwned,
pub async fn invoke(&self, state: S) -> Result<S, SynapseError>where
S: Serialize + DeserializeOwned,
Execute the graph with initial state.
Sourcepub async fn invoke_with_config(
&self,
state: S,
config: Option<CheckpointConfig>,
) -> Result<S, SynapseError>where
S: Serialize + DeserializeOwned,
pub async fn invoke_with_config(
&self,
state: S,
config: Option<CheckpointConfig>,
) -> Result<S, SynapseError>where
S: Serialize + DeserializeOwned,
Execute with optional checkpoint config for resumption.
Sourcepub fn stream(&self, state: S, mode: StreamMode) -> GraphStream<'_, S>
pub fn stream(&self, state: S, mode: StreamMode) -> GraphStream<'_, S>
Stream graph execution, yielding a GraphEvent after each node.
Sourcepub fn stream_with_config(
&self,
state: S,
_mode: StreamMode,
config: Option<CheckpointConfig>,
) -> GraphStream<'_, S>
pub fn stream_with_config( &self, state: S, _mode: StreamMode, config: Option<CheckpointConfig>, ) -> GraphStream<'_, S>
Stream graph execution with optional checkpoint config.
Sourcepub async fn update_state(
&self,
config: &CheckpointConfig,
update: S,
) -> Result<(), SynapseError>where
S: Serialize + DeserializeOwned,
pub async fn update_state(
&self,
config: &CheckpointConfig,
update: S,
) -> Result<(), SynapseError>where
S: Serialize + DeserializeOwned,
Update state on an interrupted graph (for human-in-the-loop).
Sourcepub async fn get_state(
&self,
config: &CheckpointConfig,
) -> Result<Option<S>, SynapseError>where
S: DeserializeOwned,
pub async fn get_state(
&self,
config: &CheckpointConfig,
) -> Result<Option<S>, SynapseError>where
S: DeserializeOwned,
Get the current state for a thread from the checkpointer.
Returns None if no checkpoint exists for the given thread.
Sourcepub async fn get_state_history(
&self,
config: &CheckpointConfig,
) -> Result<Vec<(S, Option<String>)>, SynapseError>where
S: DeserializeOwned,
pub async fn get_state_history(
&self,
config: &CheckpointConfig,
) -> Result<Vec<(S, Option<String>)>, SynapseError>where
S: DeserializeOwned,
Get the state history for a thread (all checkpoints).
Returns a list of (state, next_node) pairs, ordered from oldest to newest.
The next_node indicates which node was scheduled to execute next when
the checkpoint was saved.
Source§impl<S: State> CompiledGraph<S>
impl<S: State> CompiledGraph<S>
Sourcepub fn draw_mermaid(&self) -> String
pub fn draw_mermaid(&self) -> String
Render the graph as a Mermaid flowchart string.
__start__and__end__are rendered as rounded nodes([...])- User nodes are rendered as rectangles
[...] - Fixed edges use solid arrows
--> - Conditional edges with path_map use dashed arrows
-.->with labels - Conditional edges without path_map emit a Mermaid comment
Sourcepub fn draw_ascii(&self) -> String
pub fn draw_ascii(&self) -> String
Render the graph as a simple ASCII text summary.
Sourcepub async fn draw_mermaid_png(
&self,
path: impl AsRef<Path>,
) -> Result<(), SynapseError>
pub async fn draw_mermaid_png( &self, path: impl AsRef<Path>, ) -> Result<(), SynapseError>
Render the Mermaid diagram as an image via the mermaid.ink API.
Requires internet access. The generated Mermaid text is URL-safe base64-encoded
and sent to https://mermaid.ink/img/{encoded}. The image (JPEG format) is
written to the specified file path.
Note: mermaid.ink returns JPEG from the /img/ endpoint. For SVG output,
use draw_mermaid_svg instead.
Sourcepub async fn draw_mermaid_svg(
&self,
path: impl AsRef<Path>,
) -> Result<(), SynapseError>
pub async fn draw_mermaid_svg( &self, path: impl AsRef<Path>, ) -> Result<(), SynapseError>
Render the Mermaid diagram as an SVG image via the mermaid.ink API.
Requires internet access. The generated Mermaid text is URL-safe base64-encoded
and sent to https://mermaid.ink/svg/{encoded}. The SVG response is written
to the specified file path.
Sourcepub fn draw_png(&self, path: impl AsRef<Path>) -> Result<(), SynapseError>
pub fn draw_png(&self, path: impl AsRef<Path>) -> Result<(), SynapseError>
Render the graph as a PNG image using the Graphviz dot command.
Requires dot (Graphviz) to be installed and available in $PATH.
The DOT output is piped to dot -Tpng and the resulting PNG is written
to the specified file path.
Trait Implementations§
Source§impl<S: State> Debug for CompiledGraph<S>
impl<S: State> Debug for CompiledGraph<S>
Auto Trait Implementations§
impl<S> Freeze for CompiledGraph<S>
impl<S> !RefUnwindSafe for CompiledGraph<S>
impl<S> Send for CompiledGraph<S>
impl<S> Sync for CompiledGraph<S>
impl<S> Unpin for CompiledGraph<S>
impl<S> UnsafeUnpin for CompiledGraph<S>
impl<S> !UnwindSafe for CompiledGraph<S>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.