1313- Command-based state updates for advanced control flow
1414
1515Key Components:
16- ToolNode: Main class for executing tools in LangGraph workflows
17- InjectedState: Annotation for injecting graph state into tools
18- InjectedStore: Annotation for injecting persistent store into tools
19- tools_condition: Utility function for conditional routing based on tool calls
16+ ` ToolNode` : Main class for executing tools in LangGraph workflows
17+ ` InjectedState` : Annotation for injecting graph state into tools
18+ ` InjectedStore` : Annotation for injecting persistent store into tools
19+ ` tools_condition` : Utility function for conditional routing based on tool calls
2020
2121Typical Usage:
2222 ```python
@@ -123,11 +123,11 @@ class ToolCallRequest:
123123 Attributes:
124124 tool_call: Tool call dict with name, args, and id from model output.
125125 tool: BaseTool instance to be invoked, or None if tool is not
126- registered with the ToolNode. When tool is None, interceptors can
127- handle the request without validation. If the interceptor calls execute(),
126+ registered with the ` ToolNode` . When tool is ` None` , interceptors can
127+ handle the request without validation. If the interceptor calls ` execute()` ,
128128 validation will occur and raise an error for unregistered tools.
129- state: Agent state (dict, list, or BaseModel).
130- runtime: LangGraph runtime context (optional, None if outside graph).
129+ state: Agent state (` dict`, ` list` , or ` BaseModel` ).
130+ runtime: LangGraph runtime context (optional, ` None` if outside graph).
131131 """
132132
133133 tool_call : ToolCall
@@ -178,7 +178,7 @@ def override(self, **overrides: Unpack[_ToolCallRequestOverrides]) -> ToolCallRe
178178with potentially modified requests each time. Each call to execute
179179is independent and stateless.
180180
181- Note:
181+ !!! note
182182 When implementing middleware for `create_agent`, use
183183 `AgentMiddleware.wrap_tool_call` which provides properly typed
184184 state parameter for better type safety.
@@ -247,7 +247,7 @@ def handler(request, execute):
247247class ToolCallWithContext (TypedDict ):
248248 """ToolCall with additional context for graph state.
249249
250- This is an internal data structure meant to help the ToolNode accept
250+ This is an internal data structure meant to help the ` ToolNode` accept
251251 tool calls with additional context (e.g. state) when dispatched using the
252252 Send API.
253253
@@ -268,16 +268,16 @@ class ToolCallWithContext(TypedDict):
268268
269269
270270def msg_content_output (output : Any ) -> str | list [dict ]:
271- """Convert tool output to ToolMessage content format.
271+ """Convert tool output to ` ToolMessage` content format.
272272
273- Handles str, list[dict] (content blocks), and arbitrary objects by attempting
273+ Handles ` str`, ` list[dict]` (content blocks), and arbitrary objects by attempting
274274 JSON serialization with fallback to str().
275275
276276 Args:
277277 output: Tool execution output of any type.
278278
279279 Returns:
280- String or list of content blocks suitable for ToolMessage.content.
280+ String or list of content blocks suitable for ` ToolMessage.content` .
281281 """
282282 if isinstance (output , str ) or (
283283 isinstance (output , list )
@@ -297,7 +297,7 @@ def msg_content_output(output: Any) -> str | list[dict]:
297297class ToolInvocationError (ToolException ):
298298 """An error occurred while invoking a tool due to invalid arguments.
299299
300- This exception is only raised when invoking a tool using the ToolNode!
300+ This exception is only raised when invoking a tool using the ` ToolNode` !
301301 """
302302
303303 def __init__ (
@@ -338,7 +338,7 @@ def _handle_tool_error(
338338 """Generate error message content based on exception handling configuration.
339339
340340 This function centralizes error message generation logic, supporting different
341- error handling strategies configured via the ToolNode's handle_tool_errors
341+ error handling strategies configured via the ` ToolNode` 's ` handle_tool_errors`
342342 parameter.
343343
344344 Args:
@@ -350,12 +350,12 @@ def _handle_tool_error(
350350 - tuple: Not used in this context (handled by caller)
351351
352352 Returns:
353- A string containing the error message to include in the ToolMessage.
353+ A string containing the error message to include in the ` ToolMessage` .
354354
355355 Raises:
356356 ValueError: If flag is not one of the supported types.
357357
358- Note:
358+ !!! note
359359 The tuple case is handled by the caller through exception type checking,
360360 not by this function directly.
361361 """
@@ -392,9 +392,9 @@ def _infer_handled_types(handler: Callable[..., str]) -> tuple[type[Exception],
392392
393393 Raises:
394394 ValueError: If the handler's annotation contains non-Exception types or
395- if Union types contain non-Exception types.
395+ if Union types contain non-Exception types.
396396
397- Note:
397+ !!! note
398398 This function supports both single exception types and Union types for
399399 handlers that need to handle multiple exception types differently.
400400 """
@@ -560,7 +560,7 @@ def __init__(
560560 wrap_tool_call : ToolCallWrapper | None = None ,
561561 awrap_tool_call : AsyncToolCallWrapper | None = None ,
562562 ) -> None :
563- """Initialize ToolNode with tools and configuration.
563+ """Initialize ` ToolNode` with tools and configuration.
564564
565565 Args:
566566 tools: Sequence of tools to make available for execution.
@@ -1181,11 +1181,11 @@ def _inject_tool_args(
11811181
11821182 Raises:
11831183 ValueError: If a tool requires store injection but no store is provided,
1184- or if state injection requirements cannot be satisfied.
1184+ or if state injection requirements cannot be satisfied.
11851185
1186- Note:
1186+ !!! note
11871187 This method is called automatically during tool execution. It should not
1188- be called from outside the ToolNode.
1188+ be called from outside the ` ToolNode` .
11891189 """
11901190 if tool_call ["name" ] not in self .tools_by_name :
11911191 return tool_call
@@ -1329,9 +1329,9 @@ def custom_condition(state):
13291329 return tools_condition(state, messages_key="chat_history")
13301330 ```
13311331
1332- Note:
1333- This function is designed to work seamlessly with ToolNode and standard
1334- LangGraph patterns. It expects the last message to be an AIMessage when
1332+ !!! note
1333+ This function is designed to work seamlessly with ` ToolNode` and standard
1334+ LangGraph patterns. It expects the last message to be an ` AIMessage` when
13351335 tool calls are present, which is the standard output format for tool-calling
13361336 language models.
13371337 """
@@ -1353,16 +1353,16 @@ def custom_condition(state):
13531353class ToolRuntime (_DirectlyInjectedToolArg , Generic [ContextT , StateT ]):
13541354 """Runtime context automatically injected into tools.
13551355
1356- When a tool function has a parameter named ' tool_runtime' with type hint
1357- ' ToolRuntime' , the tool execution system will automatically inject
1358- an instance containing:
1356+ When a tool function has a parameter named ` tool_runtime` with type hint
1357+ ` ToolRuntime` , the tool execution system will automatically inject an instance
1358+ containing:
13591359
1360- - state: The current graph state
1361- - tool_call_id: The ID of the current tool call
1362- - config: RunnableConfig for the current execution
1363- - context: Runtime context (from langgraph Runtime)
1364- - store: BaseStore instance for persistent storage (from langgraph Runtime)
1365- - stream_writer: StreamWriter for streaming output (from langgraph Runtime)
1360+ - ` state` : The current graph state
1361+ - ` tool_call_id` : The ID of the current tool call
1362+ - ` config`: ` RunnableConfig` for the current execution
1363+ - ` context` : Runtime context (from langgraph ` Runtime` )
1364+ - ` store`: ` BaseStore` instance for persistent storage (from langgraph ` Runtime` )
1365+ - ` stream_writer`: ` StreamWriter` for streaming output (from langgraph ` Runtime` )
13661366
13671367 No `Annotated` wrapper is needed - just use `runtime: ToolRuntime`
13681368 as a parameter.
@@ -1396,7 +1396,7 @@ def my_tool(x: int, runtime: ToolRuntime) -> str:
13961396 return f"Processed {x}"
13971397 ```
13981398
1399- Note:
1399+ !!! note
14001400 This is a marker class used for type checking and detection.
14011401 The actual runtime object will be constructed during tool execution.
14021402 """
@@ -1470,7 +1470,7 @@ def foo_tool(x: int, foo: Annotated[str, InjectedState("foo")]) -> str:
14701470 ]
14711471 ```
14721472
1473- Note:
1473+ !!! note
14741474 - `InjectedState` arguments are automatically excluded from tool schemas
14751475 presented to language models
14761476 - `ToolNode` handles the injection process during execution
@@ -1550,7 +1550,7 @@ def get_preference(
15501550 result2 = graph.invoke({"messages": [HumanMessage("What's my favorite color?")]})
15511551 ```
15521552
1553- Note:
1553+ !!! note
15541554 - `InjectedStore` arguments are automatically excluded from tool schemas
15551555 presented to language models
15561556 - The store instance is automatically injected by `ToolNode` during execution
0 commit comments