Generate system instructions from chat history - #403
Conversation
🦋 Changeset detectedLatest commit: 3e93b29 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
b3f5f6a to
5e08c13
Compare
c7fe4cd to
9f22d41
Compare
Users can promote a working conversation into an editable draft instead of writing the agent prompt from scratch, and nothing is saved until they apply or copy it. Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Walk a turn's user messages newest-first so the transcript reverse keeps them in order.
9f22d41 to
0672b2f
Compare
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
The only conflicts were the import lists in sessions.ts and sessionRoutes.ts. Keep generate-instructions next to the new get-or-create-by-external-id route.
Keep the generate-from-chat slots next to the new library/sessions pages, and keep both harness tests.
Keep GenerateInstructionsButton next to SaveAgent, hide Save when agent config is open, and keep the new SaveAgentForm slots. The harness server still exposes generateInstructionsFromChat on the typed AgentChatServer from main.
|
Merged current Conflicts were in the chat chrome and harness adapter. |
Main dropped TENANT_ID and the global modelProviderStore. The handler now resolves tenant, agent, and provider the same way as the other session routes. Transcript clipping reserves user turns first so a long latest assistant reply cannot drop earlier preferences.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Want higher recall? High effort reviews run extra passes and find more bugs. A team admin can switch effort levels in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit d887691. Configure here.

Fixes #357
System instructions currently have to be written from scratch, even when the chat already made it obvious how the user wants the agent to behave.
This adds a From chat button on the session header. It drafts instructions from the transcript, you can edit them in a dialog, and nothing is saved until you apply. Inline chats can apply the draft to that session. Named/registry agents only get copy, so we don't mutate the saved agent.
Short chats return 422 before we call the model, so a "hey"/"hi" conversation doesn't turn into a generic helpful-assistant prompt.
New route:
POST /api/v1/sessions/{session_id}/generate-instructionsIt only returns a suggestion (
instructions,current_instructions,sources). Saving still goes through the existing session update.I didn't regenerate the SDK. The UI adapter hits the new path with
client.fetch.Note
Medium Risk
New session-scoped LLM endpoint reads full chat transcripts and can change agent instructions on apply, though access is creator-only and apply reuses existing session update paths.
Overview
Adds From chat in the session header to draft system instructions from the conversation transcript. Opening it calls a new
POST /api/v1/sessions/{session_id}/generate-instructionsendpoint that returns a suggestion only (instructions,current_instructions,sources); nothing is persisted until the user applies via the existing session update.The backend builds a bounded transcript from session events, rejects thin chats with 422 before any model call (user-text threshold, generic-output filtering), then uses the session’s configured model to draft instructions. The UI shows an editable modal with source excerpts; Apply to this chat is limited to mutable inline sessions, while chats bound to saved agents get Copy only. The Harness UI adapter exposes this through an optional
generateInstructionsFromChatserver method (rawclient.fetch, SDK not regenerated).Reviewed by Cursor Bugbot for commit 3e93b29. Bugbot is set up for automated code reviews on this repo. Configure here.