Liman

ToolNode

Represents a tool node in a directed graph. This node can be used to execute specific tools or functions within a workflow.

YAML example:

kind: ToolNode
name: get_weather
description:
  en: |
    This tool retrieves the current weather for a specified location.
  ru: |
    Эта функция получает текущую погоду для указанного местоположения.
func: lib.tools.get_weather
arguments:
  - name: lat
    type: float
    description:
      en: latitude of the location
      ru: широта местоположения (latitude)
  - name: lon
    type: float
    description:
      en: longitude of the location
      ru: долгота местоположения (longitude)
# Optionally, you can specify example triggers for the tool.
triggers:
  en:
    - What's the weather in New York?
  ru:
    - Какая погода в Нью-Йорке?
# Optionally, you can specify a template for the tool prompt.
# It will allow to improve tool execution accuracy.
# supported only \{name\}, \{description\} and \{triggers\} variables.
tool_prompt_template:
  en: |
    \{name\} - \{description\}
    Examples:
      \{triggers\}
  ru: |
    \{name\} - \{description\}
    Примеры:
      \{triggers\}

Usage:

kind: LLMNode
---
tools:
  - get_weather
  - another_tool

Attributes

attributespec_type
= ToolNodeSpec
attributestate_type
= ToolNodeState
attributeregistry
= registry
attributefuncCallable[..., Any] | None
= None

Functions

func__init____init__(self, /, spec, registry, *, initial_data=None, yaml_path=None, strict=False, default_lang='en', fallback_lang='en') -> None

Initialize tool node with specification and registry.

Args: spec: Tool node specification defining function and arguments registry: Component registry for dependency resolution initial_data: Optional initial data for the component yaml_path: Optional path to the YAML file this node was loaded from strict: Whether to enforce strict validation and imports default_lang: Default language code for description selection fallback_lang: Fallback language code when default is unavailable

paramself
paramspecToolNodeSpec
paramregistryRegistry
paraminitial_datadict[str, Any] | None
= None
paramyaml_pathstr | None
= None
paramstrictbool
= False
paramdefault_langstr
= 'en'
paramfallback_langstr
= 'en'

Returns

None
funccompilecompile(self) -> None

Compile the tool node by loading the target function.

Loads the function specified in spec.func and prepares the node for execution. Must be called before invoke().

paramself

Returns

None
funcset_funcset_func(self, /, func) -> None

Manually set the function for this tool node.

Args: func: Callable function that matches the tool specification signature

paramself
paramfuncCallable[..., Any]

Returns

None
funcinvokeinvoke(self, /, tool_call, execution_context=None) -> ToolMessage

Execute the tool function with provided arguments.

Calls the underlying function with extracted arguments and returns the result wrapped in a ToolMessage. Handles both sync and async functions.

Args: tool_call: Tool call containing name, arguments, and call ID execution_context: Optional execution context for dependency injection

Returns: ToolMessage containing function result and call metadata

Raises: ValueError: If no function is set or required parameters are missing

paramself
paramtool_callToolCall
paramexecution_contextExecutionContext[ToolNodeState] | None
= None

Returns

ToolMessage
func_extract_function_args_extract_function_args(self, /, args_dict, execution_context=None) -> dict[str, Any]

Extract function arguments based on function signature from provided args dict. Automatically inject Liman dependency if function parameter is typed as Liman.

Args: args_dict: Dictionary containing all available arguments execution_context: Optional ExecutionContext

Returns: Dictionary with only the arguments that match function signature

paramself
paramargs_dictdict[str, Any]
paramexecution_contextExecutionContext[ToolNodeState] | None
= None

Returns

dict[str, Any]
func_load_func_load_func(self) -> Callable[..., Any]
paramself

Returns

Callable[..., Any]
funcget_tool_descriptionget_tool_description(self, /, lang) -> str

Generate tool description for specified language.

Creates a formatted description using the tool prompt template, description, and example triggers for the given language.

Args: lang: Language code for description generation

Returns: Formatted tool description string

paramself
paramlangLanguageCode

Returns

str
funcget_json_schemaget_json_schema(self, /, lang=None) -> dict[str, Any]

Generate JSON Schema representation for LLM function calling.

Creates OpenAI-compatible function schema including name, description, and parameter definitions for the specified language.

Args: lang: Language code for schema generation (uses default_lang if None)

Returns: JSON Schema dict compatible with LLM function calling

Raises: InvalidSpecError: If description is missing or invalid

paramself
paramlangLanguageCode | None
= None

Returns

dict[str, Any]
funcget_new_stateget_new_state(self) -> ToolNodeState

Create new state instance for this tool node.

Returns: Fresh ToolNodeState for execution

paramself

Returns

ToolNodeState
func_get_tool_prompt_template_get_tool_prompt_template(self, /, lang) -> str

Get the tool prompt template from the declaration or use the default template.

paramself
paramlangLanguageCode

Returns

str

Last updated on