Skip to content

file_tools

langroid/agent/tools/file_tools.py

ReadFileTool

Bases: ToolMessage

create(get_curr_dir) classmethod

Create a subclass of ReadFileTool for a specific directory

Parameters:

Name Type Description Default
get_curr_dir callable

A function that returns the current directory.

required

Returns:

Type Description
Type[ReadFileTool]

Type[ReadFileTool]: A subclass of the ReadFileTool class, specifically for the current directory.

Source code in langroid/agent/tools/file_tools.py
@classmethod
def create(
    cls,
    get_curr_dir: Callable[[], str] | None,
) -> Type["ReadFileTool"]:
    """
    Create a subclass of ReadFileTool for a specific directory

    Args:
        get_curr_dir (callable): A function that returns the current directory.

    Returns:
        Type[ReadFileTool]: A subclass of the ReadFileTool class, specifically
            for the current directory.
    """

    class CustomReadFileTool(cls):  # type: ignore
        _curr_dir: Callable[[], str] | None = (
            staticmethod(get_curr_dir) if get_curr_dir else None
        )

    return CustomReadFileTool

WriteFileTool

Bases: XMLToolMessage

create(get_curr_dir, get_git_repo) classmethod

Create a subclass of WriteFileTool with the current directory and git repo.

Parameters:

Name Type Description Default
get_curr_dir callable

A function that returns the current directory.

required
get_git_repo callable

A function that returns the git repo.

required

Returns:

Type Description
Type[WriteFileTool]

Type[WriteFileTool]: A subclass of the WriteFileTool class, specifically for the current directory and git repo.

Source code in langroid/agent/tools/file_tools.py
@classmethod
def create(
    cls,
    get_curr_dir: Callable[[], str] | None,
    get_git_repo: Callable[[], str] | None,
) -> Type["WriteFileTool"]:
    """
    Create a subclass of WriteFileTool with the current directory and git repo.

    Args:
        get_curr_dir (callable): A function that returns the current directory.
        get_git_repo (callable): A function that returns the git repo.

    Returns:
        Type[WriteFileTool]: A subclass of the WriteFileTool class, specifically
            for the current directory and git repo.
    """

    class CustomWriteFileTool(cls):  # type: ignore
        _curr_dir: Callable[[], str] | None = (
            staticmethod(get_curr_dir) if get_curr_dir else None
        )
        _git_repo: Callable[[], str] | None = (
            staticmethod(get_git_repo) if get_git_repo else None
        )

    return CustomWriteFileTool

ListDirTool

Bases: ToolMessage

create(get_curr_dir) classmethod

Create a subclass of ListDirTool for a specific directory

Parameters:

Name Type Description Default
get_curr_dir callable

A function that returns the current directory.

required

Returns:

Type Description
Type[ReadFileTool]

Type[ReadFileTool]: A subclass of the ReadFileTool class, specifically for the current directory.

Source code in langroid/agent/tools/file_tools.py
@classmethod
def create(
    cls,
    get_curr_dir: Callable[[], str] | None,
) -> Type["ReadFileTool"]:
    """
    Create a subclass of ListDirTool for a specific directory

    Args:
        get_curr_dir (callable): A function that returns the current directory.

    Returns:
        Type[ReadFileTool]: A subclass of the ReadFileTool class, specifically
            for the current directory.
    """

    class CustomListDirTool(cls):  # type: ignore
        _curr_dir: Callable[[], str] | None = (
            staticmethod(get_curr_dir) if get_curr_dir else None
        )

    return CustomListDirTool