Skip to content

LocalShellTool

autogen.beta.tools.shell.tool.LocalShellTool #

LocalShellTool(environment=None)

Bases: Tool

The tool exposes a single shell function that runs commands in whatever environment is provided — local subprocess, Docker container, SSH, etc. All execution details are encapsulated inside the environment.

PARAMETER DESCRIPTION
environment

The execution environment, a path to a working directory, or None. When a path (str or :class:~pathlib.Path) is given, a :class:LocalShellEnvironment is created in that directory automatically. Defaults to :class:LocalShellEnvironment with a temporary directory.

TYPE: ShellEnvironment | PathLike[str] | str | None DEFAULT: None

Examples::

# Auto temp dir — cleaned up on exit
sh = LocalShellTool()

# Pass a path directly — creates LocalShellEnvironment for you
sh = LocalShellTool("/tmp/my_project")
sh = LocalShellTool(Path("/tmp/my_project"))

# Full control via explicit environment
sh = LocalShellTool(LocalShellEnvironment(path="/tmp/my_project"))

# Read-only local inspection
sh = LocalShellTool(LocalShellEnvironment(path="/tmp/my_project", readonly=True))

# Future: Docker or SSH (not yet implemented)
# sh = LocalShellTool(DockerEnvironment(image="python:3.12"))
# sh = LocalShellTool(SSHEnvironment(host="server.com", user="ubuntu"))
Source code in autogen/beta/tools/shell/tool.py
def __init__(self, environment: ShellEnvironment | PathLike[str] | str | None = None) -> None:
    if isinstance(environment, (str, PathLike)):
        env = LocalShellEnvironment(path=environment)
    else:
        env = environment if environment is not None else LocalShellEnvironment()
    self._tool: FunctionTool = tool(
        env.run,
        name="shell",
        description=f"Execute a shell command in the working directory: {env.workdir}",
    )
    self._workdir = env.workdir

workdir property #

workdir

The working directory of the underlying environment.

schemas async #

schemas(context)
Source code in autogen/beta/tools/shell/tool.py
async def schemas(self, context: "Context") -> list:
    return await self._tool.schemas(context)

register #

register(stack, context, *, middleware=())
Source code in autogen/beta/tools/shell/tool.py
def register(
    self,
    stack: "ExitStack",
    context: "Context",
    *,
    middleware: Iterable["BaseMiddleware"] = (),
) -> None:
    self._tool.register(stack, context, middleware=middleware)