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
-**History preservation** — optional `context.history.max_items` compacts older conversation turns into one preserved history item, with a runtime `onHistoryCompaction` hook for custom summaries
171
180
-**Warning controls** — top-level config can suppress or emit context size warnings differently in dev and prod
172
181
-**Caching** — LRU cache with mtime-based invalidation
|`onContextOverflow`|`(info) => string`| Optional callback to transform oversized context values before rendering |
597
+
|`onHistoryCompaction`|`(info) => string \| { role, content }`| Optional callback to compact overflow history when `context.history.max_items` is exceeded |
588
598
|`environment`|`string`| Environment override name |
589
599
|`tier`|`string`| Tier override name |
590
-
|`history`|`Array<{ role, content }>`| Conversation history |
600
+
|`history`|`Array<{ role, content }>`| Conversation history. If the prompt declares `context.history.max_items`, older turns are compacted into one preserved history item before provider rendering.|
591
601
|`toolRegistry`|`Record<string, unknown>`| Tool definitions for resolving string tool references |
|`context.inputs`| `Array<string | { name, max_size?, trim?, allow_regex?, deny_regex?, non_empty?, reject_secrets? }>` | no | Declared variable names used in templates, with optional size budgets and runtime hardening controls |
73
-
|`context.history`| object | no |`{ max_items: number }`|
73
+
|`context.history`| object | no |`{ max_items: number }`; caps rendered history by compacting older turns into one preserved message|
74
74
|`includes`| string[]| no | Relative paths to other prompt files to include |
75
75
|`environments`| object | no | Per-environment overrides (see Overrides) |
76
76
|`tiers`| object | no | Per-tier overrides (see Overrides) |
@@ -131,6 +131,32 @@ If a validator declares `return_message`, `renderPrompt()` returns that message
131
131
132
132
Malformed `allow_regex` and `deny_regex` values fail during `validate` and `compile`, not just at render time. When regex compilation fails, the error includes the prompt id, variable name, field name, and raw configured value. Double-quoted YAML regex strings with raw backslashes fail as `POK013`; use `/pattern/i`, single-quoted `pattern: '...'`, or doubled backslashes.
133
133
134
+
### Conversation history limits
135
+
136
+
Use `context.history.max_items` when a chat-style prompt should bound rendered conversation history:
137
+
138
+
```yaml
139
+
context:
140
+
history:
141
+
max_items: 10
142
+
```
143
+
144
+
When runtime `history` exceeds `max_items`, PromptOpsKit preserves history by compacting older turns into one synthetic history message and keeping the most recent turns. Callers can provide `onHistoryCompaction` to create a custom summary:
If no callback is supplied, PromptOpsKit creates a plain text compacted history message. Do not describe `max_items` as dropping history; it preserves overflow through compaction.
159
+
134
160
Example: this is the minimal valid shape for a prompt that references
135
161
`{{ pull_request }}` even when provider/model are inherited from defaults:
|`onContextOverflow`|`(info) => string`| Optional callback to transform an oversized context value before rendering |
71
+
|`onHistoryCompaction`|`(info) => string \| { role, content }`| Optional callback used when `context.history.max_items` compacts overflow history |
69
72
|`environment`|`string`| Environment override name |
70
73
|`tier`|`string`| Tier override name |
71
-
|`history`|`Array<{ role, content }>`| Conversation history |
74
+
|`history`|`Array<{ role, content }>`| Conversation history. If the prompt declares `context.history.max_items`, overflow history is compacted into one preserved history item before provider rendering.|
72
75
|`toolRegistry`|`Record<string, unknown>`| Tool definitions for resolving string tool references |
73
76
|`strict`|`boolean`| Fail on missing variables (default `false`) |
`RuntimeRenderOptions` for direct adapter rendering supports `environment`, `tier`, `runtime`, `variables`, `onContextOverflow`, `history`, `toolRegistry`, `strict`, and `openaiResponses`.
253
+
`RuntimeRenderOptions` for direct adapter rendering supports `environment`, `tier`, `runtime`, `variables`, `onContextOverflow`, `history`, `onHistoryCompaction`, `toolRegistry`, `strict`, and `openaiResponses`.
251
254
252
255
Runtime overrides can include the same overridable front matter fields as `environments` and `tiers`, including `raw` provider passthrough blocks. Raw blocks are merged into provider request bodies after normalized fields and provider-specific options.
Your application owns the HTTP call — PromptOpsKit produces the request body only.
117
125
126
+
When `context.history.max_items` is set and runtime history exceeds that count, PromptOpsKit compacts older turns into one preserved history item and keeps the most recent turns. Use `onHistoryCompaction` when your app wants to provide its own summary.
Copy file name to clipboardExpand all lines: docs/prompt-format.md
+28Lines changed: 28 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -247,6 +247,34 @@ At render time, PromptOpsKit also emits a non-blocking `POK030` warning when a p
247
247
248
248
Malformed `allow_regex` and `deny_regex` values fail during `validate` and `compile` with `POK013`, so bad patterns are caught before runtime. Double-quoted YAML regex strings with raw backslashes are also reported as `POK013`; use unquoted `/pattern/i`, single-quoted `pattern: '...'`, or doubled backslashes in double quotes.
249
249
250
+
### Conversation history
251
+
252
+
Declare `context.history.max_items` when a prompt should bound rendered conversation history:
253
+
254
+
```yaml
255
+
context:
256
+
history:
257
+
max_items: 8
258
+
```
259
+
260
+
When runtime `history` has more than `max_items` messages, PromptOpsKit preserves all history by compacting older turns into one synthetic history message, then keeping the most recent turns. The final provider request receives at most `max_items` history items before the current prompt template is added.
261
+
262
+
Callers can customize the compacted message with `onHistoryCompaction`:
If no callback is supplied, PromptOpsKit creates a plain text compacted history message. This behavior is provider-agnostic: OpenAI/OpenRouter use `messages`, OpenAI Responses uses `input`, Anthropic uses `messages`, and Gemini maps assistant history to `model`.
Copy file name to clipboardExpand all lines: docs/providers.md
+22Lines changed: 22 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -471,6 +471,28 @@ const { request } = result;
471
471
472
472
History messages are inserted between system instructions and the prompt template in the messages array. For Gemini, role `assistant` is mapped to `model`.
473
473
474
+
If the prompt declares `context.history.max_items`, provider rendering compacts overflow history before shaping the request. Older turns become one preserved history item, and the most recent turns are kept as-is:
If no `onHistoryCompaction` callback is supplied, PromptOpsKit creates a plain text compacted history message. The behavior is shared by OpenAI, OpenAI Responses, Anthropic, Gemini, and OpenRouter.
495
+
474
496
## Tools
475
497
476
498
Tools defined in front matter are included in the request body. They can be string references or inline definitions:
| `history.max_items` | `number` | Maximum history items |
281
+
| `history.max_items` | `number` | Maximum rendered history items. Overflow history is compacted into one preserved message rather than dropped. |
282
+
283
+
When runtime `history` exceeds `history.max_items`, PromptOpsKit creates one compacted history item for the older overflow and keeps the most recent turns. Applications can pass `onHistoryCompaction` to `renderPrompt()` or direct adapter rendering to produce their own summary message.
0 commit comments