can_bind_tools
What it is
A small utility that checks whether a LangChain BaseChatModel supports tool binding by attempting to bind a minimal tool.
Public API
can_bind_tools(chat_model: BaseChatModel) -> bool- Attempts to bind a single tool (
get_time_date) to the provided chat model. - Returns
Trueif binding succeeds without raising an exception; otherwise returnsFalseand logs a debug message.
- Attempts to bind a single tool (
Configuration/Dependencies
- Depends on:
langchain_core.language_models.BaseChatModellangchain_core.tools.tool(used to define a test tool)naas_abi_core.logger(debug logging on failure)
- The internal test tool uses:
datetimeandzoneinfo.ZoneInfo(standard library)
Usage
from langchain_core.language_models import BaseChatModel
from naas_abi_core.services.agent.tools.utils import can_bind_tools
def check_model(model: BaseChatModel) -> None:
if can_bind_tools(model):
print("Model supports tool binding.")
else:
print("Model does NOT support tool binding.")
Caveats
- This function uses a trial bind; any exception thrown by
chat_model.bind_tools(...)is treated as “no tool support” (even if the failure is due to other issues, e.g., model misconfiguration). - The bound tool is defined inside the function and is not exposed for reuse.