Phase 5 / Ep 24: Plugin Pipeline Architecture —— Onion Model for Message Processing
🎯 Learning Objective: Understand the 'Onion Model' of Plugins in the message pipeline.
1. Onion Model
Before a message reaches the Agent and before a response is returned to the user, it will sequentially pass through all registered Plugins:
sequenceDiagram
participant User as 🧑 User Message
participant P1 as Plugin A\n📝 Logging
participant P2 as Plugin B\n🛡️ Sensitive Word Filtering
participant P3 as Plugin C\n🏷️ Intent Classification
participant Agent as 🤖 Agent
participant P4 as Plugin D\n🎨 Response Formatting
User->>P1: ① Message enters pipeline
P1->>P2: ② Pass after logging
P2->>P2: ③ Check sensitive words
P2->>P3: ④ Pass after approval
P3->>Agent: ⑤ Attach intent tag
Agent->>P4: ⑥ Agent response
P4->>User: ⑦ Return to user after formatting2. Pipeline Execution Order
Plugins are executed sequentially according to their registration order (array order in openclaw.json):
{
"plugins": {
"pipeline": [
"logger", // 1st to execute
"content-filter", // 2nd
"intent-classifier", // 3rd
"response-formatter" // Last (response phase)
]
}
}
3. Plugin Hook Types
| Hook | Trigger Timing | Typical Use Cases |
|---|---|---|
onMessage |
When user message arrives | Logging, filtering, pre-processing |
beforeAgent |
Before sending to Agent | Intent classification, context injection |
afterAgent |
After Agent responds | Formatting, translation, moderation |
onError |
When processing errors | Error logging, fallback handling |
4. Pipeline Control
Plugins can decide whether to continue passing the message:
next():Pass to the next Pluginblock():Intercept the message, no longer pass itmodify(msg):Modify the message and then pass it
Next Episode Preview: Ep 25, develop your first Plugin from scratch—the 'Message Counter'.