AQIT 0.1.0
Loading...
Searching...
No Matches
registry.py
Go to the documentation of this file.
1# Copyright (c) 2025-present Aquin Labs Private Limited. All Rights Reserved.
2# This file is part of the Aquin Engine. Unauthorized copying, modification,
3# distribution, or use of this file, via any medium, is strictly prohibited.
4# Proprietary and confidential. See LICENSE for terms.
5
6from __future__ import annotations
7
8from typing import Any, Callable
9
10TOOL_REGISTRY: dict[str, Callable] = {}
11_TOOL_SCHEMAS: list[dict[str, Any]] = []
12
13
14def register(name: str, schema: dict[str, Any] | None = None):
15 def decorator(fn: Callable):
16 TOOL_REGISTRY[name] = fn
17 if schema is not None:
18 _TOOL_SCHEMAS.append(schema)
19 return fn
20 return decorator
21
22
23def dispatch(name: str, args: dict[str, Any], ctx: dict[str, Any]) -> Any:
24 handler = TOOL_REGISTRY.get(name)
25 if handler is None:
27 handler = TOOL_REGISTRY.get(name)
28 if handler is None:
29 # Stale/partial registry (e.g. old daemon) — bridge may still have the handler.
30 from aquin.compute.bridge import TOOL_ROUTES
31
32 if name in TOOL_ROUTES:
33 from .executor import execute_tool
34
35 return execute_tool(name, args, ctx)
36 raise NotImplementedError(f"Tool '{name}' not yet ported to engine")
37 return handler(args, ctx)
38
39
40def list_tools() -> list[str]:
41 return list(TOOL_REGISTRY.keys())
42
43
44def get_tool_schemas() -> list[dict[str, Any]]:
45 return list(_TOOL_SCHEMAS)
46
47
48def _load_stubs() -> None:
49 from . import executor as _executor # noqa: F401 # must load before stubs
50 from . import inspect as _inspect # noqa: F401
51 from . import session_memory as _session_memory # noqa: F401
52 from . import stubs as _stubs # noqa: F401
53 _ = _executor, _inspect, _session_memory, _stubs # silence unused warnings
54
register(str name, dict[str, Any]|None schema=None)
Definition registry.py:18
Any dispatch(str name, dict[str, Any] args, dict[str, Any] ctx)
Definition registry.py:27
list[dict[str, Any]] get_tool_schemas()
Definition registry.py:48