ZBaseTool#
The ZBaseTool extends BaseTool by saving default color information along with each tool, making it possible for tool output to be color-coded even if it’s not specified at runtime. This is used by the Choice chain to save tool colors during initialization.
It can either be wrapped around an existing tool:
[1]:
from langchain_contrib.tools import TerminalTool, ZBaseTool
tool = ZBaseTool.from_tool(base_tool=TerminalTool(), color="red")
tool.run("ls", verbose=True, observation_prefix="", llm_prefix="")
persistent_terminal.ipynb safe_terminal.ipynb tools.rst z_base.ipynb
[1]:
'persistent_terminal.ipynb safe_terminal.ipynb\ttools.rst z_base.ipynb\n'
Or it can be subclassed:
[2]:
class DemoTool(ZBaseTool):
name: str = "Demo"
description: str = "Demo tool"
def _run(self, tool_input: str) -> str:
"""Use the tool."""
return f"Demonstration: {tool_input}"
tool = DemoTool(color="pink")
tool.run("This is pink", verbose=True, observation_prefix="", llm_prefix="")
Demonstration: This is pink
[2]:
'Demonstration: This is pink'