mirror of
https://github.com/langgenius/dify.git
synced 2026-03-04 15:26:21 +08:00
Layers
Pluggable middleware for engine extensions.
Components
Layer (base)
Abstract base class for layers.
initialize()- Receive runtime context (runtime state is bound here and always available to hooks)on_graph_start()- Execution start hookon_event()- Process all eventson_graph_end()- Execution end hook
DebugLoggingLayer
Comprehensive execution logging.
- Configurable detail levels
- Tracks execution statistics
- Truncates long values
Usage
debug_layer = DebugLoggingLayer(
level="INFO",
include_outputs=True
)
engine = GraphEngine(graph)
engine.layer(debug_layer)
engine.run()
engine.layer() binds the read-only runtime state before execution, so
graph_runtime_state is always available inside layer hooks.
Custom Layers
class MetricsLayer(Layer):
def on_event(self, event):
if isinstance(event, NodeRunSucceededEvent):
self.metrics[event.node_id] = event.elapsed_time
Configuration
DebugLoggingLayer Options:
level- Log level (INFO, DEBUG, ERROR)include_inputs/outputs- Log data valuesmax_value_length- Truncate long values