79755698

Date: 2025-09-04 12:20:08
Score: 1.5
Natty:
Report link

We can simply use the command-update method to do this. This is the basic example how it can be implemented.


from langgraph.types import Command
@tool
def send_otp(
    phone_number: str,
    tool_call_id: Annotated[str, InjectedToolCallId],
) -> Command:
    """Send OTP to the (already validated) phone number."""
    logger.info("-----------------------------------send_otp-----------------------------------")

    formatted_number = phone_number
    otp_code = OTPService().generate_otp()
    # In production, actually send SMS here:
    # OTPService().send_otp(formatted_number, otp_code)

    payload = {
        "otp": otp_code,  # stored in state; avoid showing to user in production
        "phoneNumber": formatted_number,
        "message": f"OTP sent successfully to {formatted_number}. Please check your phone.",
    }
    logger.info(f"Send OTP tool payload: {payload}")

    return Command(
        update={
            "otp": otp_code,
            "phoneNumber": formatted_number,
            "messages": [
                ToolMessage(content=json.dumps(payload), tool_call_id=tool_call_id)
            ],
        }
    )

Refer to this documentation to understand more: https://langchain-ai.github.io/langgraph/how-tos/tool-calling/#short-term-memory

Reasons:
  • Blacklisted phrase (1): this document
  • Probably link only (1):
  • Long answer (-1):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: Mangesh Salunke