Skip to content

Call tools

ConfigType = TypeVar('ConfigType') module-attribute

StateType = TypeVar('StateType') module-attribute

logger = logging.getLogger(__name__) module-attribute

MakeToolCallNode

Bases: Generic[StateType, ConfigType]

Note: Using a class to wrap the static method for the type checking.

Examples:

MakeToolCallNode[FullGraphState, FullConfig].build(...)

build(tool_call_message_getter, conf_from_run_config, tool_call_getter, allowed_tools_getter, tools_getter, tool_input_state_getter, responses_to_state_update, internal_node_name='general_tool_node', handle_tool_errors=True) staticmethod

Create a tool call node that can be used in the graph.

This effectively orchestrates the various steps required to make tool calls generally.

Note: This calls all tools concurrently.

PARAMETER DESCRIPTION
tool_call_message_getter

A function that returns the latest tool call message from the state.

TYPE: Callable[[StateType], AIMessage]

conf_from_run_config

A function that returns the validated config to use for the tool call.

TYPE: Callable[[RunnableConfig | None], ConfigType]

allowed_tools_getter

A function that returns the allowed tools for the agent.

TYPE: Callable[[ConfigType], Awaitable[Sequence[str]]]

tool_call_getter

A function that returns the tool calls to make from the tool call message.

TYPE: Callable[[AIMessage], list[ToolCall]]

tools_getter

A function that returns the full tools to call (based on tool names, provided deps)

TYPE: Callable[[ConfigType, Sequence[str]], Awaitable[Sequence[Any]]]

tool_input_state_getter

A function that returns the additional information to pass to the tools. Note: Information provided should be general to ALL tools called by this node.

TYPE: Callable[[ConfigType, StateType], Awaitable[ToolCallInputBase]]

responses_to_state_update

A function that converts the tool response messages to a state update.

TYPE: Callable[[Sequence[ToolMessage]], ToolCallResponseOutput]

internal_node_name

The name of the node.

TYPE: str DEFAULT: 'general_tool_node'

handle_tool_errors

Whether to handle tool errors (default is True). False helpful for testing.

TYPE: bool DEFAULT: True

ToolCallInputBase

Bases: BaseModel

ToolCallResponseOutput

Bases: TypedDict

The state update that results from calling a tool.

Note: Only a subset may be updated depending on the tool called

current_response_messages instance-attribute

debug_info instance-attribute

last_completed_step instance-attribute

sub_assistant_state_datas instance-attribute

has_any_regular_tool_calls(message)

has_any_sub_assistant_tool_calls(message)

run_lg_tool_node(tools, tool_messages_key, tool_input, handle_tool_errors) async

Run the langgraph ToolNode.

This is a thin wrapper around the langgraph implementation that adds some validation.

The MakeToolCallNode builds a more complete node for use within a graph.