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

Method invoke

libs/core/langchain_core/runnables/base.py:2479–2512  ·  view source on GitHub ↗
(
        self, input: Input, config: Optional[RunnableConfig] = None, **kwargs: Any
    )

Source from the content-addressed store, hash-verified

2477 )
2478
2479 def invoke(
2480 self, input: Input, config: Optional[RunnableConfig] = None, **kwargs: Any
2481 ) -> Output:
2482 from langchain_core.beta.runnables.context import config_with_context
2483
2484 # setup callbacks and context
2485 config = config_with_context(ensure_config(config), self.steps)
2486 callback_manager = get_callback_manager_for_config(config)
2487 # start the root run
2488 run_manager = callback_manager.on_chain_start(
2489 dumpd(self),
2490 input,
2491 name=config.get("run_name") or self.get_name(),
2492 run_id=config.pop("run_id", None),
2493 )
2494
2495 # invoke all steps in sequence
2496 try:
2497 for i, step in enumerate(self.steps):
2498 # mark each step as a child run
2499 config = patch_config(
2500 config, callbacks=run_manager.get_child(f"seq:step:{i+1}")
2501 )
2502 if i == 0:
2503 input = step.invoke(input, config, **kwargs)
2504 else:
2505 input = step.invoke(input, config)
2506 # finish the root run
2507 except BaseException as e:
2508 run_manager.on_chain_error(e)
2509 raise
2510 else:
2511 run_manager.on_chain_end(input)
2512 return cast(Output, input)
2513
2514 async def ainvoke(
2515 self,

Callers

nothing calls this directly

Calls 13

config_with_contextFunction · 0.90
ensure_configFunction · 0.90
dumpdFunction · 0.90
patch_configFunction · 0.90
popMethod · 0.80
on_chain_startMethod · 0.45
getMethod · 0.45
get_nameMethod · 0.45
get_childMethod · 0.45
invokeMethod · 0.45
on_chain_errorMethod · 0.45

Tested by

no test coverage detected