from langchain_core.tools import tool from typing import Annotated from langchain_core.messages import ToolMessage from langchain_core.tools import InjectedToolCallId, tool from langgraph.types import Command, interrupt # Define tools @tool def multiply(a: int, b: int) -> int: """Multiply a and b. Args: a: first int b: second int """ return a * b @tool def add(a: int, b: int) -> int: """Adds a and b. Args: a: first int b: second int """ return a + b @tool def divide(a: int, b: int) -> float: """Divide a and b. Args: a: first int b: second int """ return a / b @tool def human_assistance( name: str, birthday: str, tool_call_id: Annotated[str, InjectedToolCallId] ) -> str: """Request assistance from a human.""" human_response = interrupt( { "question": "Is this correct?", "name": name, "birthday": birthday, }, ) if human_response.get("correct", "").lower().startswith("y"): verified_name = name verified_birthday = birthday response = "Correct" else: verified_name = human_response.get("name", name) verified_birthday = human_response.get("birthday", birthday) response = f"Made a correction: {human_response}" state_update = { "name": verified_name, "birthday": verified_birthday, "messages": [ToolMessage(response, tool_call_id=tool_call_id)], } return Command(update=state_update)