Handler mixins
Shared mixins for graph and node handler classes.
This module provides lightweight mixins that add common functionality to handler classes without changing their core runtime behavior. The mixins follow the composition pattern to keep responsibilities explicit and allow handlers to inherit only the capabilities they need.
The mixins provide structured logging, configuration management, and other cross-cutting concerns that are commonly needed across different handler types. By using mixins, the core handler logic remains focused while gaining these shared capabilities.
Typical usage
class MyHandler(BaseLoggingMixin, InterruptConfigMixin):
def __init__(self):
self._set_interrupts(["node1"], ["node2"])
self._log_start("Handler initialized")
Classes:
Name | Description |
---|---|
BaseLoggingMixin |
Provides structured logging helpers for handler classes. |
InterruptConfigMixin |
Manages interrupt configuration for graph-level execution handlers. |
Classes¶
BaseLoggingMixin
¶
Provides structured logging helpers for handler classes.
This mixin adds consistent logging capabilities to handler classes without requiring them to manage logger instances directly. It automatically creates loggers based on the module name and provides convenience methods for common logging operations.
The mixin is designed to be lightweight and non-intrusive, adding only logging functionality without affecting the core behavior of the handler.
Attributes:
Name | Type | Description |
---|---|---|
_logger |
Logger
|
Cached logger instance for the handler class. |
Example
class MyHandler(BaseLoggingMixin):
def process(self):
self._log_start("Processing started")
try:
# Do work
self._log_debug("Work completed successfully")
except Exception as e:
self._log_error("Processing failed: %s", e)
Source code in pyagenity/graph/utils/handler_mixins.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
|
InterruptConfigMixin
¶
Manages interrupt configuration for graph-level execution handlers.
This mixin provides functionality to store and manage interrupt points configuration for graph execution. Interrupts allow graph execution to be paused before or after specific nodes for debugging, human intervention, or checkpoint creation.
The mixin maintains separate lists for "before" and "after" interrupts, allowing fine-grained control over when graph execution should pause.
Attributes:
Name | Type | Description |
---|---|---|
interrupt_before |
list[str] | None
|
List of node names where execution should pause before node execution begins. |
interrupt_after |
list[str] | None
|
List of node names where execution should pause after node execution completes. |
Example
class GraphHandler(InterruptConfigMixin):
def __init__(self):
self._set_interrupts(
interrupt_before=["approval_node"], interrupt_after=["data_processing"]
)
Source code in pyagenity/graph/utils/handler_mixins.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
|