Skip to main content

Callable

Trait Callable 

Source
pub trait Callable: Send + Sync {
    // Required methods
    fn name(&self) -> &str;
    fn run<'life0, 'life1, 'async_trait>(
        &'life0 self,
        input: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<String>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;

    // Provided methods
    fn description(&self) -> Option<&str> { ... }
    fn run_streaming<'life0, 'life1, 'async_trait>(
        &'life0 self,
        input: &'life1 str,
        event_tx: Sender<StreamEvent>,
    ) -> Pin<Box<dyn Future<Output = Result<String>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn last_usage(&self) -> Option<LlmTokenUsage> { ... }
}
Expand description

Core Callable trait - the fundamental execution unit

Everything that can be “run” implements this trait:

  • LLM agents
  • Graph nodes
  • Tools (when wrapped)
  • Flow compositions

§Design Principles

  1. Simple: Just run with input, get output
  2. Async: All execution is async by default
  3. Named: Every callable has a name for logging/debugging
  4. Composable: Callables can wrap other callables

Required Methods§

Source

fn name(&self) -> &str

Callable logical name (for logging, debugging, UI)

Source

fn run<'life0, 'life1, 'async_trait>( &'life0 self, input: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<String>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Execute the callable with the given input

This is the core execution method. Implementations should:

  • Be idempotent when possible
  • Handle their own retries if needed
  • Return meaningful error messages

Provided Methods§

Source

fn description(&self) -> Option<&str>

Callable description (optional, for documentation)

Source

fn run_streaming<'life0, 'life1, 'async_trait>( &'life0 self, input: &'life1 str, event_tx: Sender<StreamEvent>, ) -> Pin<Box<dyn Future<Output = Result<String>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Execute with streaming events forwarded to the given sender.

Default implementation ignores the sender and calls run(). LLM/agent callables should override to poll their event emitter and forward events to event_tx while running.

Source

fn last_usage(&self) -> Option<LlmTokenUsage>

Token usage from the last successful run, if available.

LLM-backed callables may set this from provider usage metadata; others return None. The runner uses this for accurate cost tracking when present, otherwise falls back to estimates.

Implementors§