Skip to main content

BaseChain

Trait BaseChain 

Source
pub trait BaseChain: Send + Sync {
    // Required methods
    fn input_keys(&self) -> Vec<&str>;
    fn output_keys(&self) -> Vec<&str>;
    fn invoke<'life0, 'async_trait>(
        &'life0 self,
        inputs: HashMap<String, Value>,
    ) -> Pin<Box<dyn Future<Output = Result<ChainResult, ChainError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;

    // Provided methods
    fn invoke_with_config<'life0, 'async_trait>(
        &'life0 self,
        inputs: HashMap<String, Value>,
        config: Option<RunnableConfig>,
    ) -> Pin<Box<dyn Future<Output = Result<ChainResult, ChainError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
    fn stream<'life0, 'async_trait>(
        &'life0 self,
        inputs: HashMap<String, Value>,
    ) -> Pin<Box<dyn Future<Output = Result<ChainStream, ChainError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
    fn stream_with_config<'life0, 'async_trait>(
        &'life0 self,
        inputs: HashMap<String, Value>,
        config: Option<RunnableConfig>,
    ) -> Pin<Box<dyn Future<Output = Result<ChainStream, ChainError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
    fn validate_inputs(
        &self,
        inputs: &HashMap<String, Value>,
    ) -> Result<(), ChainError> { ... }
    fn name(&self) -> &str { ... }
}
Expand description

Base Chain trait.

Chain is LangChain’s core abstraction, representing a sequence of operations.

Required Methods§

Source

fn input_keys(&self) -> Vec<&str>

Get input keys.

Source

fn output_keys(&self) -> Vec<&str>

Get output keys.

Source

fn invoke<'life0, 'async_trait>( &'life0 self, inputs: HashMap<String, Value>, ) -> Pin<Box<dyn Future<Output = Result<ChainResult, ChainError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Execute the Chain.

§Arguments
  • inputs - Input parameter dictionary
§Returns

Output result dictionary

Provided Methods§

Source

fn invoke_with_config<'life0, 'async_trait>( &'life0 self, inputs: HashMap<String, Value>, config: Option<RunnableConfig>, ) -> Pin<Box<dyn Future<Output = Result<ChainResult, ChainError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Execute the Chain with a RunnableConfig.

This method propagates callbacks through the chain execution. The default implementation wraps invoke() with on_chain_start / on_chain_end (or on_chain_error) dispatch, so config.callbacks are never silently dropped — even for chains that don’t override this method.

Chains that want to propagate LLM callbacks (on_llm_start/end) or thread config into sub-chains (SequentialChain / RouterChain) override this method.

Source

fn stream<'life0, 'async_trait>( &'life0 self, inputs: HashMap<String, Value>, ) -> Pin<Box<dyn Future<Output = Result<ChainStream, ChainError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Stream execute the Chain – token by token output.

Default implementation wraps the invoke result as a single-element stream. Chains that support LLM streaming (LLMChain / ConversationChain) should override this method, calling BaseChatModel::stream_chat internally.

§Arguments
  • inputs - Input parameter dictionary
§Returns

Token stream

Source

fn stream_with_config<'life0, 'async_trait>( &'life0 self, inputs: HashMap<String, Value>, config: Option<RunnableConfig>, ) -> Pin<Box<dyn Future<Output = Result<ChainStream, ChainError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Stream execute the Chain with a RunnableConfig.

The default implementation wraps stream() with on_chain_start and dispatches on_chain_end (or on_chain_error) once the token stream completes, so config.callbacks are never silently dropped.

Source

fn validate_inputs( &self, inputs: &HashMap<String, Value>, ) -> Result<(), ChainError>

Validate inputs.

Source

fn name(&self) -> &str

Get Chain name.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§