pub trait Runnable<I, O>: Send + Sync{
// Required method
fn invoke<'life0, 'async_trait>(
&'life0 self,
input: I,
config: RunnableConfig,
) -> Pin<Box<dyn Future<Output = Result<O, CognisError>> + Send + 'async_trait>>
where 'life0: 'async_trait,
Self: 'async_trait;
// Provided methods
fn batch<'life0, 'async_trait>(
&'life0 self,
inputs: Vec<I>,
config: RunnableConfig,
) -> Pin<Box<dyn Future<Output = Result<Vec<O>, CognisError>> + Send + 'async_trait>>
where 'life0: 'async_trait,
I: 'static,
O: 'static,
Self: Sized + Sync + 'async_trait { ... }
fn stream<'life0, 'async_trait>(
&'life0 self,
input: I,
config: RunnableConfig,
) -> Pin<Box<dyn Future<Output = Result<RunnableStream<O>, CognisError>> + Send + 'async_trait>>
where 'life0: 'async_trait,
Self: Sized + Sync + 'async_trait { ... }
fn stream_events<'life0, 'async_trait>(
&'life0 self,
input: I,
config: RunnableConfig,
) -> Pin<Box<dyn Future<Output = Result<EventStream, CognisError>> + Send + 'async_trait>>
where 'life0: 'async_trait,
I: Serialize,
O: Serialize,
Self: Sized + Sync + 'async_trait { ... }
fn name(&self) -> &str { ... }
fn input_schema(&self) -> Option<Value> { ... }
fn output_schema(&self) -> Option<Value> { ... }
}Expand description
The unified contract every cognis primitive implements.
Generic over I (input) and O (output). One required method (invoke);
batch, stream, and stream_events have sensible defaults that
implementations override only when they can do better.
Required Methods§
Sourcefn invoke<'life0, 'async_trait>(
&'life0 self,
input: I,
config: RunnableConfig,
) -> Pin<Box<dyn Future<Output = Result<O, CognisError>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
fn invoke<'life0, 'async_trait>(
&'life0 self,
input: I,
config: RunnableConfig,
) -> Pin<Box<dyn Future<Output = Result<O, CognisError>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
One-shot invocation. The hot path.
Provided Methods§
Sourcefn batch<'life0, 'async_trait>(
&'life0 self,
inputs: Vec<I>,
config: RunnableConfig,
) -> Pin<Box<dyn Future<Output = Result<Vec<O>, CognisError>> + Send + 'async_trait>>
fn batch<'life0, 'async_trait>( &'life0 self, inputs: Vec<I>, config: RunnableConfig, ) -> Pin<Box<dyn Future<Output = Result<Vec<O>, CognisError>> + Send + 'async_trait>>
Run multiple inputs in parallel. Defaults to buffer_unordered
honouring config.max_concurrency.
Sourcefn stream<'life0, 'async_trait>(
&'life0 self,
input: I,
config: RunnableConfig,
) -> Pin<Box<dyn Future<Output = Result<RunnableStream<O>, CognisError>> + Send + 'async_trait>>
fn stream<'life0, 'async_trait>( &'life0 self, input: I, config: RunnableConfig, ) -> Pin<Box<dyn Future<Output = Result<RunnableStream<O>, CognisError>> + Send + 'async_trait>>
Stream the final output (chunks of O). Default emits one item via
invoke — non-streaming runnables are correct without override.
Sourcefn stream_events<'life0, 'async_trait>(
&'life0 self,
input: I,
config: RunnableConfig,
) -> Pin<Box<dyn Future<Output = Result<EventStream, CognisError>> + Send + 'async_trait>>
fn stream_events<'life0, 'async_trait>( &'life0 self, input: I, config: RunnableConfig, ) -> Pin<Box<dyn Future<Output = Result<EventStream, CognisError>> + Send + 'async_trait>>
Stream structured events. Default emits OnStart + OnEnd around an
invoke call. Graph engines override to surface per-node events.
Sourcefn input_schema(&self) -> Option<Value>
fn input_schema(&self) -> Option<Value>
JSON Schema for the input type, if known.
Sourcefn output_schema(&self) -> Option<Value>
fn output_schema(&self) -> Option<Value>
JSON Schema for the output type, if known.