openmanus 使用工具
mauns 默认集成4个工具
- PythonExecute():代码执行工具,重写execute,exec执行输入code
- BrowserUseTool():浏览器操作工具,重写execute,使用web引擎执行搜索、下拉、网页解析等工具,提取检索内容
- StrReplaceEditor():文件操作工具,重写execute,执行查看、创建、验证、修改文件的操作
- Terminate():任务终止工具,重写execute,输出任务终止提示
# Add general-purpose tools to the tool collection available_tools: ToolCollection = Field( default_factory=lambda: ToolCollection( PythonExecute(), BrowserUseTool(), StrReplaceEditor(), Terminate() ) )
各工具对抽象基类进行重写
class BaseTool(ABC, BaseModel): name: str description: str parameters: Optional[dict] = None class Config: arbitrary_types_allowed = True async def __call__(self, **kwargs) -> Any: """Execute the tool with given parameters.""" return await self.execute(**kwargs) @abstractmethod async def execute(self, **kwargs) -> Any: """Execute the tool with given parameters.""" def to_param(self) -> Dict: """Convert tool to function call format.""" return { "type": "function", "function": { "name": self.name, "description": self.description, "parameters": self.parameters, }, }

浙公网安备 33010602011771号