Skip to main content

TaskNode

Trait TaskNode 

Source
pub trait TaskNode:
    Send
    + Sync
    + DynClone
    + Any {
    type Input: NodeArg;
    type Output: NodeArg;
    type Error: Error + Send + Sync + 'static;

    // Required method
    fn evaluate<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        node_id: &'life1 NodeId<dyn TaskNode<Error = Self::Error, Output = Self::Output, Input = Self::Input>>,
        input: &'life2 Self::Input,
    ) -> Pin<Box<dyn Future<Output = Result<Self::Output, Self::Error>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait,
             Self: 'async_trait;
}
Available on crate feature swiftide-tasks only.
Expand description

A typed step in a Task.

Implement this trait for your own domain-specific nodes when you want full control over how a task step runs. For lightweight closure nodes, use Task::register_node_fn, or Task::register_node_async_fn for async closures.

Required Associated Types§

Source

type Input: NodeArg

The input accepted by this node.

Source

type Output: NodeArg

The output produced by this node.

Source

type Error: Error + Send + Sync + 'static

The error returned when evaluation fails.

Required Methods§

Source

fn evaluate<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, node_id: &'life1 NodeId<dyn TaskNode<Error = Self::Error, Output = Self::Output, Input = Self::Input>>, input: &'life2 Self::Input, ) -> Pin<Box<dyn Future<Output = Result<Self::Output, Self::Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, Self: 'async_trait,

Evaluates the node with the current input.

Trait Implementations§

Source§

impl<Input, Output, Error> TaskNode for Box<dyn TaskNode<Error = Error, Output = Output, Input = Input>>
where Input: NodeArg, Output: NodeArg, Error: Error + Send + Sync + 'static,

Source§

type Input = Input

The input accepted by this node.
Source§

type Output = Output

The output produced by this node.
Source§

type Error = Error

The error returned when evaluation fails.
Source§

fn evaluate<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, node_id: &'life1 NodeId<dyn TaskNode<Error = <Box<dyn TaskNode<Error = Error, Output = Output, Input = Input>> as TaskNode>::Error, Output = <Box<dyn TaskNode<Error = Error, Output = Output, Input = Input>> as TaskNode>::Output, Input = <Box<dyn TaskNode<Error = Error, Output = Output, Input = Input>> as TaskNode>::Input>>, input: &'life2 <Box<dyn TaskNode<Error = Error, Output = Output, Input = Input>> as TaskNode>::Input, ) -> Pin<Box<dyn Future<Output = Result<<Box<dyn TaskNode<Error = Error, Output = Output, Input = Input>> as TaskNode>::Output, <Box<dyn TaskNode<Error = Error, Output = Output, Input = Input>> as TaskNode>::Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, Box<dyn TaskNode<Error = Error, Output = Output, Input = Input>>: 'async_trait,

Evaluates the node with the current input.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl TaskNode for Arc<dyn ChatCompletion>

Source§

type Input = ChatCompletionRequest<'static>

Source§

type Output = ChatCompletionResponse

Source§

type Error = LanguageModelError

Source§

fn evaluate<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, _node_id: &'life1 NodeId<dyn TaskNode<Error = <Arc<dyn ChatCompletion> as TaskNode>::Error, Output = <Arc<dyn ChatCompletion> as TaskNode>::Output, Input = <Arc<dyn ChatCompletion> as TaskNode>::Input>>, input: &'life2 <Arc<dyn ChatCompletion> as TaskNode>::Input, ) -> Pin<Box<dyn Future<Output = Result<<Arc<dyn ChatCompletion> as TaskNode>::Output, <Arc<dyn ChatCompletion> as TaskNode>::Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, Arc<dyn ChatCompletion>: 'async_trait,

Source§

impl TaskNode for Arc<dyn SimplePrompt>

Source§

type Input = Prompt

Source§

type Output = String

Source§

type Error = LanguageModelError

Source§

fn evaluate<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, _node_id: &'life1 NodeId<dyn TaskNode<Error = <Arc<dyn SimplePrompt> as TaskNode>::Error, Output = <Arc<dyn SimplePrompt> as TaskNode>::Output, Input = <Arc<dyn SimplePrompt> as TaskNode>::Input>>, input: &'life2 <Arc<dyn SimplePrompt> as TaskNode>::Input, ) -> Pin<Box<dyn Future<Output = Result<<Arc<dyn SimplePrompt> as TaskNode>::Output, <Arc<dyn SimplePrompt> as TaskNode>::Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, Arc<dyn SimplePrompt>: 'async_trait,

Source§

impl TaskNode for Arc<dyn ToolExecutor>

Source§

type Input = Command

Source§

type Output = CommandOutput

Source§

type Error = CommandError

Source§

fn evaluate<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, _node_id: &'life1 NodeId<dyn TaskNode<Error = <Arc<dyn ToolExecutor> as TaskNode>::Error, Output = <Arc<dyn ToolExecutor> as TaskNode>::Output, Input = <Arc<dyn ToolExecutor> as TaskNode>::Input>>, input: &'life2 <Arc<dyn ToolExecutor> as TaskNode>::Input, ) -> Pin<Box<dyn Future<Output = Result<<Arc<dyn ToolExecutor> as TaskNode>::Output, <Arc<dyn ToolExecutor> as TaskNode>::Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, Arc<dyn ToolExecutor>: 'async_trait,

Source§

impl TaskNode for Box<dyn ChatCompletion>

Source§

type Input = ChatCompletionRequest<'static>

Source§

type Output = ChatCompletionResponse

Source§

type Error = LanguageModelError

Source§

fn evaluate<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, _node_id: &'life1 NodeId<dyn TaskNode<Error = <Box<dyn ChatCompletion> as TaskNode>::Error, Output = <Box<dyn ChatCompletion> as TaskNode>::Output, Input = <Box<dyn ChatCompletion> as TaskNode>::Input>>, input: &'life2 <Box<dyn ChatCompletion> as TaskNode>::Input, ) -> Pin<Box<dyn Future<Output = Result<<Box<dyn ChatCompletion> as TaskNode>::Output, <Box<dyn ChatCompletion> as TaskNode>::Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, Box<dyn ChatCompletion>: 'async_trait,

Source§

impl TaskNode for Box<dyn SimplePrompt>

Source§

type Input = Prompt

Source§

type Output = String

Source§

type Error = LanguageModelError

Source§

fn evaluate<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, _node_id: &'life1 NodeId<dyn TaskNode<Error = <Box<dyn SimplePrompt> as TaskNode>::Error, Output = <Box<dyn SimplePrompt> as TaskNode>::Output, Input = <Box<dyn SimplePrompt> as TaskNode>::Input>>, input: &'life2 <Box<dyn SimplePrompt> as TaskNode>::Input, ) -> Pin<Box<dyn Future<Output = Result<<Box<dyn SimplePrompt> as TaskNode>::Output, <Box<dyn SimplePrompt> as TaskNode>::Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, Box<dyn SimplePrompt>: 'async_trait,

Source§

impl TaskNode for Box<dyn ToolExecutor>

Source§

type Input = Command

Source§

type Output = CommandOutput

Source§

type Error = CommandError

Source§

fn evaluate<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, _node_id: &'life1 NodeId<dyn TaskNode<Error = <Box<dyn ToolExecutor> as TaskNode>::Error, Output = <Box<dyn ToolExecutor> as TaskNode>::Output, Input = <Box<dyn ToolExecutor> as TaskNode>::Input>>, input: &'life2 <Box<dyn ToolExecutor> as TaskNode>::Input, ) -> Pin<Box<dyn Future<Output = Result<<Box<dyn ToolExecutor> as TaskNode>::Output, <Box<dyn ToolExecutor> as TaskNode>::Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, Box<dyn ToolExecutor>: 'async_trait,

Source§

impl<Input, Output, Error> TaskNode for Box<dyn TaskNode<Error = Error, Output = Output, Input = Input>>
where Input: NodeArg, Output: NodeArg, Error: Error + Send + Sync + 'static,

Source§

type Input = Input

Source§

type Output = Output

Source§

type Error = Error

Source§

fn evaluate<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, node_id: &'life1 NodeId<dyn TaskNode<Error = <Box<dyn TaskNode<Error = Error, Output = Output, Input = Input>> as TaskNode>::Error, Output = <Box<dyn TaskNode<Error = Error, Output = Output, Input = Input>> as TaskNode>::Output, Input = <Box<dyn TaskNode<Error = Error, Output = Output, Input = Input>> as TaskNode>::Input>>, input: &'life2 <Box<dyn TaskNode<Error = Error, Output = Output, Input = Input>> as TaskNode>::Input, ) -> Pin<Box<dyn Future<Output = Result<<Box<dyn TaskNode<Error = Error, Output = Output, Input = Input>> as TaskNode>::Output, <Box<dyn TaskNode<Error = Error, Output = Output, Input = Input>> as TaskNode>::Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, Box<dyn TaskNode<Error = Error, Output = Output, Input = Input>>: 'async_trait,

Implementors§

Source§

impl TaskNode for TaskAgent

Source§

impl<F, I, O, E> TaskNode for AsyncFn<F, I, O, E>
where F: for<'a> Fn(&'a I) -> Pin<Box<dyn Future<Output = Result<O, E>> + Send + 'a>> + Clone + Send + Sync + 'static, I: NodeArg + Clone, O: NodeArg + Clone, E: Error + Send + Sync + 'static,

Source§

type Input = I

Source§

type Output = O

Source§

type Error = E

Source§

impl<F, I, O, E> TaskNode for SyncFn<F, I, O, E>
where F: Fn(&I) -> Result<O, E> + Clone + Send + Sync + 'static, I: NodeArg + Clone, O: NodeArg + Clone, E: Error + Send + Sync + 'static,

Source§

type Input = I

Source§

type Output = O

Source§

type Error = E