forked from LangQi99/NeoFish
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtool_registry.py
More file actions
34 lines (23 loc) · 869 Bytes
/
tool_registry.py
File metadata and controls
34 lines (23 loc) · 869 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
"""
tool_registry.py - Runtime tool handler registry for NeoFish agent.
"""
from __future__ import annotations
from dataclasses import dataclass
from typing import Awaitable, Callable
@dataclass
class ToolExecutionResult:
output: str
finished: bool = False
manual_compact: bool = False
compact_focus: str | None = None
ToolHandler = Callable[[dict], Awaitable[ToolExecutionResult]]
class ToolRegistry:
def __init__(self) -> None:
self._handlers: dict[str, ToolHandler] = {}
def register(self, name: str, handler: ToolHandler) -> None:
self._handlers[name] = handler
async def execute(self, name: str, args: dict) -> ToolExecutionResult:
handler = self._handlers.get(name)
if handler is None:
return ToolExecutionResult(output=f"Unknown tool: {name}")
return await handler(args)