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§
Sourcefn input_keys(&self) -> Vec<&str>
fn input_keys(&self) -> Vec<&str>
Get input keys.
Sourcefn output_keys(&self) -> Vec<&str>
fn output_keys(&self) -> Vec<&str>
Get output keys.
Provided Methods§
Sourcefn 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 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 delegates to invoke() without config,
so chains that don’t need callback support work automatically.
Chains that want to propagate callbacks (on_chain_start/end, on_llm_start/end) should override this method.
Sourcefn 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<'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
Sourcefn 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 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 delegates to stream() without config.
Sourcefn validate_inputs(
&self,
inputs: &HashMap<String, Value>,
) -> Result<(), ChainError>
fn validate_inputs( &self, inputs: &HashMap<String, Value>, ) -> Result<(), ChainError>
Validate inputs.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".