Skip to content

feat: tool-registry pattern + example echo_tool#57

Merged
constk merged 1 commit into
developfrom
feat/20-tool-registry
Apr 26, 2026
Merged

feat: tool-registry pattern + example echo_tool#57
constk merged 1 commit into
developfrom
feat/20-tool-registry

Conversation

@constk
Copy link
Copy Markdown
Owner

@constk constk commented Apr 26, 2026

Closes #20. Generic Registry class with register()/dispatch()/names(); echo_tool exercises the layer; 7 unit tests; lint-imports keeps tools at the right layer.

Add src/tools/registry.py: a generic dispatcher mapping tool name -> (input
schema, callable). Each tool's input + output are StrictModel subclasses.
Three-method API matches the issue spec:

- register(name, input_schema) -> decorator
- dispatch(name, raw_input)    -> validates raw dict against input schema,
                                  invokes the tool, returns typed output
- names()                      -> sorted list of registered tool names

UnknownToolError (KeyError subclass) raises on dispatch with a missing
name; Pydantic's ValidationError propagates on bad input (wrong type or
unknown keys via StrictModel's extra="forbid").

Module-global `registry` singleton; `echo_tool` (input/output pair
EchoToolInput/EchoToolOutput) self-registers at module load to demonstrate
the pattern.

Layer hygiene: registry.py imports only from src/models/. Verified by
lint-imports — both contracts still kept.

7 unit tests cover: module-global resolves echo, happy-path dispatch,
unknown-tool error, bad input rejection, unknown-key rejection, duplicate
registration, and registry isolation.

Closes #20

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@constk constk merged commit 1c09345 into develop Apr 26, 2026
@constk constk deleted the feat/20-tool-registry branch April 26, 2026 17:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant