MCPcopy
hub / github.com/langchain-ai/langchain / _invoke

Method _invoke

libs/core/langchain_core/runnables/base.py:3827–3869  ·  view source on GitHub ↗
(
        self,
        input: Input,
        run_manager: CallbackManagerForChainRun,
        config: RunnableConfig,
        **kwargs: Any,
    )

Source from the content-addressed store, hash-verified

3825 return "RunnableLambda(...)"
3826
3827 def _invoke(
3828 self,
3829 input: Input,
3830 run_manager: CallbackManagerForChainRun,
3831 config: RunnableConfig,
3832 **kwargs: Any,
3833 ) -> Output:
3834 if inspect.isgeneratorfunction(self.func):
3835 output: Optional[Output] = None
3836 for chunk in call_func_with_variable_args(
3837 cast(Callable[[Input], Iterator[Output]], self.func),
3838 input,
3839 config,
3840 run_manager,
3841 **kwargs,
3842 ):
3843 if output is None:
3844 output = chunk
3845 else:
3846 try:
3847 output = output + chunk # type: ignore[operator]
3848 except TypeError:
3849 output = chunk
3850 else:
3851 output = call_func_with_variable_args(
3852 self.func, input, config, run_manager, **kwargs
3853 )
3854 # If the output is a runnable, invoke it
3855 if isinstance(output, Runnable):
3856 recursion_limit = config["recursion_limit"]
3857 if recursion_limit <= 0:
3858 raise RecursionError(
3859 f"Recursion limit reached when invoking {self} with input {input}."
3860 )
3861 output = output.invoke(
3862 input,
3863 patch_config(
3864 config,
3865 callbacks=run_manager.get_child(),
3866 recursion_limit=recursion_limit - 1,
3867 ),
3868 )
3869 return cast(Output, output)
3870
3871 async def _ainvoke(
3872 self,

Callers

nothing calls this directly

Calls 4

patch_configFunction · 0.90
invokeMethod · 0.45
get_childMethod · 0.45

Tested by

no test coverage detected