Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions agent/title_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,10 @@ def maybe_auto_title(

# Count user messages in history to detect first exchange.
# conversation_history includes the exchange that just happened,
# so for a first exchange we expect exactly 1 user message
# (or 2 counting system). Be generous: generate on first 2 exchanges.
# so for a first exchange we expect exactly 1 user message.
# Only generate a title on the very first exchange (user_msg_count == 1).
user_msg_count = sum(1 for m in (conversation_history or []) if m.get("role") == "user")
if user_msg_count > 2:
if user_msg_count > 1:
return

thread = threading.Thread(
Expand Down
16 changes: 16 additions & 0 deletions tests/agent/test_title_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,22 @@ def test_skips_if_not_first_exchange(self):
time.sleep(0.1)
mock_auto.assert_not_called()

def test_skips_on_second_exchange(self):
"""Should not fire for conversations with exactly 2 user messages (second exchange)."""
db = MagicMock()
history = [
{"role": "user", "content": "first"},
{"role": "assistant", "content": "response 1"},
{"role": "user", "content": "second"},
{"role": "assistant", "content": "response 2"},
]

with patch("agent.title_generator.auto_title_session") as mock_auto:
maybe_auto_title(db, "sess-1", "second", "response 2", history)
import time
time.sleep(0.1)
mock_auto.assert_not_called()

def test_fires_on_first_exchange(self):
"""Should fire a background thread for the first exchange."""
db = MagicMock()
Expand Down