MCPcopy Create free account
hub / github.com/Louisym/MiniCC / ToolExecutor

Class ToolExecutor

tutorials/05_agentic_loop_complete.py:123–138  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

121
122# --- 工具执行器 (Tutorial 03 精简版) ---
123class ToolExecutor:
124 def __init__(self):
125 self._handlers: dict[str, Callable[[str], str]] = {}
126
127 def register(self, name: str, handler: Callable[[str], str]) -> "ToolExecutor":
128 self._handlers[name] = handler
129 return self
130
131 def execute(self, tool_name: str, tool_input: str) -> tuple[str, bool]:
132 if tool_name not in self._handlers:
133 return (f"Unknown tool: {tool_name}", True)
134 try:
135 result = self._handlers[tool_name](tool_input)
136 return (result, False)
137 except Exception as e:
138 return (str(e), True)
139
140
141# ======================================================================

Callers 1

mainFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected