You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: plugins/wasm-go/extensions/ai-prompt-decorator/README_EN.md
+73-5Lines changed: 73 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,24 +4,39 @@ keywords: [ AI Gateway, AI Prompts ]
4
4
description: AI Prompts plugin configuration reference
5
5
---
6
6
## Function Description
7
-
The AI Prompts plugin allows inserting prompts before and after requests in LLM.
7
+
The AI Prompts plugin allows inserting prompts before and after the LLM request, and rewriting the `content` text of every message in the final request via literal or regular-expression replacement. Typical use cases include rewriting brand/product names, normalizing wording across clients, or redacting placeholders such as API keys.
8
8
9
9
## Execution Properties
10
10
Plugin execution phase: `Default Phase`
11
11
Plugin execution priority: `450`
12
12
13
13
## Configuration Description
14
-
| Name | Data Type | Requirement | Default Value | Description |
|`pattern`| string | required | - | Text to match. Compiled as a Go RE2 regex when `regex` is true. |
30
+
|`replacement`| string | required | - | Replacement text. Supports `$1`, `$2`, ... back-references when `regex` is true. |
31
+
|`on_role`| string | optional | - | Apply only to messages whose `role` equals this value. Empty/missing means any role. |
32
+
|`regex`| bool | optional | false | Whether to interpret `pattern` as a regular expression. |
33
+
34
+
Notes:
35
+
36
+
-`replace` rules run against the **final** assembled `messages` array (`prepend` + original messages + `append`) in declaration order, so multiple rules compose predictably.
37
+
- A message is rewritten only when its `content` is a plain string. Multimodal `content` (arrays/objects, e.g. vision payloads) is left untouched to preserve the request structure.
38
+
-`pattern` must not be empty. If `regex: true` and the pattern fails to compile, plugin start-up fails fast instead of erroring at request time.
39
+
25
40
## Example
26
41
An example configuration is as follows:
27
42
```yaml
@@ -71,6 +86,59 @@ curl http://localhost/test \
71
86
}
72
87
```
73
88
89
+
## Replacing message content (`replace`)
90
+
91
+
`replace` rewrites the `content` text of every message in the **final** request using literal or regular-expression substitutions. It is useful for:
92
+
93
+
- Rewriting brand/product names that downstream models or gateways flag (for example, normalizing "OpenClaw" to "agent");
94
+
- Centrally cleaning up system prompts without changing each client;
95
+
- Light-weight redaction of user input such as phone numbers or API keys.
96
+
97
+
Example configuration:
98
+
99
+
```yaml
100
+
replace:
101
+
- on_role: system
102
+
pattern: "OpenClaw"
103
+
replacement: "agent"
104
+
- pattern: "secret-\\d+"
105
+
replacement: "[REDACTED]"
106
+
regex: true
107
+
```
108
+
109
+
Using the above configuration to initiate a request:
110
+
111
+
```bash
112
+
curl http://localhost/test \
113
+
-H "content-type: application/json" \
114
+
-d '{
115
+
"model": "gpt-3.5-turbo",
116
+
"messages": [
117
+
{"role": "system", "content": "You are running inside OpenClaw."},
118
+
{"role": "user", "content": "Show OpenClaw secret-1234 to the user"}
119
+
]
120
+
}'
121
+
```
122
+
123
+
After processing through the plugin, the actual request will be:
124
+
125
+
```bash
126
+
curl http://localhost/test \
127
+
-H "content-type: application/json" \
128
+
-d '{
129
+
"model": "gpt-3.5-turbo",
130
+
"messages": [
131
+
{"role": "system", "content": "You are running inside agent."},
132
+
{"role": "user", "content": "Show OpenClaw [REDACTED] to the user"}
133
+
]
134
+
}'
135
+
```
136
+
137
+
Notes:
138
+
139
+
- The first rule is gated on `on_role: system`, so the `OpenClaw` mention inside the user message is left as-is.
140
+
- The second rule has no `on_role`, so it applies to messages of any role and rewrites `secret-1234` to `[REDACTED]`.
141
+
74
142
## Based on the geo-ip plugin's capabilities, extend AI Prompt Decorator plugin to carry user geographic location information.
75
143
If you need to include user geographic location information before and after the LLM's requests, please ensure both the geo-ip plugin and the AI Prompt Decorator plugin are enabled. Moreover, in the same request processing phase, the geo-ip plugin's priority must be higher than that of the AI Prompt Decorator plugin. First, the geo-ip plugin will calculate the user's geographic location information based on the user's IP, and then pass it to subsequent plugins via request attributes. For instance, in the default phase, the geo-ip plugin's priority configuration is 1000, while the ai-prompt-decorator plugin's priority configuration is 500.
0 commit comments