Home / File/ render.py — langchain Source File

render.py — langchain Source File

Architecture documentation for render.py, a python file in the langchain codebase. 3 imports, 0 dependents.

File python AgentOrchestration ActionLogic 3 imports 2 functions

Entity Profile

Dependency Diagram

graph LR
  f02b7602_69d7_9adf_ddea_892aea3802b0["render.py"]
  cfe2bde5_180e_e3b0_df2b_55b3ebaca8e7["collections.abc"]
  f02b7602_69d7_9adf_ddea_892aea3802b0 --> cfe2bde5_180e_e3b0_df2b_55b3ebaca8e7
  614e7b9f_ed51_0780_749c_ff40b74963fc["inspect"]
  f02b7602_69d7_9adf_ddea_892aea3802b0 --> 614e7b9f_ed51_0780_749c_ff40b74963fc
  17795dda_8689_7308_3ff9_4b900129bd10["langchain_core.tools.base"]
  f02b7602_69d7_9adf_ddea_892aea3802b0 --> 17795dda_8689_7308_3ff9_4b900129bd10
  style f02b7602_69d7_9adf_ddea_892aea3802b0 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

"""Utilities to render tools."""

from __future__ import annotations

from collections.abc import Callable
from inspect import signature

from langchain_core.tools.base import BaseTool

ToolsRenderer = Callable[[list[BaseTool]], str]


def render_text_description(tools: list[BaseTool]) -> str:
    """Render the tool name and description in plain text.

    Args:
        tools: The tools to render.

    Returns:
        The rendered text.

    Output will be in the format of:

    ```txt
    search: This tool is used for search
    calculator: This tool is used for math
    ```
    """
    descriptions = []
    for tool in tools:
        if hasattr(tool, "func") and tool.func:
            sig = signature(tool.func)
            description = f"{tool.name}{sig} - {tool.description}"
        else:
            description = f"{tool.name} - {tool.description}"

        descriptions.append(description)
    return "\n".join(descriptions)


def render_text_description_and_args(tools: list[BaseTool]) -> str:
    """Render the tool name, description, and args in plain text.

    Args:
        tools: The tools to render.

    Returns:
        The rendered text.

    Output will be in the format of:

    ```txt
    search: This tool is used for search, args: {"query": {"type": "string"}}
    calculator: This tool is used for math, \
    args: {"expression": {"type": "string"}}
    ```
    """
    tool_strings = []
    for tool in tools:
        args_schema = str(tool.args)
        if hasattr(tool, "func") and tool.func:
            sig = signature(tool.func)
            description = f"{tool.name}{sig} - {tool.description}"
        else:
            description = f"{tool.name} - {tool.description}"
        tool_strings.append(f"{description}, args: {args_schema}")
    return "\n".join(tool_strings)

Subdomains

Dependencies

  • collections.abc
  • inspect
  • langchain_core.tools.base

Frequently Asked Questions

What does render.py do?
render.py is a source file in the langchain codebase, written in python. It belongs to the AgentOrchestration domain, ActionLogic subdomain.
What functions are defined in render.py?
render.py defines 2 function(s): render_text_description, render_text_description_and_args.
What does render.py depend on?
render.py imports 3 module(s): collections.abc, inspect, langchain_core.tools.base.
Where is render.py in the architecture?
render.py is located at libs/core/langchain_core/tools/render.py (domain: AgentOrchestration, subdomain: ActionLogic, directory: libs/core/langchain_core/tools).

Analyze Your Own Codebase

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

Try Supermodel Free