Home / Function/ run() — langchain Function Reference

run() — langchain Function Reference

Architecture documentation for the run() function in base.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  51b059af_20e0_9233_077d_cd590dd94dc8["run()"]
  5ebe56ae_0ac8_cb13_b5a9_ee567b924009["BaseTool"]
  51b059af_20e0_9233_077d_cd590dd94dc8 -->|defined in| 5ebe56ae_0ac8_cb13_b5a9_ee567b924009
  ede8808b_c1b5_3ed7_439d_90ebc56dd263["invoke()"]
  ede8808b_c1b5_3ed7_439d_90ebc56dd263 -->|calls| 51b059af_20e0_9233_077d_cd590dd94dc8
  fa82d3e5_c342_0a6d_3c6f_5aa889ad3f2a["_filter_injected_args()"]
  51b059af_20e0_9233_077d_cd590dd94dc8 -->|calls| fa82d3e5_c342_0a6d_3c6f_5aa889ad3f2a
  89d802c7_d6ac_3fc5_68f4_5fa72c2afc76["_to_args_and_kwargs()"]
  51b059af_20e0_9233_077d_cd590dd94dc8 -->|calls| 89d802c7_d6ac_3fc5_68f4_5fa72c2afc76
  0ebf9c8b_48e0_ffff_f656_8876be0326eb["_get_runnable_config_param()"]
  51b059af_20e0_9233_077d_cd590dd94dc8 -->|calls| 0ebf9c8b_48e0_ffff_f656_8876be0326eb
  7cfccf7f_59e7_df70_47a7_ac13e2b6d05d["_handle_validation_error()"]
  51b059af_20e0_9233_077d_cd590dd94dc8 -->|calls| 7cfccf7f_59e7_df70_47a7_ac13e2b6d05d
  5674464e_53c8_8ac6_8d4a_eca7e0803115["_handle_tool_error()"]
  51b059af_20e0_9233_077d_cd590dd94dc8 -->|calls| 5674464e_53c8_8ac6_8d4a_eca7e0803115
  4c39dba4_e991_3a3f_7dc3_2908930c9cf5["_format_output()"]
  51b059af_20e0_9233_077d_cd590dd94dc8 -->|calls| 4c39dba4_e991_3a3f_7dc3_2908930c9cf5
  style 51b059af_20e0_9233_077d_cd590dd94dc8 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/core/langchain_core/tools/base.py lines 877–1003

    def run(
        self,
        tool_input: str | dict[str, Any],
        verbose: bool | None = None,  # noqa: FBT001
        start_color: str | None = "green",
        color: str | None = "green",
        callbacks: Callbacks = None,
        *,
        tags: list[str] | None = None,
        metadata: dict[str, Any] | None = None,
        run_name: str | None = None,
        run_id: uuid.UUID | None = None,
        config: RunnableConfig | None = None,
        tool_call_id: str | None = None,
        **kwargs: Any,
    ) -> Any:
        """Run the tool.

        Args:
            tool_input: The input to the tool.
            verbose: Whether to log the tool's progress.
            start_color: The color to use when starting the tool.
            color: The color to use when ending the tool.
            callbacks: Callbacks to be called during tool execution.
            tags: Optional list of tags associated with the tool.
            metadata: Optional metadata associated with the tool.
            run_name: The name of the run.
            run_id: The id of the run.
            config: The configuration for the tool.
            tool_call_id: The id of the tool call.
            **kwargs: Keyword arguments to be passed to tool callbacks (event handler)

        Returns:
            The output of the tool.

        Raises:
            ToolException: If an error occurs during tool execution.
        """
        callback_manager = CallbackManager.configure(
            callbacks,
            self.callbacks,
            self.verbose or bool(verbose),
            tags,
            self.tags,
            metadata,
            self.metadata,
        )

        # Filter out injected arguments from callback inputs
        filtered_tool_input = (
            self._filter_injected_args(tool_input)
            if isinstance(tool_input, dict)
            else None
        )

        # Use filtered inputs for the input_str parameter as well
        tool_input_str = (
            tool_input
            if isinstance(tool_input, str)
            else str(
                filtered_tool_input if filtered_tool_input is not None else tool_input
            )
        )

        run_manager = callback_manager.on_tool_start(
            {"name": self.name, "description": self.description},
            tool_input_str,
            color=start_color,
            name=run_name,
            run_id=run_id,
            inputs=filtered_tool_input,
            tool_call_id=tool_call_id,
            **kwargs,
        )

        content = None
        artifact = None
        status = "success"
        error_to_raise: Exception | KeyboardInterrupt | None = None
        try:
            child_config = patch_config(config, callbacks=run_manager.get_child())

Subdomains

Called By

Frequently Asked Questions

What does run() do?
run() is a function in the langchain codebase, defined in libs/core/langchain_core/tools/base.py.
Where is run() defined?
run() is defined in libs/core/langchain_core/tools/base.py at line 877.
What does run() call?
run() calls 6 function(s): _filter_injected_args, _format_output, _get_runnable_config_param, _handle_tool_error, _handle_validation_error, _to_args_and_kwargs.
What calls run()?
run() is called by 1 function(s): invoke.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free