Bases: Toolkit
Toolkit that exposes local filesystem operations as function tools.
All paths are resolved relative to base_path. A path-traversal guard rejects any resolved path that escapes the base directory.
Individual tools are available as attributes and can be passed to an agent separately::
fs = FilesystemToolset(base_path="/tmp/workspace")
# use the full toolset
agent = Agent("a", config=config, tools=[fs])
# or pick individual tools
agent = Agent("a", config=config, tools=[fs.read_file, fs.find_files])
Source code in autogen/beta/tools/toolkits/filesystem.py
| def __init__(
self,
base_path: str | Path = ".",
*,
read_only: bool = False,
) -> None:
base = Path(base_path).resolve()
self.read_file = _make_read_file(base)
self.find_files = _make_find_files(base)
self.write_file = _make_write_file(base)
self.update_file = _make_update_file(base)
self.delete_file = _make_delete_file(base)
tools = [self.read_file, self.find_files]
if not read_only:
tools.extend([self.write_file, self.update_file, self.delete_file])
super().__init__(*tools)
|
read_file = _make_read_file(base)
find_files = _make_find_files(base)
write_file = _make_write_file(base)
update_file = _make_update_file(base)
delete_file = _make_delete_file(base)
Source code in autogen/beta/tools/final/toolkit.py
| async def schemas(self, context: "Context") -> Iterable[ToolSchema]:
schemas: list[ToolSchema] = []
for t in self.tools:
schemas.extend(await t.schemas(context))
return schemas
|
register(stack, context, *, middleware=())
Source code in autogen/beta/tools/final/toolkit.py
| def register(
self,
stack: "ExitStack",
context: "Context",
*,
middleware: Iterable["BaseMiddleware"] = (),
) -> None:
for t in self.tools:
t.register(stack, context, middleware=middleware)
|
tool(function: Callable[..., Any], *, name: str | None = None, description: str | None = None, schema: FunctionParameters | None = None, sync_to_thread: bool = True, middleware: Iterable[ToolMiddleware] = ()) -> Tool
tool(function: None = None, *, name: str | None = None, description: str | None = None, schema: FunctionParameters | None = None, sync_to_thread: bool = True, middleware: Iterable[ToolMiddleware] = ()) -> Callable[[Callable[..., Any]], Tool]
tool(function=None, *, name=None, description=None, schema=None, sync_to_thread=True, middleware=())
Source code in autogen/beta/tools/final/toolkit.py
| def tool(
self,
function: Callable[..., Any] | None = None,
*,
name: str | None = None,
description: str | None = None,
schema: FunctionParameters | None = None,
sync_to_thread: bool = True,
middleware: Iterable[ToolMiddleware] = (),
) -> Tool | Callable[[Callable[..., Any]], Tool]:
def make_tool(f: Callable[..., Any]) -> Tool:
t = FunctionTool.ensure_tool(
tool(
f,
name=name,
description=description,
schema=schema,
sync_to_thread=sync_to_thread,
middleware=middleware,
)
)
self.tools.append(t)
return t
if function:
return make_tool(function)
return make_tool
|