interrupt.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. from typing import Literal
  2. from langgraph.warnings import LangGraphDeprecatedSinceV10
  3. from typing_extensions import TypedDict, deprecated
  4. @deprecated(
  5. "HumanInterruptConfig has been moved to `langchain.agents.interrupt`. Please update your import to `from langchain.agents.interrupt import HumanInterruptConfig`.",
  6. category=LangGraphDeprecatedSinceV10,
  7. )
  8. class HumanInterruptConfig(TypedDict):
  9. """Configuration that defines what actions are allowed for a human interrupt.
  10. This controls the available interaction options when the graph is paused for human input.
  11. Attributes:
  12. allow_ignore: Whether the human can choose to ignore/skip the current step
  13. allow_respond: Whether the human can provide a text response/feedback
  14. allow_edit: Whether the human can edit the provided content/state
  15. allow_accept: Whether the human can accept/approve the current state
  16. """
  17. allow_ignore: bool
  18. allow_respond: bool
  19. allow_edit: bool
  20. allow_accept: bool
  21. @deprecated(
  22. "ActionRequest has been moved to `langchain.agents.interrupt`. Please update your import to `from langchain.agents.interrupt import ActionRequest`.",
  23. category=LangGraphDeprecatedSinceV10,
  24. )
  25. class ActionRequest(TypedDict):
  26. """Represents a request for human action within the graph execution.
  27. Contains the action type and any associated arguments needed for the action.
  28. Attributes:
  29. action: The type or name of action being requested (e.g., `"Approve XYZ action"`)
  30. args: Key-value pairs of arguments needed for the action
  31. """
  32. action: str
  33. args: dict
  34. @deprecated(
  35. "HumanInterrupt has been moved to `langchain.agents.interrupt`. Please update your import to `from langchain.agents.interrupt import HumanInterrupt`.",
  36. category=LangGraphDeprecatedSinceV10,
  37. )
  38. class HumanInterrupt(TypedDict):
  39. """Represents an interrupt triggered by the graph that requires human intervention.
  40. This is passed to the `interrupt` function when execution is paused for human input.
  41. Attributes:
  42. action_request: The specific action being requested from the human
  43. config: Configuration defining what actions are allowed
  44. description: Optional detailed description of what input is needed
  45. Example:
  46. ```python
  47. # Extract a tool call from the state and create an interrupt request
  48. request = HumanInterrupt(
  49. action_request=ActionRequest(
  50. action="run_command", # The action being requested
  51. args={"command": "ls", "args": ["-l"]} # Arguments for the action
  52. ),
  53. config=HumanInterruptConfig(
  54. allow_ignore=True, # Allow skipping this step
  55. allow_respond=True, # Allow text feedback
  56. allow_edit=False, # Don't allow editing
  57. allow_accept=True # Allow direct acceptance
  58. ),
  59. description="Please review the command before execution"
  60. )
  61. # Send the interrupt request and get the response
  62. response = interrupt([request])[0]
  63. ```
  64. """
  65. action_request: ActionRequest
  66. config: HumanInterruptConfig
  67. description: str | None
  68. class HumanResponse(TypedDict):
  69. """The response provided by a human to an interrupt, which is returned when graph execution resumes.
  70. Attributes:
  71. type: The type of response:
  72. - `'accept'`: Approves the current state without changes
  73. - `'ignore'`: Skips/ignores the current step
  74. - `'response'`: Provides text feedback or instructions
  75. - `'edit'`: Modifies the current state/content
  76. args: The response payload:
  77. - `None`: For ignore/accept actions
  78. - `str`: For text responses
  79. - `ActionRequest`: For edit actions with updated content
  80. """
  81. type: Literal["accept", "ignore", "response", "edit"]
  82. args: None | str | ActionRequest