Skip to content

Commit 652b6a5

Browse files
authored
Merge pull request #1503 from krissetto/editable-session-titles
Editable session titles
2 parents 698aa6e + 909c5f7 commit 652b6a5

39 files changed

+7165
-406
lines changed

cmd/root/new.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/docker/cagent/pkg/creator"
1313
"github.com/docker/cagent/pkg/runtime"
1414
"github.com/docker/cagent/pkg/session"
15+
"github.com/docker/cagent/pkg/sessiontitle"
1516
"github.com/docker/cagent/pkg/telemetry"
1617
"github.com/docker/cagent/pkg/tui"
1718
)
@@ -73,6 +74,13 @@ func (f *newFlags) runNewCommand(cmd *cobra.Command, args []string) error {
7374
}
7475

7576
func runTUI(ctx context.Context, rt runtime.Runtime, sess *session.Session, opts ...app.Opt) error {
77+
// For local runtime, create and pass a title generator.
78+
if pr, ok := rt.(*runtime.PersistentRuntime); ok {
79+
if model := pr.CurrentAgent().Model(); model != nil {
80+
opts = append(opts, app.WithTitleGenerator(sessiontitle.New(model)))
81+
}
82+
}
83+
7684
a := app.New(ctx, rt, sess, opts...)
7785
m := tui.New(ctx, a)
7886

docs/USAGE.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ During TUI sessions, you can use special slash commands. Type `/` to see all ava
172172
| `/star` | Toggle star on current session |
173173
| `/theme` | Change the color theme (see [Theming](#theming)) |
174174
| `/think` | Toggle thinking/reasoning mode |
175+
| `/title` | Set or regenerate session title (usage: /title [new title]) |
175176
| `/yolo` | Toggle automatic approval of tool calls |
176177

177178
#### Runtime Model Switching
@@ -279,6 +280,30 @@ Themes can customize colors in three sections: `colors`, `chroma` (syntax highli
279280

280281
See the [built-in themes on GitHub](https://github.com/docker/cagent/tree/main/pkg/tui/styles/themes) for complete examples.
281282

283+
#### Session Title Editing
284+
285+
You can customize session titles to make them more meaningful and easier to find later. By default, cagent automatically generates titles based on your first message, but you can override or regenerate them at any time.
286+
287+
**Using the `/title` command:**
288+
289+
```
290+
/title # Regenerate title using AI (based on at most the last 2 user messages)
291+
/title My Custom Title # Set a specific title
292+
```
293+
294+
**Using the sidebar:**
295+
296+
In the TUI, you can click on the pencil icon (✎) next to the session title in the sidebar to edit it inline:
297+
298+
1. Click the pencil icon next to the title
299+
2. Type your new title
300+
3. Press Enter to save, or Escape to cancel
301+
302+
**Notes:**
303+
- Manually set titles are preserved and won't be overwritten by auto-generation
304+
- Title changes are persisted immediately to the session
305+
- Works with both local and remote runtimes
306+
282307
## 🔧 Configuration Reference
283308
284309
### Agent Properties

e2e/runtime_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func TestRuntime_OpenAI_Basic(t *testing.T) {
3232

3333
response := sess.GetLastAssistantMessageContent()
3434
assert.Equal(t, "2 + 2 equals 4.", response)
35-
assert.Equal(t, "Simple Math: Addition of 2 and 2", sess.Title)
35+
// Title generation is now handled by pkg/app or pkg/server, not the runtime
3636
}
3737

3838
func TestRuntime_Mistral_Basic(t *testing.T) {
@@ -55,5 +55,5 @@ func TestRuntime_Mistral_Basic(t *testing.T) {
5555

5656
response := sess.GetLastAssistantMessageContent()
5757
assert.Equal(t, "The sum of 2 + 2 is 4.", response)
58-
assert.Equal(t, "Math Basics: Simple Addition", sess.Title)
58+
// Title generation is now handled by pkg/app or pkg/server, not the runtime
5959
}

e2e/testdata/cassettes/TestRuntime_Mistral_Basic.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ interactions:
5858
proto_minor: 1
5959
content_length: 0
6060
host: api.mistral.ai
61-
body: '{"messages":[{"content":"You are a helpful AI assistant that generates concise, descriptive titles for conversations. You will be given a conversation history and asked to create a single-line title that captures the main topic. Never use newlines or line breaks in your response.","role":"system"},{"content":"Based on the following message a user sent to an AI assistant, generate a short, descriptive title (maximum 50 characters) that captures the main topic or purpose of the conversation. Return ONLY the title text on a single line, nothing else. Do not include any newlines, explanations, or formatting.\n\nUser message: What''s 2+2?\n\n","role":"user"}],"model":"mistral-small","stream_options":{"include_usage":true},"stream":true}'
61+
body: '{"messages":[{"content":"You are a helpful AI assistant that generates concise, descriptive titles for conversations. You will be given up to 2 recent user messages and asked to create a single-line title that captures the main topic. Never use newlines or line breaks in your response.","role":"system"},{"content":"Based on the following recent user messages from a conversation with an AI assistant, generate a short, descriptive title (maximum 50 characters) that captures the main topic or purpose of the conversation. Return ONLY the title text on a single line, nothing else. Do not include any newlines, explanations, or formatting.\n\nRecent user messages:\n1. What''s 2+2?\n\n\n","role":"user"}],"model":"mistral-small","stream_options":{"include_usage":true},"stream":true}'
6262
url: https://api.mistral.ai/v1/chat/completions
6363
method: POST
6464
response:

e2e/testdata/cassettes/TestRuntime_OpenAI_Basic.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ interactions:
5252
proto_minor: 1
5353
content_length: 0
5454
host: api.openai.com
55-
body: '{"messages":[{"content":"You are a helpful AI assistant that generates concise, descriptive titles for conversations. You will be given a conversation history and asked to create a single-line title that captures the main topic. Never use newlines or line breaks in your response.","role":"system"},{"content":"Based on the following message a user sent to an AI assistant, generate a short, descriptive title (maximum 50 characters) that captures the main topic or purpose of the conversation. Return ONLY the title text on a single line, nothing else. Do not include any newlines, explanations, or formatting.\n\nUser message: What''s 2+2?\n\n","role":"user"}],"model":"gpt-3.5-turbo","stream_options":{"include_usage":true},"stream":true}'
55+
body: '{"messages":[{"content":"You are a helpful AI assistant that generates concise, descriptive titles for conversations. You will be given up to 2 recent user messages and asked to create a single-line title that captures the main topic. Never use newlines or line breaks in your response.","role":"system"},{"content":"Based on the following recent user messages from a conversation with an AI assistant, generate a short, descriptive title (maximum 50 characters) that captures the main topic or purpose of the conversation. Return ONLY the title text on a single line, nothing else. Do not include any newlines, explanations, or formatting.\n\nRecent user messages:\n1. What''s 2+2?\n\n\n","role":"user"}],"model":"gpt-3.5-turbo","stream_options":{"include_usage":true},"stream":true}'
5656
url: https://api.openai.com/v1/chat/completions
5757
method: POST
5858
response:

0 commit comments

Comments
 (0)