LocalShellTool(environment=None, name='run_shell_command', *, description='Execute a shell command in the working directory: {workdir}', middleware=())
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 | str | PathLike[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 | str | os.PathLike[str] | None = None,
name: str = "run_shell_command",
*,
description: str = "Execute a shell command in the working directory: {workdir}",
middleware: Iterable["ToolMiddleware"] = (),
) -> None:
if environment:
env: ShellEnvironment = LocalShellEnvironment.ensure_env(environment)
else:
env = LocalShellEnvironment()
self._tool: FunctionTool = tool(
env.run,
name=name,
description=description.format(workdir=env.workdir),
middleware=middleware,
)
self._workdir = env.workdir
self.name = name
|
The working directory of the underlying environment.
Source code in autogen/beta/tools/shell/tool.py
| async def schemas(self, context: "Context") -> list:
return await self._tool.schemas(context)
|
register(stack, context, *, middleware=())
Source code in autogen/beta/tools/shell/tool.py
| def register(
self,
stack: "ExitStack | AsyncExitStack",
context: "Context",
*,
middleware: Iterable["BaseMiddleware"] = (),
) -> None:
self._tool.register(stack, context, middleware=middleware)
|
Source code in autogen/beta/tools/tool.py
| def set_provider(self, provider: Provider) -> None:
pass
|