Tool Reflection Discovery & Parameter Signature Type Coercion
Decrypting model_tools.py dispatcher and tools/registry.py introspection coercion self-healing
📊 Figure 3-1-1: ToolRegistry Class Diagram, Reflection Introspection & Parameter Type Coercion UML Structure
🛠️ 1. Dynamic Tool Discovery (discover_builtin_tools)
The system does not hardcode any tool list. Instead, at startup it automatically scans the tools/ folder for all Python files with decorators. This mechanism lives in tools/registry.py:
It uses Python's ast.parse() to statically analyze file headers for registry.register calls. If found, it calls importlib.import_module() to import the module.
📊 Figure 3-1-2: Parameter Signature Reflection Introspection & Type Conversion Flowchart
⚙️ 2. Type Coercion & Self-Healing (Parameter Coercion)
The LLM frequently passes numeric values (e.g., 120) as JSON strings ("120") or provides integers where floats are expected. In model_tools.py, the TypeCoercionEngine automatically reads the target Python function's inspect.signature and type hints to perform forced type conversion.