MCPcopy Create free account
hub / github.com/Louisym/MiniCC / DecoratorRegistry

Class DecoratorRegistry

tutorials/18_design_patterns_for_agents.py:685–698  ·  view source on GitHub ↗

用 Python 装饰器语法自动注册

Source from the content-addressed store, hash-verified

683 print(" ──────────────────")
684
685 class DecoratorRegistry:
686 """用 Python 装饰器语法自动注册"""
687 def __init__(self):
688 self._handlers: dict[str, Callable] = {}
689
690 def tool(self, name: str):
691 """装饰器: @registry.tool("bash")"""
692 def decorator(func):
693 self._handlers[name] = func
694 return func
695 return decorator
696
697 def execute(self, name: str, inp: str) -> str:
698 return self._handlers[name](inp)
699
700 r = DecoratorRegistry()
701

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected