pub struct Graph {
pub id: String,
/* private fields */
}Expand description
A graph of tasks that can be executed
Fields§
§id: StringImplementations§
Source§impl Graph
impl Graph
pub fn new(id: impl Into<String>) -> Self
Sourcepub fn set_task_timeout(&mut self, timeout: Duration)
pub fn set_task_timeout(&mut self, timeout: Duration)
Set the timeout duration for task execution
Sourcepub fn set_max_execution_steps(&mut self, max: Option<usize>)
pub fn set_max_execution_steps(&mut self, max: Option<usize>)
Set the maximum number of chained ContinueAndExecute steps allowed
within a single execute_session call. Guards against accidental
infinite loops in cyclic graphs. None means unlimited.
Sourcepub fn set_start_task(&self, task_id: impl Into<String>) -> &Self
pub fn set_start_task(&self, task_id: impl Into<String>) -> &Self
Set the starting task.
Logs a warning and leaves the current start task unchanged if the given task id has not been added to the graph.
Sourcepub fn add_edge(&self, from: impl Into<String>, to: impl Into<String>) -> &Self
pub fn add_edge(&self, from: impl Into<String>, to: impl Into<String>) -> &Self
Add an edge between tasks
Sourcepub fn add_conditional_edge<F>(
&self,
from: impl Into<String>,
condition: F,
yes: impl Into<String>,
no: impl Into<String>,
) -> &Self
pub fn add_conditional_edge<F>( &self, from: impl Into<String>, condition: F, yes: impl Into<String>, no: impl Into<String>, ) -> &Self
Add a conditional edge with an explicit else branch.
yes is taken when condition(ctx) returns true; otherwise no is chosen.
Sourcepub async fn execute_session(
&self,
session: &mut Session,
) -> Result<ExecutionResult>
pub async fn execute_session( &self, session: &mut Session, ) -> Result<ExecutionResult>
Execute the graph with session management.
Runs the session’s current task. If the task returns
NextAction::ContinueAndExecute, execution proceeds to the next task
within the same call, repeating until a task pauses, waits for input,
ends, or the configured max_execution_steps limit is hit.
Note: the session is only persisted by the caller (e.g.
crate::FlowRunner::run) after this method returns, so context
updates made by intermediate ContinueAndExecute steps are not durable
until the whole chain finishes.
Sourcepub async fn execute(
&self,
task_id: &str,
context: Context,
) -> Result<TaskResult>
👎Deprecated since 0.5.2: use execute_session (or FlowRunner::run) instead; this method’s NextAction semantics are inconsistent with the documented behavior and it will be removed in a future release
pub async fn execute( &self, task_id: &str, context: Context, ) -> Result<TaskResult>
use execute_session (or FlowRunner::run) instead; this method’s NextAction semantics are inconsistent with the documented behavior and it will be removed in a future release
Execute the graph starting from a specific task.
Note that this method’s NextAction semantics differ from
Graph::execute_session: Continue recurses into the next task when
the current task produced no response, and ContinueAndExecute stops.
Sourcepub fn find_next_task(
&self,
current_task_id: &str,
context: &Context,
) -> Option<String>
pub fn find_next_task( &self, current_task_id: &str, context: &Context, ) -> Option<String>
Find the next task based on edges and conditions
Sourcepub fn start_task_id(&self) -> Option<String>
pub fn start_task_id(&self) -> Option<String>
Get the start task ID
Auto Trait Implementations§
impl !Freeze for Graph
impl !RefUnwindSafe for Graph
impl !UnwindSafe for Graph
impl Send for Graph
impl Sync for Graph
impl Unpin for Graph
impl UnsafeUnpin for Graph
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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more