from __future__ import annotations

from collections.abc import Mapping

from ..agent_tool_core import ToolHandler


def resolve_handler(handlers: Mapping[str, ToolHandler], name: str, group: str) -> ToolHandler:
    """从工具组 handler 映射中取出指定工具的执行函数。"""

    try:
        return handlers[name]
    except KeyError as exc:
        raise KeyError(f'Missing {group} tool handler: {name}') from exc

