Files
ai-agent-book/chapter5/coding-agent/tool_registry.py
T
liqiang b119135836
Build latest book artifacts / build (push) Canceled after 0s
dependency resolution / resolve (3.11) (push) Canceled after 0s
dependency resolution / resolve (3.13) (push) Canceled after 0s
deploy-pages / build (push) Canceled after 0s
deploy-pages / deploy (push) Canceled after 0s
i18n consistency check / check (push) Canceled after 0s
provider adoption tests / test (chapter2/context-compression) (push) Canceled after 0s
provider adoption tests / test (chapter2/prompt-injection) (push) Canceled after 0s
provider adoption tests / test (chapter2/system-hint) (push) Canceled after 0s
provider adoption tests / test (chapter3/log-sanitization) (push) Canceled after 0s
web-search-agent tests / test (push) Canceled after 0s
web-search-agent tests / agentbook (push) Canceled after 0s
ai-agent-book 精选快照(<2MB 代码与文档,来自 github.com/bojieli/ai-agent-book)
2026-08-20 13:12:50 +00:00

49 lines
1.4 KiB
Python

"""
Tool registry - Maps tool names to implementations
"""
from typing import Dict, Type
from tools import (
BaseTool, BashTool, BashOutputTool, KillBashTool,
ReadTool, WriteTool, EditTool, MultiEditTool,
GrepTool, GlobTool, LSTool,
TodoWriteTool, ExitPlanModeTool, NotebookEditTool,
WebFetchTool, WebSearchTool, TaskTool
)
class ToolRegistry:
"""Registry of all available tools"""
def __init__(self):
self._tools: Dict[str, Type[BaseTool]] = {
"Bash": BashTool,
"BashOutput": BashOutputTool,
"KillBash": KillBashTool,
"Read": ReadTool,
"Write": WriteTool,
"Edit": EditTool,
"MultiEdit": MultiEditTool,
"Grep": GrepTool,
"Glob": GlobTool,
"LS": LSTool,
"TodoWrite": TodoWriteTool,
"ExitPlanMode": ExitPlanModeTool,
"NotebookEdit": NotebookEditTool,
"WebFetch": WebFetchTool,
"WebSearch": WebSearchTool,
"Task": TaskTool,
}
def get_tool(self, name: str, system_state) -> BaseTool:
"""Get tool instance by name"""
tool_class = self._tools.get(name)
if tool_class is None:
raise ValueError(f"Unknown tool: {name}")
return tool_class(system_state)
def get_all_tool_names(self):
"""Get list of all tool names"""
return list(self._tools.keys())