对应 conversation.rs:429-447
| 500 | print(" Builder 2: StaticToolExecutor (工具注册)") |
| 501 | |
| 502 | class StaticToolExecutor: |
| 503 | """对应 conversation.rs:429-447""" |
| 504 | def __init__(self): |
| 505 | self._handlers: dict[str, Callable] = {} |
| 506 | |
| 507 | def register(self, name: str, handler: Callable) -> StaticToolExecutor: |
| 508 | """对应 .register(tool_name, handler) -> Self""" |
| 509 | self._handlers[name] = handler |
| 510 | return self # 链式调用 |
| 511 | |
| 512 | def execute(self, name: str, inp: str) -> str: |
| 513 | if name not in self._handlers: |
| 514 | raise KeyError(f"unknown tool: {name}") |
| 515 | return self._handlers[name](inp) |
| 516 | |
| 517 | executor = ( |
| 518 | StaticToolExecutor() |
no outgoing calls
no test coverage detected