Package com.tnsai.tools.method
Class ToolMethodRegistry
java.lang.Object
com.tnsai.tools.method.ToolMethodRegistry
Discovers and indexes
Tool-annotated methods across a list of POJO
tool-bearing instances.
Given a list of objects (whatever the user passes to Role.tools()),
this registry scans each object's runtime class for public methods carrying
@Tool, extracts their parameter metadata via ToolParam, and
maintains an indexed view by tool name for fast LLM-call dispatch.
Discovery rules
- Only public methods are scanned. Private / package-private /
protected methods carrying
@Toolare skipped with a debug log. staticmethods carrying@Toolare skipped — tools are instance-level so they can carry constructor-injected dependencies.- If two methods (across the same or different POJOs) resolve to the
same tool name, registry construction throws
IllegalArgumentException— duplicate names break LLM dispatch determinism.
Parameter metadata
Parameter names are read from ToolParam.name() when set,
otherwise from the reflected Parameter.getName() (which requires
the -parameters compile flag — already enforced by this project's
maven-compiler-plugin). Consumer projects compiling their own
@Tool POJOs must enable -parameters or always set
@ToolParam(name=...). A synthetic JVM name (arg0) without
an explicit @ToolParam name fails registration instead of
advertising garbage schema names.
- Since:
- 0.5.7 (LangChain-style tool refactor — see issue #188)
-
Constructor Summary
ConstructorsConstructorDescriptionToolMethodRegistry(Collection<?> toolBearingObjects) Build a registry from a collection of POJO tool-bearing instances.ToolMethodRegistry(Collection<?> toolBearingObjects, Collection<DynamicToolMethod> dynamicTools) Build a registry from a collection of POJO tool-bearing instances and a list of pre-builtDynamicToolMethods (e.g. from MCP proxy discovery). -
Method Summary
-
Constructor Details
-
ToolMethodRegistry
Build a registry from a collection of POJO tool-bearing instances.- Parameters:
toolBearingObjects- user-supplied list (typically whatRole.tools()returns)- Throws:
IllegalArgumentException- if two discovered tools have the same name, or if a tool is structurally invalid (blank description, etc.)
-
ToolMethodRegistry
public ToolMethodRegistry(Collection<?> toolBearingObjects, Collection<DynamicToolMethod> dynamicTools) Build a registry from a collection of POJO tool-bearing instances and a list of pre-builtDynamicToolMethods (e.g. from MCP proxy discovery).- Parameters:
toolBearingObjects- user-supplied POJOs scanned for@ToolmethodsdynamicTools- pre-built dynamic tools (proxies, runtime-defined)- Throws:
IllegalArgumentException- if any two registered tools (across both sources) share a name
-
-
Method Details
-
lookup
- Parameters:
name- the LLM-facing tool name- Returns:
- the tool method, or
nullwhen no such tool is registered
-
all
- Returns:
- all discovered tools in registration order
-
size
public int size()- Returns:
- the count of discovered tools
-