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
Show how to wire a "Summarize conversation" button or slash command
via actionSchema + onAction. The backend summarizes and replaces
history with chat.history.set(); run() short-circuits when
trigger === "action" so no LLM response is generated. Includes a
progress-feedback variant using chat.stream.append().
Resolves TRI-8268.
Sometimes you want the user to decide when to compact — a "Summarize conversation" button, a `/compact` slash command, or a settings toggle. Wire this up with [actions](/ai-chat/backend#actions): the frontend sends a typed action, `onAction` runs the summary, and `chat.history.set()` replaces the conversation.
196
+
197
+
### Backend
198
+
199
+
Define a `compact` action that reuses your existing `summarize` function:
// Compact action doesn't need an LLM response — just exit.
247
+
if (trigger==="action") return;
248
+
249
+
returnstreamText({ model: openai("gpt-4o"), messages, abortSignal: signal });
250
+
},
251
+
});
252
+
```
253
+
254
+
Actions fire `onAction`, apply any `chat.history.*` mutations, then call `run()`. For compaction there's no new user message to respond to, so `run()` returns early when `trigger === "action"`. `onTurnComplete` still fires with the compacted `uiMessages` — use it to persist the new state.
255
+
256
+
### Frontend
257
+
258
+
Call `transport.sendAction()` from a button or slash command:
The call returns as soon as the backend accepts the action. Because `onTurnComplete` replaces the `uiMessages` with the summary, `useChat` receives the new state via the normal turn-complete flow — the UI updates automatically.
280
+
281
+
### Indicating compaction in the UI
282
+
283
+
For "Compacting..." feedback while the summary generates, append a transient data part from `onAction` via `chat.stream.append()`:
0 commit comments